init.debian 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. #!/bin/sh
  2. ### BEGIN INIT INFO
  3. # Provides: ympd
  4. # Required-Start: $remote_fs mpd
  5. # Required-Stop: $remote_fs mpd
  6. # Default-Start: 2 3 4 5
  7. # Default-Stop: 0 1 6
  8. # Short-Description: Daemonized version of ympd.
  9. # Description: Enable service provided by ympd.
  10. ### END INIT INFO
  11. #Author: Andrew Karpow <andy@ndyk.de>
  12. . /lib/lsb/init-functions
  13. PATH=/sbin:/usr/sbin:/bin:/usr/bin
  14. DESC="ympd Daemon"
  15. NAME=ympd
  16. DAEMON=/usr/bin/$NAME
  17. PIDFILE=/var/run/$NAME.pid
  18. SCRIPTNAME=/etc/init.d/$NAME
  19. LOG_OUT=/var/log/$NAME.out
  20. LOG_ERR=/var/log/$NAME.err
  21. YMPD_USER=nobody
  22. MPD_HOST=localhost
  23. MPD_PORT=6600
  24. WEB_PORT=8080
  25. DIRBLE_API_TOKEN=2e223c9909593b94fc6577361a
  26. # Exit if the package is not installed
  27. [ -x "$DAEMON" ] || exit 0
  28. # Read configuration variable file if it is present
  29. [ -r /etc/default/$NAME ] && . /etc/default/$NAME
  30. # Load the VERBOSE setting and other rcS variables
  31. [ -f /etc/default/rcS ] && . /etc/default/rcS
  32. DAEMON_OPT="--user $YMPD_USER --mpdpass '$MPD_PASSWORD' --webport $WEB_PORT --host $MPD_HOST --port $MPD_PORT --dirbletoken $DIRBLE_API_TOKEN"
  33. do_start()
  34. {
  35. start-stop-daemon --start --background --quiet --pidfile $PIDFILE --make-pidfile \
  36. --exec $DAEMON --test > /dev/null || return 1
  37. start-stop-daemon --start --background --quiet --pidfile $PIDFILE --make-pidfile \
  38. --exec $DAEMON -- $DAEMON_OPT || return 2
  39. }
  40. do_stop()
  41. {
  42. start-stop-daemon --stop --quiet --retry=TERM/30/KILL/5 --pidfile $PIDFILE --name $NAME
  43. RETVAL="$?"
  44. [ "$RETVAL" = 2 ] && return 2
  45. rm -f $PIDFILE
  46. return "$RETVAL"
  47. }
  48. case "$1" in
  49. start)
  50. [ "$VERBOSE" != no ] && log_daemon_msg "Starting $DESC" "$NAME"
  51. do_start
  52. case "$?" in
  53. 0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
  54. 2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
  55. esac
  56. ;;
  57. stop)
  58. [ "$VERBOSE" != no ] && log_daemon_msg "Stopping $DESC" "$NAME"
  59. do_stop
  60. case "$?" in
  61. 0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
  62. 2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
  63. esac
  64. ;;
  65. status)
  66. status_of_proc "$DAEMON" "$NAME" && exit 0 || exit $?
  67. ;;
  68. restart|force-reload)
  69. #
  70. # If the "reload" option is implemented then remove the
  71. # 'force-reload' alias
  72. #
  73. log_daemon_msg "Restarting $DESC" "$NAME"
  74. do_stop
  75. case "$?" in
  76. 0|1)
  77. do_start
  78. case "$?" in
  79. 0) log_end_msg 0 ;;
  80. 1) log_end_msg 1 ;; # Old process is still running
  81. *) log_end_msg 1 ;; # Failed to start
  82. esac
  83. ;;
  84. *)
  85. # Failed to stop
  86. log_end_msg 1
  87. ;;
  88. esac
  89. ;;
  90. *)
  91. echo "Usage: $SCRIPTNAME {start|stop|status|restart|force-reload}" >&2
  92. exit 3
  93. ;;
  94. esac