Personal wiki notebook (not under development)

luminotes_debian_initscript 4.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. #! /bin/sh
  2. ### BEGIN INIT INFO
  3. # Provides: luminotes
  4. # Required-Start: $local_fs $remote_fs
  5. # Required-Stop: $local_fs $remote_fs
  6. # Default-Start: 2 3 4 5
  7. # Default-Stop: 0 1 6
  8. # Short-Description: Luminotes
  9. # Description: personal wiki notebook server
  10. ### END INIT INFO
  11. # Author: Dan Helfman <dan@luminotes.com>
  12. # Do NOT "set -e"
  13. # PATH should only include /usr/* if it runs after the mountnfs.sh script
  14. PATH=/sbin:/usr/sbin:/bin:/usr/bin
  15. DESC="personal wiki notebook server"
  16. NAME=luminotes
  17. DAEMON=/home/luminotes/luminotes/$NAME.py
  18. DAEMON_ARGS=""
  19. PIDFILE=/var/run/$NAME.pid
  20. SCRIPTNAME=/etc/init.d/$NAME
  21. CHUID=luminotes
  22. CHDIR=/home/luminotes/luminotes
  23. # Exit if the package is not installed
  24. [ -x "$DAEMON" ] || exit 0
  25. # Read configuration variable file if it is present
  26. [ -r /etc/default/$NAME ] && . /etc/default/$NAME
  27. # Load the VERBOSE setting and other rcS variables
  28. . /lib/init/vars.sh
  29. # Define LSB log_* functions.
  30. # Depend on lsb-base (>= 3.0-6) to ensure that this file is present.
  31. . /lib/lsb/init-functions
  32. #
  33. # Function that starts the daemon/service
  34. #
  35. do_start()
  36. {
  37. # Return
  38. # 0 if daemon has been started
  39. # 1 if daemon was already running
  40. # 2 if daemon could not be started
  41. start-stop-daemon --start --quiet --chuid $CHUID --chdir $CHDIR --make-pidfile --pidfile $PIDFILE --background --exec $DAEMON --test > /dev/null \
  42. || return 1
  43. start-stop-daemon --start --quiet --chuid $CHUID --chdir $CHDIR --make-pidfile --pidfile $PIDFILE --background --exec $DAEMON -- \
  44. $DAEMON_ARGS \
  45. || return 2
  46. # Add code here, if necessary, that waits for the process to be ready
  47. # to handle requests from services started subsequently which depend
  48. # on this one. As a last resort, sleep for some time.
  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 --name $NAME.py
  61. RETVAL="$?"
  62. [ "$RETVAL" = 2 ] && return 2
  63. # Wait for children to finish too if this is a daemon that forks
  64. # and if the daemon is only ever run from this initscript.
  65. # If the above conditions are not satisfied then add some other code
  66. # that waits for the process to drop all resources that could be
  67. # needed by services started subsequently. A last resort is to
  68. # sleep for some time.
  69. start-stop-daemon --stop --quiet --oknodo --retry=0/30/KILL/5 --exec $DAEMON
  70. [ "$?" = 2 ] && return 2
  71. # Many daemons don't delete their pidfiles when they exit.
  72. rm -f $PIDFILE
  73. return "$RETVAL"
  74. }
  75. #
  76. # Function that sends a SIGHUP to the daemon/service
  77. #
  78. do_reload() {
  79. #
  80. # If the daemon can reload its configuration without
  81. # restarting (for example, when it is sent a SIGHUP),
  82. # then implement that here.
  83. #
  84. start-stop-daemon --stop --signal 1 --quiet --pidfile $PIDFILE --name $NAME.py
  85. return 0
  86. }
  87. case "$1" in
  88. start)
  89. [ "$VERBOSE" != no ] && log_daemon_msg "Starting $DESC" "$NAME"
  90. do_start
  91. case "$?" in
  92. 0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
  93. 2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
  94. esac
  95. ;;
  96. stop)
  97. [ "$VERBOSE" != no ] && log_daemon_msg "Stopping $DESC" "$NAME"
  98. do_stop
  99. case "$?" in
  100. 0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
  101. 2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
  102. esac
  103. ;;
  104. #reload|force-reload)
  105. #
  106. # If do_reload() is not implemented then leave this commented out
  107. # and leave 'force-reload' as an alias for 'restart'.
  108. #
  109. #log_daemon_msg "Reloading $DESC" "$NAME"
  110. #do_reload
  111. #log_end_msg $?
  112. #;;
  113. restart|force-reload)
  114. #
  115. # If the "reload" option is implemented then remove the
  116. # 'force-reload' alias
  117. #
  118. log_daemon_msg "Restarting $DESC" "$NAME"
  119. do_stop
  120. case "$?" in
  121. 0|1)
  122. do_start
  123. case "$?" in
  124. 0) log_end_msg 0 ;;
  125. 1) log_end_msg 1 ;; # Old process is still running
  126. *) log_end_msg 1 ;; # Failed to start
  127. esac
  128. ;;
  129. *)
  130. # Failed to stop
  131. log_end_msg 1
  132. ;;
  133. esac
  134. ;;
  135. *)
  136. #echo "Usage: $SCRIPTNAME {start|stop|restart|reload|force-reload}" >&2
  137. echo "Usage: $SCRIPTNAME {start|stop|restart|force-reload}" >&2
  138. exit 3
  139. ;;
  140. esac
  141. :