stdd.init 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. #! /bin/sh
  2. ### BEGIN INIT INFO
  3. # Provides: stdd
  4. # Required-Start: $syslog
  5. # Required-Stop: $syslog
  6. # Default-Start: 2 3 4 5
  7. # Default-Stop: 0 1 6
  8. # Short-Description: stdd - the simple time display daemon
  9. # Description: Init script for stdd, the simple time
  10. # display daemon written for the Raspberry PI.
  11. ### END INIT INFO
  12. # Author: Helmut Pozimski <helmut@pozimski.eu>
  13. # PATH should only include /usr/* if it runs after the mountnfs.sh script
  14. PATH=/sbin:/usr/sbin:/bin:/usr/bin
  15. DESC="simple time display daemon"
  16. NAME="stdd"
  17. DAEMON=/usr/bin/$NAME
  18. DAEMON_ARGS="-d -c /etc/stdd.conf -u $STDD_USER -g $STDD_GROUP"
  19. SCRIPTNAME=/etc/init.d/$NAME
  20. if [ -d /run ]; then
  21. PIDFILE=/run/stdd
  22. else
  23. PIDFILE=/var/run/stdd
  24. fi
  25. # Exit if the package is not installed
  26. [ -x "$DAEMON" ] || exit 0
  27. # Read configuration variable file if it is present
  28. [ -r /etc/default/$NAME ] && . /etc/default/$NAME
  29. # Load the VERBOSE setting and other rcS variables
  30. . /lib/init/vars.sh
  31. # Define LSB log_* functions.
  32. # Depend on lsb-base (>= 3.2-14) to ensure that this file is present
  33. # and status_of_proc is working.
  34. . /lib/lsb/init-functions
  35. #
  36. # Function that starts the daemon/service
  37. #
  38. do_start()
  39. {
  40. # Return
  41. # 0 if daemon has been started
  42. # 1 if daemon was already running
  43. # 2 if daemon could not be started
  44. start-stop-daemon --status --quiet --pidfile $PIDFILE > /dev/null \
  45. && exit 1
  46. start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON -- \
  47. $DAEMON_ARGS \
  48. || return 2
  49. }
  50. #
  51. # Function that stops the daemon/service
  52. #
  53. do_stop()
  54. {
  55. # Return
  56. # 0 if daemon has been stopped
  57. # 1 if daemon was already stopped
  58. # 2 if daemon could not be stopped
  59. # other if a failure occurred
  60. start-stop-daemon --stop --quiet --retry=TERM/30/KILL/5 --pidfile $PIDFILE
  61. RETVAL="$?"
  62. return "$RETVAL"
  63. }
  64. case "$1" in
  65. start)
  66. log_daemon_msg "Starting $DESC" "$NAME"
  67. do_start
  68. case "$?" in
  69. 0|1) log_end_msg 0 ;;
  70. 2) log_end_msg 1 ;;
  71. esac
  72. ;;
  73. stop)
  74. log_daemon_msg "Stopping $DESC" "$NAME"
  75. do_stop
  76. case "$?" in
  77. 0|1) log_end_msg 0 ;;
  78. 2) log_end_msg 1 ;;
  79. esac
  80. ;;
  81. status)
  82. status_of_proc "$DAEMON" "$NAME" && exit 0 || exit $?
  83. ;;
  84. restart|force-reload)
  85. #
  86. # If the "reload" option is implemented then remove the
  87. # 'force-reload' alias
  88. #
  89. log_daemon_msg "Restarting $DESC" "$NAME"
  90. do_stop
  91. case "$?" in
  92. 0|1)
  93. do_start
  94. case "$?" in
  95. 0) log_end_msg 0 ;;
  96. 1) log_end_msg 1 ;; # Old process is still running
  97. *) log_end_msg 1 ;; # Failed to start
  98. esac
  99. ;;
  100. *)
  101. # Failed to stop
  102. log_end_msg 1
  103. ;;
  104. esac
  105. ;;
  106. *)
  107. echo "Usage: $SCRIPTNAME {start|stop|status|restart|force-reload}" >&2
  108. exit 3
  109. ;;
  110. esac
  111. :