Advertisement
Guest User

qBittorrent user written daemon (mirror)

a guest
Dec 1st, 2013
856
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 2.58 KB | None | 0 0
  1. #! /bin/sh
  2. ### BEGIN INIT INFO
  3. # Provides:          qbittorrent-nox
  4. # Required-Start:    $remote_fs $syslog
  5. # Required-Stop:     $remote_fs $syslog
  6. # Default-Start:     2 3 4 5
  7. # Default-Stop:      0 1 6
  8. # Short-Description: Starts QBittorrent
  9. # Description:       Start qbittorrent-nox on start. Change USER= before running
  10. ### END INIT INFO
  11.  
  12. # Author: Jesper Smith
  13. #
  14.  
  15. # Do NOT "set -e"
  16.  
  17. # PATH should only include /usr/* if it runs after the mountnfs.sh script
  18. PATH=/sbin:/usr/sbin:/bin:/usr/bin
  19. DESC="QBittorrent"
  20. NAME=qbittorrent-nox
  21. DAEMON=/usr/bin/$NAME
  22. DAEMON_ARGS=""
  23. PIDFILE=/var/run/$NAME.pid
  24. SCRIPTNAME=/etc/init.d/qbittorrent
  25. USER=[USERNAME]
  26.  
  27. # Exit if the package is not installed
  28. [ -x "$DAEMON" ] || exit 0
  29.  
  30. # Read configuration variable file if it is present
  31. [ -r /etc/default/$NAME ] && . /etc/default/$NAME
  32.  
  33. # Load the VERBOSE setting and other rcS variables
  34. . /lib/init/vars.sh
  35.  
  36. # Define LSB log_* functions.
  37. # Depend on lsb-base (>= 3.0-6) to ensure that this file is present.
  38. . /lib/lsb/init-functions
  39.  
  40. #
  41. # Function that starts the daemon/service
  42. #
  43. do_start()
  44. {
  45.     # Return
  46.     #   0 if daemon has been started
  47.     #   1 if daemon was already running
  48.     #   2 if daemon could not be started
  49.     start-stop-daemon -c $USER -b -t --start --quiet  --exec $DAEMON  \
  50.                 || return 1
  51.  
  52.     start-stop-daemon -c $USER -b --start --quiet --exec $DAEMON -- \
  53.         $DAEMON_ARGS \
  54.         || return 2
  55.     sleep 1
  56. }
  57.  
  58. #
  59. # Function that stops the daemon/service
  60. #
  61. do_stop()
  62. {
  63.     start-stop-daemon -c $USER --quiet  --stop --exec $DAEMON
  64.     sleep 2
  65.     return "$?"
  66. }
  67.  
  68.  
  69. case "$1" in
  70.   start)
  71.     [ "$VERBOSE" != no ] && log_daemon_msg "Starting $DESC" "$NAME"
  72.     do_start
  73.     case "$?" in
  74.         0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
  75.         2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
  76.     esac
  77.     ;;
  78.   stop)
  79.     [ "$VERBOSE" != no ] && log_daemon_msg "Stopping $DESC" "$NAME"
  80.     do_stop
  81.     case "$?" in
  82.         0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
  83.         2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
  84.     esac
  85.     ;;
  86.   status)
  87.        status_of_proc "$DAEMON" "$NAME" && exit 0 || exit $?
  88.        ;;
  89.   restart|force-reload)
  90.     log_daemon_msg "Restarting $DESC" "$NAME"
  91.     do_stop
  92.     case "$?" in
  93.       0|1)
  94.         do_start
  95.         case "$?" in
  96.             0) log_end_msg 0 ;;
  97.             1) log_end_msg 1 ;; # Old process is still running
  98.             *) log_end_msg 1 ;; # Failed to start
  99.         esac
  100.         ;;
  101.       *)
  102.         # Failed to stop
  103.         log_end_msg 1
  104.         ;;
  105.     esac
  106.     ;;
  107.   *)
  108.     #echo "Usage: $SCRIPTNAME {start|stop|restart|reload|force-reload}" >&2
  109.     echo "Usage: $SCRIPTNAME {start|stop|status|restart|force-reload}" >&2
  110.     exit 3
  111.     ;;
  112. esac
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement