captainarkdotnet/output/flexget-init-script.html

451 lines
22 KiB
HTML
Raw Normal View History

2016-01-31 13:43:06 +01:00
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="description" content="">
<meta name="author" content="">
<title>Flexget init script</title>
<!-- Bootstrap Core CSS -->
<link href="https://captainark.net/theme/css/bootstrap.min.css" rel="stylesheet">
2016-01-31 13:43:06 +01:00
<!-- Custom CSS -->
<link href="https://captainark.net/theme/css/clean-blog.min.css" rel="stylesheet">
2016-01-31 13:43:06 +01:00
<!-- Code highlight color scheme -->
<link href="https://captainark.net/theme/css/code_blocks/github.css" rel="stylesheet">
2016-01-31 13:43:06 +01:00
<!-- Custom Fonts -->
<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.1.0/css/font-awesome.min.css" rel="stylesheet" type="text/css">
<link href='https://fonts.googleapis.com/css?family=Lora:400,700,400italic,700italic' rel='stylesheet' type='text/css'>
<link href='https://fonts.googleapis.com/css?family=Open+Sans:300italic,400italic,600italic,700italic,800italic,400,300,600,700,800' rel='stylesheet' type='text/css'>
<!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
<!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
<!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
<script src="https://oss.maxcdn.com/libs/respond.js/1.4.2/respond.min.js"></script>
<![endif]-->
<meta property="og:locale" content="">
<meta property="og:site_name" content="Sysadmining. All day. Every day.">
<meta property="og:type" content="article">
<meta property="article:author" content="">
<meta property="og:url" content="https://captainark.net/flexget-init-script.html">
2016-01-31 13:43:06 +01:00
<meta property="og:title" content="Flexget init script">
<meta property="og:description" content="">
<meta property="og:image" content="https://captainark.net/">
2016-01-31 13:43:06 +01:00
<meta property="article:published_time" content="2015-05-05 00:00:00+02:00">
</head>
<body>
<!-- Navigation -->
<nav class="navbar navbar-default navbar-custom navbar-fixed-top">
<div class="container-fluid">
<!-- Brand and toggle get grouped for better mobile display -->
<div class="navbar-header page-scroll">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="https://captainark.net/">Sysadmining. All day. Every day.</a>
2016-01-31 13:43:06 +01:00
</div>
<!-- Collect the nav links, forms, and other content for toggling -->
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
<ul class="nav navbar-nav navbar-right">
<li><a href="/">Homepage</a></li>
<li><a href="/categories.html">Categories</a></li>
<li><a href="https://captainark.net/pages/about.html">About</a></li>
<li><a href="https://captainark.net/pages/resume.html">Resume</a></li>
2016-01-31 13:43:06 +01:00
</ul>
</div>
<!-- /.navbar-collapse -->
</div>
<!-- /.container -->
</nav>
<!-- Page Header -->
<header class="intro-header" style="background-image: url('/bg.png')">
<div class="container">
<div class="row">
<div class="col-lg-8 col-lg-offset-2 col-md-10 col-md-offset-1">
<div class="post-heading">
<h1>Flexget init script</h1>
<span class="meta">Posted by
<a href="https://captainark.net/author/antoine-joubert.html">Antoine Joubert</a>
2016-01-31 13:43:06 +01:00
on Tue 05 May 2015
</span>
</div>
</div>
</div>
</div>
</header>
<!-- Main Content -->
<div class="container">
<div class="row">
<div class="col-lg-8 col-lg-offset-2 col-md-10 col-md-offset-1">
<!-- Post Content -->
<article>
<h2>Introduction</h2>
<p>I've been using <a href="http://flexget.com/">Flexget</a> for the past two years or so as a download automator.</p>
<p>Since I wrote an <a href="http://flexget.com/wiki/Daemon/Startup#InsservscriptDebiancompatible">init script</a> for it a while back, and it is compatible with Debian Jessie / systemd, I figured I'd share it here.</p>
<h2>The script</h2>
<p>All of the following should be done as the root user.</p>
<p>First, create a /etc/default/flexget file with the following content :</p>
<div class="highlight"><pre><span class="c1"># Configuration file for /etc/init.d/flexget</span>
<span class="c1"># User to run flexget as.</span>
<span class="c1"># Daemon will not start if left empty.</span>
<span class="nv">FGUSER</span><span class="o">=</span><span class="s2">&quot;&quot;</span>
<span class="c1"># Full path to the flexget config.yml file to use.</span>
<span class="c1"># Defaults to FGUSER $HOME/.flexget/config.yml</span>
<span class="nv">CONFIG</span><span class="o">=</span><span class="s2">&quot;&quot;</span>
<span class="c1"># Path to the directory where flexget should log. Do not add trailing slash.</span>
<span class="c1"># Defaults to the FGUSER $HOME/.flexget directory</span>
<span class="nv">LOG</span><span class="o">=</span><span class="s2">&quot;&quot;</span>
<span class="c1"># Log verbosity </span>
<span class="c1"># Available options : none critical error warning info verbose debug trace</span>
<span class="c1"># Defaults to info</span>
<span class="nv">LEVEL</span><span class="o">=</span><span class="s2">&quot;&quot;</span>
</pre></div>
<p>Please note that the FGUSER variable needs to be defined for the daemon to start. It can be set to your current user, or you can run flexget as its own user.</p>
<p>You can create a flexget user with the following command :</p>
<div class="highlight"><pre>useradd -m -d /var/lib/flexget -r -s /bin/false flexget
</pre></div>
<p>Then, create the /etc/init.d/flexget file :</p>
<div class="highlight"><pre><span class="ch">#!/bin/bash</span>
<span class="c1">### BEGIN INIT INFO</span>
<span class="c1"># Provides: flexget</span>
<span class="c1"># Required-Start: $network $remote_fs</span>
<span class="c1"># Required-Stop: $network $remote_fs</span>
<span class="c1"># Should-Start: </span>
<span class="c1"># Should-Stop: </span>
<span class="c1"># Default-Start: 2 3 4 5</span>
<span class="c1"># Default-Stop: 0 1 6</span>
<span class="c1"># Short-Description: Flexget</span>
<span class="c1"># Description: FlexGet is a multipurpose automation tool </span>
<span class="c1"># for content like torrents, nzbs, podcasts,</span>
<span class="c1"># comics, series, movies, etc.</span>
<span class="c1">### END INIT INFO</span>
<span class="c1"># Author: Antoine Joubert, 19/01/2014</span>
<span class="nv">NAME</span><span class="o">=</span><span class="s2">&quot;flexget&quot;</span>
<span class="nv">DAEMON</span><span class="o">=</span><span class="s2">&quot;/usr/local/bin/flexget&quot;</span>
<span class="nv">SETTINGS</span><span class="o">=</span><span class="s2">&quot;/etc/default/</span>$<span class="s2">NAME&quot;</span>
<span class="nv">DESC</span><span class="o">=</span><span class="s2">&quot;Flexget&quot;</span>
<span class="nv">PIDFILE</span><span class="o">=</span><span class="s2">&quot;/var/run/</span>$<span class="s2">NAME.pid&quot;</span>
<span class="nb">set</span> -e
. /lib/lsb/init-functions
<span class="nb">unset</span> FGUSER CONFIG LOG LEVEL
<span class="c1"># Exit if flexget not installed</span>
<span class="k">if</span> <span class="o">[</span> ! -x <span class="s2">&quot;</span><span class="nv">$DAE</span><span class="s2">MON&quot;</span> <span class="o">]</span><span class="p">;</span> <span class="k">then</span>
log_action_msg <span class="s2">&quot;</span><span class="nv">$DE</span><span class="s2">SC: Could not find flexget executable. Exiting.&quot;</span>
<span class="nb">exit</span> 2
<span class="k">fi</span>
<span class="c1"># Read configuration variables</span>
<span class="k">if</span> <span class="o">[</span> -r /etc/default/$NAME <span class="o">]</span><span class="p">;</span> <span class="k">then</span>
. /etc/default/$NAME
<span class="k">else</span>
log_action_msg <span class="s2">&quot;</span><span class="nv">$DE</span><span class="s2">SC: /etc/default/</span>$<span class="s2">NAME not found. Exiting.&quot;</span>
<span class="nb">exit</span> 2
<span class="k">fi</span>
<span class="c1"># Exit if FGUSER has not been set in /etc/default/flexget</span>
<span class="k">if</span> <span class="o">[</span> -z <span class="nv">$F</span>GUSER <span class="o">]</span><span class="p">;</span> <span class="k">then</span>
log_action_msg <span class="s2">&quot;</span><span class="nv">$DE</span><span class="s2">SC: FGUSER not set in /etc/default/</span>$<span class="s2">NAME. Exiting.&quot;</span>
<span class="nb">exit</span> 2
<span class="k">fi</span>
<span class="c1"># Function to verify if flexget is already running</span>
run_check<span class="o">()</span> <span class="o">{</span>
<span class="k">if</span> <span class="o">[</span> -e $PIDFILE <span class="o">]</span><span class="p">;</span> <span class="k">then</span>
status_of_proc -p $PIDFILE <span class="nv">$DAE</span>MON $NAME &gt; /dev/null <span class="o">&amp;&amp;</span> <span class="nv">RETVAL</span><span class="o">=</span><span class="m">0</span> <span class="o">||</span> <span class="nv">RETVAL</span><span class="o">=</span><span class="s2">&quot;</span><span class="nv">$?</span><span class="s2">&quot;</span>
<span class="k">else</span>
<span class="nv">RETVAL</span><span class="o">=</span><span class="s2">&quot;2&quot;</span>
<span class="k">fi</span>
<span class="o">}</span>
end_log<span class="o">()</span> <span class="o">{</span>
<span class="k">if</span> <span class="o">[</span> $RETVAL -eq <span class="m">0</span> <span class="o">]</span><span class="p">;</span> <span class="k">then</span>
log_end_msg 0
<span class="k">return</span> 0
<span class="k">else</span>
log_end_msg 1
<span class="nb">exit</span> 1
<span class="k">fi</span>
<span class="o">}</span>
<span class="c1"># Function to define config file, log file and log level</span>
conf_check<span class="o">()</span> <span class="o">{</span>
<span class="k">if</span> <span class="o">[</span> -z <span class="nv">$C</span>ONFIG <span class="o">]</span><span class="p">;</span> <span class="k">then</span>
<span class="nv">OPTIONS</span><span class="o">=</span><span class="s2">&quot;</span>$<span class="s2">OPTIONS&quot;</span>
<span class="k">else</span>
<span class="nv">OPTIONS</span><span class="o">=</span><span class="s2">&quot;-c </span><span class="nv">$C</span><span class="s2">ONFIG&quot;</span>
<span class="k">fi</span>
<span class="k">if</span> <span class="o">[</span> -z $LOG <span class="o">]</span><span class="p">;</span> <span class="k">then</span>
<span class="nv">OPTIONS</span><span class="o">=</span><span class="s2">&quot;</span>$<span class="s2">OPTIONS&quot;</span>
<span class="k">else</span>
<span class="nv">OPTIONS</span><span class="o">=</span><span class="s2">&quot;</span>$<span class="s2">OPTIONS -l </span>$<span class="s2">LOG/flexget.log&quot;</span>
<span class="k">if</span> <span class="o">[</span> ! -d $LOG <span class="o">]</span><span class="p">;</span> <span class="k">then</span>
mkdir -p -m <span class="m">750</span> $LOG
chown <span class="nv">$F</span>GUSER $LOG
<span class="k">fi</span>
<span class="k">fi</span>
<span class="k">if</span> <span class="o">[</span> -z $LEVEL <span class="o">]</span><span class="p">;</span> <span class="k">then</span>
<span class="nv">OPTIONS</span><span class="o">=</span><span class="s2">&quot;</span>$<span class="s2">OPTIONS&quot;</span>
<span class="k">else</span>
<span class="nv">OPTIONS</span><span class="o">=</span><span class="s2">&quot;</span>$<span class="s2">OPTIONS -L </span>$<span class="s2">LEVEL&quot;</span>
<span class="k">fi</span>
<span class="o">}</span>
start_flexget<span class="o">()</span> <span class="o">{</span>
run_check
<span class="k">if</span> <span class="o">[</span> $<span class="nv">RETVAL</span> <span class="o">=</span> <span class="m">0</span> <span class="o">]</span><span class="p">;</span> <span class="k">then</span>
log_action_msg <span class="s2">&quot;</span><span class="nv">$DE</span><span class="s2">SC: Already running with PID </span><span class="k">$(</span>cat $PIDFILE<span class="k">)</span><span class="s2">. Aborting.&quot;</span>
<span class="nb">exit</span> 2
<span class="k">else</span>
conf_check
log_daemon_msg <span class="s2">&quot;</span><span class="nv">$DE</span><span class="s2">SC: Starting the daemon.&quot;</span>
start-stop-daemon --start --background --quiet --pidfile $PIDFILE --make-pidfile <span class="se">\</span>
--chuid <span class="nv">$F</span>GUSER --user <span class="nv">$F</span>GUSER --exec <span class="nv">$DAE</span>MON -- $OPTIONS daemon start
<span class="nv">RETVAL</span><span class="o">=</span><span class="nv">$?</span>
end_log
<span class="k">fi</span>
<span class="o">}</span>
stop_flexget<span class="o">()</span> <span class="o">{</span>
run_check
<span class="k">if</span> <span class="o">[</span> $<span class="nv">RETVAL</span> <span class="o">=</span> <span class="m">0</span> <span class="o">]</span><span class="p">;</span> <span class="k">then</span>
log_daemon_msg <span class="s2">&quot;</span><span class="nv">$DE</span><span class="s2">SC: Stopping the daemon.&quot;</span>
start-stop-daemon --stop --quiet --chuid <span class="s2">&quot;</span><span class="nv">$F</span><span class="s2">GUSER&quot;</span> --pidfile <span class="s2">&quot;</span>$<span class="s2">PIDFILE&quot;</span> --retry 30
<span class="nv">RETVAL</span><span class="o">=</span><span class="nv">$?</span>
<span class="o">[</span> -e <span class="s2">&quot;</span>$<span class="s2">PIDFILE&quot;</span> <span class="o">]</span> <span class="o">&amp;&amp;</span> rm -f <span class="s2">&quot;</span>$<span class="s2">PIDFILE&quot;</span>
end_log
<span class="k">else</span>
log_action_msg <span class="s2">&quot;</span><span class="nv">$DE</span><span class="s2">SC: Not currently running. Aborting.&quot;</span>
<span class="nb">exit</span> 2
<span class="k">fi</span>
<span class="o">}</span>
status_flexget<span class="o">()</span> <span class="o">{</span>
run_check
<span class="k">if</span> <span class="o">[</span> $<span class="nv">RETVAL</span> <span class="o">=</span> <span class="m">0</span> <span class="o">]</span><span class="p">;</span> <span class="k">then</span>
log_action_msg <span class="s2">&quot;</span><span class="nv">$DE</span><span class="s2">SC: Currently running with PID </span><span class="k">$(</span>cat $PIDFILE<span class="k">)</span><span class="s2">.&quot;</span>
<span class="k">else</span>
log_action_msg <span class="s2">&quot;</span><span class="nv">$DE</span><span class="s2">SC: Not currently running.&quot;</span>
<span class="k">fi</span>
<span class="nb">exit</span> $RETVAL
<span class="o">}</span>
<span class="k">case</span> <span class="s2">&quot;</span><span class="nv">$1</span><span class="s2">&quot;</span> in
start<span class="o">)</span>
start_flexget
<span class="p">;;</span>
stop<span class="o">)</span>
stop_flexget
<span class="p">;;</span>
restart<span class="o">)</span>
stop_flexget <span class="o">&amp;&amp;</span> sleep <span class="m">2</span> <span class="o">&amp;&amp;</span> start_flexget
<span class="p">;;</span>
status<span class="o">)</span>
status_flexget
<span class="p">;;</span>
*<span class="o">)</span>
<span class="nb">echo</span> <span class="s2">&quot;Usage: </span><span class="nv">$0</span><span class="s2"> {start|stop|restart|status}&quot;</span>
<span class="p">;;</span>
<span class="k">esac</span>
<span class="nb">exit</span> 0
</pre></div>
<p>Then, give execution rights to the script :</p>
<div class="highlight"><pre>chmod +x /etc/init.d/flexget
</pre></div>
<p>And then, generate the necessary symlinks for the service to start on boot :</p>
<p><em>Debian Jessie</em></p>
<div class="highlight"><pre>systemctl <span class="nb">enable</span> flexget
</pre></div>
<p><em>Debian Wheezy</em></p>
<div class="highlight"><pre>insserv flexget
</pre></div>
<p>To start, stop or check if the daemon is running :</p>
<p><em>Debian Jessie</em></p>
<div class="highlight"><pre>systemctl start flexget
systemctl stop flexget
systemctl status flexget
</pre></div>
<p><em>Debian Wheezy / Jessie</em></p>
<div class="highlight"><pre>service flexget start
service flexget stop
service flexget status
</pre></div>
<p><em>Debian Wheezy</em></p>
<div class="highlight"><pre>/etc/init.d/flexget start
/etc/init.d/flexget stop
/etc/init.d/flexget status
</pre></div>
<h2>Conclusion</h2>
<p>That's all ! If you are using this script, please let me know in the comment section below !</p>
</article>
<hr>
<div class="sharing">
</div>
<hr>
<div class="comments">
<h2>Comments !</h2>
<div id="disqus_thread"></div>
<script type="text/javascript">
2016-01-31 14:36:18 +01:00
var disqus_shortname = 'captainark';
2016-01-31 13:43:06 +01:00
var disqus_identifier = 'flexget-init-script.html';
var disqus_url = 'https://captainark.net/flexget-init-script.html';
2016-01-31 13:43:06 +01:00
(function() {
var dsq = document.createElement('script'); dsq.type = 'text/javascript'; dsq.async = true;
2016-01-31 14:36:18 +01:00
dsq.src = '//captainark.disqus.com/embed.js';
2016-01-31 13:43:06 +01:00
(document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(dsq);
})();
</script>
<noscript>Please enable JavaScript to view the comments.</noscript>
</div>
</div>
</div>
</div>
<hr>
<!-- Footer -->
<footer>
<div class="container">
<div class="row">
<div class="col-lg-8 col-lg-offset-2 col-md-10 col-md-offset-1">
<ul class="list-inline text-center">
<li>
<a href="mailto:contact@captainark.net">
<span class="fa-stack fa-lg">
<i class="fa fa-circle fa-stack-2x"></i>
<i class="fa fa-envelope fa-stack-1x fa-inverse"></i>
</span>
</a>
</li>
<li>
<a href="https://twitter.com/captainark">
<span class="fa-stack fa-lg">
<i class="fa fa-circle fa-stack-2x"></i>
<i class="fa fa-twitter fa-stack-1x fa-inverse"></i>
</span>
</a>
</li>
<li>
<a href="https://github.com/captainark">
<span class="fa-stack fa-lg">
<i class="fa fa-circle fa-stack-2x"></i>
<i class="fa fa-github fa-stack-1x fa-inverse"></i>
</span>
</a>
</li>
<li>
<a href="http://www.last.fm/user/captainark">
2016-01-31 13:43:06 +01:00
<span class="fa-stack fa-lg">
<i class="fa fa-circle fa-stack-2x"></i>
<i class="fa fa-lastfm fa-stack-1x fa-inverse"></i>
2016-01-31 13:43:06 +01:00
</span>
</a>
</li>
<li>
<a href="https://steamcommunity.com/id/captainark">
<span class="fa-stack fa-lg">
<i class="fa fa-circle fa-stack-2x"></i>
<i class="fa fa-steam fa-stack-1x fa-inverse"></i>
</span>
</a>
</li>
<li>
<a href="http://www.twitch.tv/captainark">
<span class="fa-stack fa-lg">
<i class="fa fa-circle fa-stack-2x"></i>
<i class="fa fa-twitch fa-stack-1x fa-inverse"></i>
</span>
</a>
</li>
</ul>
<p class="copyright text-muted">
Blog powered by <a href="http://getpelican.com">Pelican</a>,
which takes great advantage of <a href="http://python.org">Python</a>.
</p> </div>
</div>
</div>
</footer>
<!-- jQuery -->
<script src="https://captainark.net/theme/js/jquery.js"></script>
2016-01-31 13:43:06 +01:00
<!-- Bootstrap Core JavaScript -->
<script src="https://captainark.net/theme/js/bootstrap.min.js"></script>
2016-01-31 13:43:06 +01:00
<!-- Custom Theme JavaScript -->
<script src="https://captainark.net/theme/js/clean-blog.min.js"></script>
2016-01-31 13:43:06 +01:00
<script type="text/javascript">
2016-01-31 14:36:18 +01:00
var disqus_shortname = 'captainark';
2016-01-31 13:43:06 +01:00
(function () {
var s = document.createElement('script'); s.async = true;
s.type = 'text/javascript';
s.src = '//' + disqus_shortname + '.disqus.com/count.js';
(document.getElementsByTagName('HEAD')[0] || document.getElementsByTagName('BODY')[0]).appendChild(s);
}());
</script>
</body>
</html>