stdd.init 2.7 KB

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