Created
December 17, 2016 20:04
-
-
Save nokimaro/f0c2b7411f4d3ec39ee86e60e4556b13 to your computer and use it in GitHub Desktop.
utserver init.d script
This file contains hidden or 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/bash | |
| ### BEGIN INIT INFO | |
| # Provides: utserver | |
| # 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: Start or stop the utserver. | |
| ### END INIT INFO | |
| CHDIR=/opt/utorrent-server-alpha-v3_3 | |
| NAME=utserver | |
| OPTIONS="-LOGFILE" | |
| DAEMON=$CHDIR/$NAME | |
| USER=root | |
| PIDFILE=/var/run/$NAME.pid | |
| STOP_TIMEOUT=5 | |
| [ -x $DAEMON ] || exit 1 | |
| . /lib/lsb/init-functions | |
| start_daemon () { | |
| pgrep -U $USER $NAME >/dev/null && echo "$NAME is already running" && log_end_msg 1 | |
| rm -f $PIDFILE >/dev/null | |
| start-stop-daemon --start --quiet --make-pidfile --pidfile $PIDFILE --chuid $USER --chdir $CHDIR --background --exec $DAEMON -- $OPTIONS | |
| } | |
| case "$1" in | |
| start) | |
| log_daemon_msg "Starting $NAME daemon" "$NAME" | |
| start_daemon | |
| log_end_msg 0 | |
| ;; | |
| stop) | |
| log_daemon_msg "Stopping $NAME daemon" "$NAME" | |
| start-stop-daemon --stop --quiet --pidfile $PIDFILE --exec $DAEMON --retry $STOP_TIMEOUT || log_end_msg 1 | |
| pgrep -U $USER $NAME >/dev/null || rm -f $PIDFILE >/dev/null | |
| log_end_msg 0 | |
| ;; | |
| restart) | |
| log_daemon_msg "Restarting $NAME daemon" "$NAME" | |
| start-stop-daemon --stop --quiet --pidfile $PIDFILE --exec $DAEMON --retry $STOP_TIMEOUT || log_end_msg 1 | |
| start_daemon | |
| log_end_msg 0 | |
| ;; | |
| *) | |
| echo "Usage: /etc/init.d/$NAME {start|stop|restart}" | |
| exit 2 | |
| ;; | |
| esac | |
| exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment