forked from xombiemp/ultimate-torrent-setup
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Converted btsync and rtorrent init scripts to upstart.
- Loading branch information
Showing
4 changed files
with
95 additions
and
262 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
# btsync startup script | ||
# requires upstart v1.4 or newer | ||
|
||
description "BitTorrent Sync" | ||
|
||
setuid YOURUSER | ||
setgid YOURUSER | ||
env CONFIG=/home/YOURUSER/.config/btsync/config.json | ||
|
||
start on ( local-filesystems | ||
and net-device-up IFACE=eth0) | ||
stop on runlevel [!2345] | ||
|
||
respawn | ||
|
||
pre-start script | ||
# check for config.json | ||
if [ ! -f ${CONFIG} ]; then | ||
# won't try to start without config | ||
echo "ERROR: ${CONFIG} not found!" | ||
exit 1 | ||
fi | ||
end script | ||
|
||
exec btsync --nodaemon --config ${CONFIG} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
# rtorrent startup script | ||
# requires upstart v1.4 or newer | ||
|
||
description "rTorrent - BitTorrent client" | ||
|
||
setuid YOURUSER | ||
setgid YOURUSER | ||
env RTORRENTRC=/home/YOURUSER/.config/rtorrent/rtorrent.rc | ||
|
||
start on ( local-filesystems | ||
and net-device-up IFACE=eth0 | ||
and stopped rc) | ||
stop on runlevel [!2345] | ||
|
||
respawn | ||
|
||
# "setsid screen -Dm" only forks once | ||
expect fork | ||
|
||
pre-start script | ||
# check for configuration and session directory | ||
|
||
# check for rtorrent.rc | ||
if [ -f ${RTORRENTRC} ]; then | ||
# check config for session directory | ||
SESSION_DIR=$(sed -n 's/^[[:space:]]*session[[:space:]]*=[[:space:]]*\(.*\)$/\1/p' ${RTORRENTRC}) | ||
if [ -z ${SESSION_DIR} ]; then | ||
echo "ERROR: session directory not configured!" | ||
exit 1 | ||
else | ||
# make sure directory exists | ||
mkdir -p ${SESSION_DIR} | ||
fi | ||
|
||
# check config for session.lock.set | ||
USE_LOCK=$(sed -n 's/^[[:space:]]*session\.use_lock.set[[:space:]]*=[[:space:]]*\(.*\)$/\1/p' ${RTORRENTRC}) | ||
if [ "x$USE_LOCK" != "xyes" ]; then | ||
echo "WARNING: for proper service control add this to rtorrent.rc: session.use_lock.set = yes" | ||
fi | ||
else | ||
# won't try to start without config | ||
echo "ERROR: ${RTORRENTRC} not found!" | ||
exit 1 | ||
fi | ||
end script | ||
|
||
# using setsid to avoid screen complaining about /var/run/screen permissions | ||
# invoking interactive shell after clean rtorrent shutdown to avoid immediate | ||
# termination of screen (stop command would end up in respawn-loop otherwise) | ||
exec setsid screen -Dm -S rtorrent sh -c 'rtorrent -n -o import=${RTORRENTRC} && exec sh' | ||
|
||
pre-stop script | ||
# stop rtorrent instance gracefully before upstart stop command kills the screen session | ||
|
||
# get session directory | ||
# as we're already running, there's no need to do all the sanity checks again | ||
SESSION_DIR=$(sed -n 's/^[[:space:]]*session[[:space:]]*=[[:space:]]*\(.*\)$/\1/p' ${RTORRENTRC}) | ||
|
||
# now, if we have a pid file, we can perform a clean shutdown | ||
if [ -f ${SESSION_DIR}/rtorrent.lock ]; then | ||
RT_PID=$(sed -n 's/^.*+\([0-9]\+\)$/\1/p' ${SESSION_DIR}/rtorrent.lock) | ||
kill -2 $RT_PID | ||
# wait until rtorrent exits | ||
while kill -0 $RT_PID >/dev/null 2>&1; do | ||
sleep 1 | ||
done | ||
else | ||
echo "WARNING: No pid for rtorrent found. Did you set \"session.use_lock.set = yes\" in rtorrent.rc?" | ||
fi | ||
end script |