swupdate 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. #! /bin/sh
  2. ### BEGIN INIT INFO
  3. # Provides: swupdate
  4. # Required-Start: $local_fs
  5. # Should-Start:
  6. # Required-Stop: $local_fs
  7. # Should-Stop:
  8. # Default-Start: 2 3 4 5
  9. # Default-Stop: 0 1 6
  10. # Short-Description: Start swupdate application
  11. ### END INIT INFO
  12. # The definition of actions: (From LSB 3.1.0)
  13. # start start the service
  14. # stop stop the service
  15. # restart stop and restart the service if the service is already running,
  16. # otherwise start the service
  17. # try-restart restart the service if the service is already running
  18. # reload cause the configuration of the service to be reloaded without
  19. # actually stopping and restarting the service
  20. # force-reload cause the configuration to be reloaded if the service supports
  21. # this, otherwise restart the service if it is running
  22. # status print the current status of the service
  23. # The start, stop, restart, force-reload, and status actions shall be supported
  24. # by all init scripts; the reload and the try-restart actions are optional
  25. # PATH should only include /usr/* if it runs after the mountnfs.sh script
  26. PATH=/sbin:/usr/sbin:/bin:/usr/bin
  27. DESC="swupdate"
  28. NAME="swupdate"
  29. DAEMON=/usr/lib/swupdate/swupdate.sh
  30. PIDFILE=/var/run/$NAME.pid
  31. . /etc/init.d/functions || exit 1
  32. # Exit if the package is not installed
  33. [ -x "$DAEMON" ] || exit 0
  34. # Read configuration variable file if it is present
  35. [ -r /etc/default/$NAME ] && . /etc/default/$NAME
  36. #
  37. # Function that starts the daemon/service
  38. #
  39. do_start() {
  40. local status pid
  41. status=0
  42. pid=`pidofproc $NAME` || status=$?
  43. case $status in
  44. 0)
  45. echo "$DESC already running ($pid)."
  46. exit 1
  47. ;;
  48. *)
  49. echo "Starting $DESC ..."
  50. cd /home/root
  51. exec $DAEMON &
  52. exit 0
  53. ;;
  54. esac
  55. }
  56. #
  57. # Function that stops the daemon/service
  58. #
  59. do_stop() {
  60. local pid status
  61. status=0
  62. pid=`pidofproc $NAME` || status=$?
  63. case $status in
  64. 0)
  65. # Exit when fail to stop, the kill would complain when fail
  66. kill -s 15 $pid >/dev/null && rm -f $PIDFILE && \
  67. echo "Stopped $DESC ($pid)." || exit $?
  68. # Wait up to 10 seconds for the process to exit
  69. for i in `seq 10`; do
  70. if ! pidofproc $NAME > /dev/null; then
  71. break
  72. fi
  73. sleep 1
  74. done
  75. ;;
  76. *)
  77. echo "$DESC is not running; none killed." >&2
  78. ;;
  79. esac
  80. return 0
  81. }
  82. #
  83. # Function that sends a SIGHUP to the daemon/service
  84. #
  85. do_reload() {
  86. local pid status
  87. status=0
  88. # If the daemon can reload its configuration without
  89. # restarting (for example, when it is sent a SIGHUP),
  90. # then implement that here.
  91. pid=`pidofproc $NAME` || status=$?
  92. case $status in
  93. 0)
  94. echo "Reloading $DESC ..."
  95. kill -s 1 $pid || exit $?
  96. ;;
  97. *)
  98. echo "$DESC is not running; none reloaded." >&2
  99. ;;
  100. esac
  101. exit $status
  102. }
  103. #
  104. # Function that shows the daemon/service status
  105. #
  106. status_of_proc () {
  107. local pid status
  108. status=0
  109. # pidof output null when no program is running, so no "2>/dev/null".
  110. pid=`pidofproc $NAME` || status=$?
  111. case $status in
  112. 0)
  113. echo "$DESC is running ($pid)."
  114. exit 0
  115. ;;
  116. *)
  117. echo "$DESC is not running." >&2
  118. exit $status
  119. ;;
  120. esac
  121. }
  122. case "$1" in
  123. start)
  124. do_start
  125. ;;
  126. stop)
  127. do_stop || exit $?
  128. ;;
  129. status)
  130. status_of_proc
  131. ;;
  132. restart)
  133. # Always start the service regardless the status of do_stop
  134. do_stop
  135. do_start
  136. ;;
  137. try-restart|force-reload)
  138. # force-reload is the same as reload or try-restart according
  139. # to its definition, the reload is not implemented here, so
  140. # force-reload is the alias of try-restart here, but it should
  141. # be the alias of reload if reload is implemented.
  142. #
  143. # Only start the service when do_stop succeeds
  144. do_stop && do_start
  145. ;;
  146. #reload)
  147. # If the "reload" action is implemented properly, then let the
  148. # force-reload be the alias of reload, and remove it from
  149. # try-restart|force-reload)
  150. #
  151. #do_reload
  152. #;;
  153. *)
  154. echo "Usage: $0 {start|stop|status|restart|try-restart|force-reload}" >&2
  155. exit 3
  156. ;;
  157. esac