swupdate 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  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. ;;
  69. *)
  70. echo "$DESC is not running; none killed." >&2
  71. ;;
  72. esac
  73. # Wait for children to finish too if this is a daemon that forks
  74. # and if the daemon is only ever run from this initscript.
  75. # If the above conditions are not satisfied then add some other code
  76. # that waits for the process to drop all resources that could be
  77. # needed by services started subsequently. A last resort is to
  78. # sleep for some time.
  79. return $status
  80. }
  81. #
  82. # Function that sends a SIGHUP to the daemon/service
  83. #
  84. do_reload() {
  85. local pid status
  86. status=0
  87. # If the daemon can reload its configuration without
  88. # restarting (for example, when it is sent a SIGHUP),
  89. # then implement that here.
  90. pid=`pidofproc $NAME` || status=$?
  91. case $status in
  92. 0)
  93. echo "Reloading $DESC ..."
  94. kill -s 1 $pid || exit $?
  95. ;;
  96. *)
  97. echo "$DESC is not running; none reloaded." >&2
  98. ;;
  99. esac
  100. exit $status
  101. }
  102. #
  103. # Function that shows the daemon/service status
  104. #
  105. status_of_proc () {
  106. local pid status
  107. status=0
  108. # pidof output null when no program is running, so no "2>/dev/null".
  109. pid=`pidofproc $NAME` || status=$?
  110. case $status in
  111. 0)
  112. echo "$DESC is running ($pid)."
  113. exit 0
  114. ;;
  115. *)
  116. echo "$DESC is not running." >&2
  117. exit $status
  118. ;;
  119. esac
  120. }
  121. case "$1" in
  122. start)
  123. do_start
  124. ;;
  125. stop)
  126. do_stop || exit $?
  127. ;;
  128. status)
  129. status_of_proc
  130. ;;
  131. restart)
  132. # Always start the service regardless the status of do_stop
  133. do_stop
  134. do_start
  135. ;;
  136. try-restart|force-reload)
  137. # force-reload is the same as reload or try-restart according
  138. # to its definition, the reload is not implemented here, so
  139. # force-reload is the alias of try-restart here, but it should
  140. # be the alias of reload if reload is implemented.
  141. #
  142. # Only start the service when do_stop succeeds
  143. do_stop && do_start
  144. ;;
  145. #reload)
  146. # If the "reload" action is implemented properly, then let the
  147. # force-reload be the alias of reload, and remove it from
  148. # try-restart|force-reload)
  149. #
  150. #do_reload
  151. #;;
  152. *)
  153. echo "Usage: $0 {start|stop|status|restart|try-restart|force-reload}" >&2
  154. exit 3
  155. ;;
  156. esac