stdd.init 2.6 KB

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