Guest User

Untitled

a guest
May 24th, 2018
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.58 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. ### BEGIN INIT INFO
  4. # Provides: srsd
  5. # Required-Start: $networking $local_fs $remote_fs $syslog
  6. # Required-Stop: $networking $local_fs $remote_fs $syslog
  7. # Should-Start:
  8. # Default-Start: 2 3 4 5
  9. # Default-Stop: 0 1 6
  10. # Short-Description: SRS daemon
  11. # Description: SRS daemon
  12. ### END INIT INFO
  13.  
  14.  
  15. # /etc/init.d/srsd: start and stop srsd
  16.  
  17. PATH=/usr/sbin:/usr/bin:/bin:/sbin
  18. DESC="SRS daemon"
  19. NAME="srsd"
  20. DAEMON=/usr/bin/srsd
  21. HASHLENGTH=24
  22. USER=Debian-exim
  23. SECRETFILE=/etc/exim4/srsd.secret
  24. PIDFILE=/var/run/exim4/srsd.pid
  25. SOCKETFILE=/tmp/srsd
  26.  
  27. # populate secret
  28. DAEMON_ARGS="--secretfile ${SECRETFILE} --hashlength ${HASHLENGTH}"
  29.  
  30. # Exit if the package is not installed
  31. [ -x "$DAEMON" ] || exit 0
  32.  
  33. # Load the VERBOSE setting and other rcS variables
  34. . /lib/init/vars.sh
  35.  
  36. # Define LSB log_* functions.
  37. # Depend on lsb-base (>= 3.2-14) to ensure that this file is present
  38. # and status_of_proc is working.
  39. . /lib/lsb/init-functions
  40.  
  41. #
  42. # Function that starts/stops/reloads the daemon/service
  43. #
  44. do_start()
  45. {
  46. # Return
  47. # 0 if daemon has been started
  48. # 1 if daemon was already running
  49. # 2 if daemon could not be started
  50. start-stop-daemon --start --quiet --pidfile $PIDFILE --chuid $USER --exec /usr/bin/perl --startas $DAEMON --test > /dev/null \
  51. || return 1
  52. start-stop-daemon --start --quiet --background --pidfile $PIDFILE --make-pidfile --chuid $USER --exec /usr/bin/perl --startas $DAEMON -- \
  53. $DAEMON_ARGS \
  54. || return 2
  55.  
  56. # Add code here, if necessary, that waits for the process to be ready
  57. # to handle requests from services started subsequently which depend
  58. # on this one. As a last resort, sleep for some time.
  59.  
  60. # change mode to 750 of socket
  61. WAIT=0
  62. while [ ! -e "$SOCKETFILE" -a $WAIT -le 5 ]; do
  63. sleep 1
  64. let "WAIT+=1"
  65. done
  66. chmod 750 "$SOCKETFILE"
  67. }
  68.  
  69. do_stop()
  70. {
  71. # Return
  72. # 0 if daemon has been stopped
  73. # 1 if daemon was already stopped
  74. # 2 if daemon could not be stopped
  75. # other if a failure occurred
  76. start-stop-daemon --stop --quiet --retry=TERM/30/KILL/5 --pidfile $PIDFILE --name $NAME
  77. RETVAL="$?"
  78. [ "$RETVAL" = 2 ] && return 2
  79. # Wait for children to finish too if this is a daemon that forks
  80. # and if the daemon is only ever run from this initscript.
  81. # If the above conditions are not satisfied then add some other code
  82. # that waits for the process to drop all resources that could be
  83. # needed by services started subsequently. A last resort is to
  84. # sleep for some time.
  85. start-stop-daemon --stop --quiet --oknodo --retry=0/30/KILL/5 --exec $DAEMON
  86. [ "$?" = 2 ] && return 2
  87. # Many daemons don't delete their pidfiles when they exit.
  88. rm -f "$PIDFILE"
  89. rm -f "$SOCKETFILE"
  90.  
  91. return "$RETVAL"
  92. }
  93.  
  94.  
  95. case "$1" in
  96.  
  97. start)
  98. [ "$VERBOSE" != no ] && log_daemon_msg "Starting $DESC" "$NAME"
  99. do_start
  100. case "$?" in
  101. 0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
  102. 2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
  103. esac
  104. ;;
  105.  
  106. stop)
  107. [ "$VERBOSE" != no ] && log_daemon_msg "Stopping $DESC" "$NAME"
  108. do_stop
  109. case "$?" in
  110. 0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
  111. 2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
  112. esac
  113. ;;
  114.  
  115. status)
  116. status_of_proc "$DAEMON" "$NAME" && exit 0 || exit $?
  117. ;;
  118.  
  119. restart|force-reload)
  120. log_daemon_msg "Restarting $DESC" "$NAME"
  121. do_stop
  122. case "$?" in
  123. 0|1)
  124. do_start
  125. case "$?" in
  126. 0) log_end_msg 0 ;;
  127. 1) log_end_msg 1 ;; # Old process is still running
  128. *) log_end_msg 1 ;; # Failed to start
  129. esac
  130. ;;
  131. *)
  132. # Failed to stop
  133. log_end_msg 1
  134. ;;
  135. esac
  136. ;;
  137. *)
  138. #echo "Usage: $SCRIPTNAME {start|stop|restart|reload|force-reload}" >&2
  139. echo "Usage: $SCRIPTNAME {start|stop|status|restart|force-reload}" >&2
  140. exit 3
  141. ;;
  142. esac
Add Comment
Please, Sign In to add comment