Last active
December 21, 2015 10:29
-
-
Save typomedia/6292514 to your computer and use it in GitHub Desktop.
BitTorrent Sync Init Script
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
#!/bin/sh | |
### BEGIN INIT INFO | |
# Provides: btsync | |
# Required-Start: $local_fs $remote_fs $network | |
# Required-Stop: $local_fs $remote_fs $network | |
# Default-Start: 2 3 4 5 | |
# Default-Stop: 0 1 6 | |
# Short-Description: BitTorrent Sync | |
# Description: Automatically sync files via secure, distributed technology | |
# Author: Typomedia Foundation | |
# Version: 1.3 | |
### END INIT INFO | |
PATH=/bin:/usr/bin:/sbin:/usr/sbin | |
DESC="BitTorrent Sync" | |
NAME=btsync | |
DAEMON=/usr/bin/$NAME | |
PIDFILE=/var/run/btsync.pid | |
TIMEOUT=60 | |
export BTSYNC_RUN_USER=root | |
[ -x $DAEMON ] || exit 0 | |
[ -e /etc/default/$NAME ] && . /etc/default/$NAME | |
. /lib/lsb/init-functions | |
check_daemon () { | |
if [ $ENABLE_DAEMON != 1 ]; then | |
log_progress_msg "(disabled)" | |
log_end_msg 255 || true | |
else | |
start_daemon | |
fi | |
} | |
start_daemon () { | |
start-stop-daemon --start --quiet \ | |
--make-pidfile --pidfile $PIDFILE \ | |
--chuid $BTSYNC_RUN_USER \ | |
$START_STOP_OPTIONS \ | |
--exec $DAEMON -- $OPTIONS | |
} | |
stop_daemon () { | |
start-stop-daemon --stop --quiet \ | |
--pidfile $PIDFILE \ | |
--exec $DAEMON --retry $TIMEOUT \ | |
--oknodo | |
} | |
reload_daemon () { | |
start-stop-daemon --stop --quiet \ | |
--exec $DAEMON \ | |
--oknodo --signal 1 | |
} | |
case "$1" in | |
start) | |
log_daemon_msg "Starting $DESC" | |
check_daemon | |
log_end_msg 0 | |
;; | |
stop) | |
log_daemon_msg "Stopping $DESC" "$NAME" | |
stop_daemon | |
log_end_msg 0 | |
;; | |
reload) | |
log_daemon_msg "Reloading $DESC" "$NAME" | |
reload_daemon | |
log_end_msg 0 | |
;; | |
restart|force-reload) | |
log_daemon_msg "Restarting $DESC" | |
stop_daemon | |
sleep 1 | |
start_daemon | |
log_end_msg 0 | |
;; | |
status) | |
status_of_proc "$DAEMON" "$DESC" && exit 0 || exit $? | |
;; | |
*) | |
log_action_msg "Usage: service $NAME {start|stop|reload|force-reload|restart|status}" || true | |
exit 2 | |
;; | |
esac | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment