captainarkdotnet/public/2015/05/25/flexget-init-script/index.html

638 lines
17 KiB
HTML

<!DOCTYPE html>
<html lang="en-us">
<head>
<meta charset="utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="twitter:card" content="summary"/>
<meta name="twitter:title" content="Flexget init script"/>
<meta name="twitter:description" content=""/>
<meta name="twitter:site" content="@"/>
<meta property="og:title" content="Flexget init script &middot; Sysadmining. All day. Every day." />
<meta property="og:site_name" content="Sysadmining. All day. Every day." />
<meta property="og:url" content="https://www.captainark.net/2015/05/25/flexget-init-script/" />
<meta property="og:image" content="/images/cover.jpg"/>
<meta property="og:description" content="" />
<meta property="og:type" content="article" />
<meta property="article:published_time" content="2015-05-25T00:00:00&#43;01:00" />
<title>Flexget init script &middot; Sysadmining. All day. Every day.</title>
<meta name="description" content="I&amp;rsquo;ve been using Flexget for the past two years or so as a download automator.
Since I wrote an init script for it a while back, and it is compatible with " />
<meta name="HandheldFriendly" content="True" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<link rel="apple-touch-icon" sizes="180x180" href="https://www.captainark.net/apple-touch-icon.png">
<link rel="icon" type="image/png" sizes="32x32" href="https://www.captainark.net/favicon-32x32.png">
<link rel="icon" type="image/png" sizes="16x16" href="https://www.captainark.net/favicon-16x16.png">
<link rel="manifest" href="https://www.captainark.net/site.webmanifest">
<link rel="mask-icon" href="https://www.captainark.net/safari-pinned-tab.svg" color="#5bbad5">
<meta name="msapplication-TileColor" content="#9f00a7">
<meta name="theme-color" content="#ffffff">
<link rel="stylesheet" type="text/css" href="https://www.captainark.net/css/screen.css" />
<link rel="stylesheet" type="text/css" href="https://www.captainark.net/css/nav.css" />
<link rel="stylesheet" type="text/css" href="https://fonts.googleapis.com/css?family=Merriweather:300,700,700italic,300italic|Open+Sans:700,400|Inconsolata:700,400" />
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.13.1/styles/solarized-light.min.css" integrity="sha384-bFKDPkG3geCujYJIbPornilfOgmYQoPS45Oh/8daqqo1SUwNY06OeHorpgnNvx82" crossorigin="anonymous">
<script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.13.1/highlight.min.js" integrity="sha384-BlPof9RtjBqeJFskKv3sK3dh4Wk70iKlpIe92FeVN+6qxaGUOUu+mZNpALZ+K7ya" crossorigin="anonymous"></script>
<script type="text/javascript" src="https://www.captainark.net/js/hjsload.js"></script>
<link href="https://www.captainark.net/index.xml" rel="alternate" type="application/rss+xml" title="Sysadmining. All day. Every day." />
<meta name="generator" content="Hugo 0.54.0" />
<link rel="canonical" href="https://www.captainark.net/2015/05/25/flexget-init-script/" />
<script type="application/ld+json">
{
"@context": "https://schema.org",
"@type": "Article",
"publisher": {
"@type": "Organization",
"name": ,
"logo": https://www.captainark.net/images/logo.png
},
"author": {
"@type": "Person",
"name": ,
"image": {
"@type": "ImageObject",
"url": https://www.captainark.net/images/author.jpg,
"width": 250,
"height": 250
},
"url": https://www.captainark.net,
"sameAs": [
],
"description": Geek | Gamer | TV Shows Aficionado
},
"headline": Flexget init script,
"name": Flexget init script,
"wordCount": 715,
"timeRequired": "PT4M",
"inLanguage": {
"@type": "Language",
"alternateName": en
},
"url": https://www.captainark.net/2015/05/25/flexget-init-script/,
"datePublished": 2015-05-25T00:00Z,
"dateModified": 2015-05-25T00:00Z,
"description": ,
"mainEntityOfPage": {
"@type": "WebPage",
"@id": https://www.captainark.net/2015/05/25/flexget-init-script/
}
}
</script>
<script type="text/javascript" src="https://www.captainark.net/js/stats.js"></script>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/fork-awesome@1.1.7/css/fork-awesome.min.css" integrity="sha256-gsmEoJAws/Kd3CjuOQzLie5Q3yshhvmo7YNtBG7aaEY=" crossorigin="anonymous">
</head>
<body class="nav-closed">
<div class="nav">
<h3 class="nav-title">Menu</h3>
<a href="#" class="nav-close">
<span class="hidden">Close</span>
</a>
<ul>
<h3>This site</h3>
<li class="nav-opened" role="presentation">
<a href="https://www.captainark.net/">Home</a>
</li>
<li class="nav-opened" role="presentation">
<a href="https://www.captainark.net/about">About</a>
</li>
<li class="nav-opened" role="presentation">
<a href="https://www.captainark.net/resume">Resume</a>
</li>
<h3>Other services</h3>
<li class="nav-opened" role="presentation">
<a href="https://chat.captainark.net">Rocket.Chat</a>
</li>
<li class="nav-opened" role="presentation">
<a href="https://notes.captainark.net">CodiMD</a>
</li>
<li class="nav-opened" role="presentation">
<a href="https://git.captainark.net">Gitea</a>
</li>
<li class="nav-opened" role="presentation">
<a href="https://paste.captainark.net">Privatebin</a>
</li>
<li class="nav-opened" role="presentation">
<a href="https://pics.captainark.net">Pics</a>
</li>
</ul>
<a class="subscribe-button icon-feed" href="https://www.captainark.net/index.xml">Subscribe</a>
</div>
<span class="nav-cover"></span>
<div class="site-wrapper">
<header class="main-header post-head no-cover">
<nav class="main-nav clearfix">
<a class="blog-logo" href="https://www.captainark.net/"><img src="https://www.captainark.net/images/logo.png" alt="Home" /></a>
<a class="menu-button" href="#"><span class="burger">&#9776;</span><span class="word">Menu</span></a>
</nav>
</header>
<main class="content" role="main">
<article class="post post">
<header class="post-header">
<h1 class="post-title">Flexget init script</h1>
<small></small>
<section class="post-meta">
<time class="post-date" datetime="2015-05-25T00:00:00&#43;01:00">
25 May 2015
</time>
</section>
</header>
<section class="post-content">
<p>I&rsquo;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&rsquo;d share it here.</p>
<h2 id="the-script">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>
<pre><code class="language-bash"># Configuration file for /etc/init.d/flexget
# User to run flexget as.
# Daemon will not start if left empty.
FGUSER=&quot;&quot;
# Full path to the flexget config.yml file to use.
# Defaults to FGUSER $HOME/.flexget/config.yml
CONFIG=&quot;&quot;
# Path to the directory where flexget should log. Do not add trailing slash.
# Defaults to the FGUSER $HOME/.flexget directory
LOG=&quot;&quot;
# Log verbosity
# Available options : none critical error warning info verbose debug trace
# Defaults to info
LEVEL=&quot;&quot;
</code></pre>
<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>
<pre><code class="language-bash">useradd -m -d /var/lib/flexget -r -s /bin/false flexget
</code></pre>
<p>Then, create the /etc/init.d/flexget file :</p>
<pre><code class="language-bash">#!/bin/bash
### BEGIN INIT INFO
# Provides: flexget
# Required-Start: $network $remote_fs
# Required-Stop: $network $remote_fs
# Should-Start:
# Should-Stop:
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Flexget
# Description: FlexGet is a multipurpose automation tool
# for content like torrents, nzbs, podcasts,
# comics, series, movies, etc.
### END INIT INFO
# Author: Antoine Joubert, 19/01/2014
NAME=&quot;flexget&quot;
DAEMON=&quot;/usr/local/bin/flexget&quot;
SETTINGS=&quot;/etc/default/$NAME&quot;
DESC=&quot;Flexget&quot;
PIDFILE=&quot;/var/run/$NAME.pid&quot;
set -e
. /lib/lsb/init-functions
unset FGUSER CONFIG LOG LEVEL
# Exit if flexget not installed
if [ ! -x &quot;$DAEMON&quot; ]; then
log_action_msg &quot;$DESC: Could not find flexget executable. Exiting.&quot;
exit 2
fi
# Read configuration variables
if [ -r /etc/default/$NAME ]; then
. /etc/default/$NAME
else
log_action_msg &quot;$DESC: /etc/default/$NAME not found. Exiting.&quot;
exit 2
fi
# Exit if FGUSER has not been set in /etc/default/flexget
if [ -z $FGUSER ]; then
log_action_msg &quot;$DESC: FGUSER not set in /etc/default/$NAME. Exiting.&quot;
exit 2
fi
# Function to verify if flexget is already running
run_check() {
if [ -e $PIDFILE ]; then
status_of_proc -p $PIDFILE $DAEMON $NAME &gt; /dev/null &amp;&amp; RETVAL=0 || RETVAL=&quot;$?&quot;
else
RETVAL=&quot;2&quot;
fi
}
end_log() {
if [ $RETVAL -eq 0 ]; then
log_end_msg 0
return 0
else
log_end_msg 1
exit 1
fi
}
# Function to define config file, log file and log level
conf_check() {
if [ -z $CONFIG ]; then
OPTIONS=&quot;$OPTIONS&quot;
else
OPTIONS=&quot;-c $CONFIG&quot;
fi
if [ -z $LOG ]; then
OPTIONS=&quot;$OPTIONS&quot;
else
OPTIONS=&quot;$OPTIONS -l $LOG/flexget.log&quot;
if [ ! -d $LOG ]; then
mkdir -p -m 750 $LOG
chown $FGUSER $LOG
fi
fi
if [ -z $LEVEL ]; then
OPTIONS=&quot;$OPTIONS&quot;
else
OPTIONS=&quot;$OPTIONS -L $LEVEL&quot;
fi
}
start_flexget() {
run_check
if [ $RETVAL = 0 ]; then
log_action_msg &quot;$DESC: Already running with PID $(cat $PIDFILE). Aborting.&quot;
exit 2
else
conf_check
log_daemon_msg &quot;$DESC: Starting the daemon.&quot;
start-stop-daemon --start --background --quiet --pidfile $PIDFILE --make-pidfile \
--chuid $FGUSER --user $FGUSER --exec $DAEMON -- $OPTIONS daemon start
RETVAL=$?
end_log
fi
}
stop_flexget() {
run_check
if [ $RETVAL = 0 ]; then
log_daemon_msg &quot;$DESC: Stopping the daemon.&quot;
start-stop-daemon --stop --quiet --chuid &quot;$FGUSER&quot; --pidfile &quot;$PIDFILE&quot; --retry 30
RETVAL=$?
[ -e &quot;$PIDFILE&quot; ] &amp;&amp; rm -f &quot;$PIDFILE&quot;
end_log
else
log_action_msg &quot;$DESC: Not currently running. Aborting.&quot;
exit 2
fi
}
status_flexget() {
run_check
if [ $RETVAL = 0 ]; then
log_action_msg &quot;$DESC: Currently running with PID $(cat $PIDFILE).&quot;
else
log_action_msg &quot;$DESC: Not currently running.&quot;
fi
exit $RETVAL
}
case &quot;$1&quot; in
start)
start_flexget
;;
stop)
stop_flexget
;;
restart)
stop_flexget &amp;&amp; sleep 2 &amp;&amp; start_flexget
;;
status)
status_flexget
;;
*)
echo &quot;Usage: $0 {start|stop|restart|status}&quot;
;;
esac
exit 0
</code></pre>
<p>Then, give execution rights to the script :</p>
<pre><code class="language-bash">chmod +x /etc/init.d/flexget
</code></pre>
<p>And then, generate the necessary symlinks for the service to start on boot :</p>
<p><em>Debian Jessie</em></p>
<pre><code class="language-bash">systemctl enable flexget
</code></pre>
<p><em>Debian Wheezy</em></p>
<pre><code class="language-bash">insserv flexget
</code></pre>
<p>To start, stop or check if the daemon is running :</p>
<p><em>Debian Jessie</em></p>
<pre><code class="language-bash">systemctl start flexget
systemctl stop flexget
systemctl status flexget
</code></pre>
<p><em>Debian Wheezy / Jessie</em></p>
<pre><code class="language-bash">service flexget start
service flexget stop
service flexget status
</code></pre>
<p><em>Debian Wheezy</em></p>
<pre><code class="language-bash">/etc/init.d/flexget start
/etc/init.d/flexget stop
/etc/init.d/flexget status
</code></pre>
<h2 id="conclusion">Conclusion</h2>
<p>That&rsquo;s all ! If you are using this script, please let me know in the comment section below !</p>
</section>
<footer class="post-footer">
<figure class="author-image">
<a class="img" href="https://www.captainark.net/" style="background-image: url(/images/author.jpg)"><span class="hidden">Antoine Joubert's Picture</span></a>
</figure>
<section class="author">
<h4><a href="https://www.captainark.net/">Antoine Joubert</a></h4>
<p>Geek | Gamer | TV Shows Aficionado</p>
<div class="author-meta">
<span class="author-location icon-location">Angers, France</span>
<span class="author-link icon-link"><a href="https://www.captainark.net">https://www.captainark.net</a></span>
</div>
</section>
<!-- isso -->
<script data-isso="https://www.captainark.net/comments/" src="https://www.captainark.net/comments/js/embed.min.js"></script>
<noscript>Please enable JavaScript to view comments</noscript>
<section id="isso-thread"></section>
<!-- end isso -->
</footer>
</article>
</main>
<aside class="read-next">
<a class="read-next-story" style="no-cover" href="https://www.captainark.net/2016/01/31/private-git-repo/">
<section class="post">
<h2>Private Git repo</h2>
</section>
</a>
<a class="read-next-story prev" style="no-cover" href="https://www.captainark.net/2015/04/24/setting-up-a-mail-server/">
<section class="post">
<h2>Setting up a mail server</h2>
</section>
</a>
</aside>
<center>
<a class="fa-icons" 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>
<a class="fa-icons" 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>
<a class="fa-icons" href="https://social.captainark.net/users/captainark">
<span class="fa-stack fa-lg">
<i class="fa fa-circle fa-stack-2x"></i>
<i class="fa fa-mastodon-alt fa-stack-1x fa-inverse"></i>
</span>
</a>
<a class="fa-icons" 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>
<a class="fa-icons" href="https://www.last.fm/user/captainark">
<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>
</span>
</a>
<a class="fa-icons" 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>
<a class="fa-icons" href="https://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>
</center>
<footer class="site-footer clearfix">
<section class="copyright"><a href="">Sysadmining. All day. Every day.</a> © 2015 - 2019</section>
<section class="poweredby">Proudly generated by <a class="icon-hugo" href="http://gohugo.io">HUGO</a>, with <a class="icon-theme" href="https://github.com/vjeantet/hugo-theme-casper">Casper</a> theme</section>
</footer>
</div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js" integrity="sha384-CgeP3wqr9h5YanePjYLENwCTSSEz42NJkbFpAFgHWQz7u3Zk8D00752ScNpXqGjS" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/fitvids/1.1.0/jquery.fitvids.min.js" integrity="sha384-2/VQUb0aZHixKnNLh7pD38DZk+acGpEw5LeHieWVDPR0h/H326kp/1qnRPDYmFXM" crossorigin="anonymous"></script>
<script type="text/javascript" src="https://www.captainark.net/js/index.js"></script>
</body>
</html>