vonFS

freeswitch.init on Debian 8

May 2nd, 2016
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 4.51 KB | None | 0 0
  1. #!/bin/bash
  2. ### BEGIN INIT INFO
  3. # Provides: freeswitch
  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. # Description: Freeswitch debian init script.
  9. # Author: Matthew Williams
  10. #
  11. ### END INIT INFO
  12. # Do NOT "set -e"
  13.  
  14. # PATH should only include /usr/* if it runs after the mountnfs.sh script
  15. PATH=/sbin:/usr/sbin:/bin:/usr/bin:/usr/local/bin
  16. DESC="Freeswitch"
  17. NAME=freeswitch
  18. DAEMON=/usr/local/freeswitch/bin/$NAME
  19. DAEMON_ARGS="-nc -nonat"
  20. PIDFILE=/usr/local/freeswitch/run/$NAME.pid
  21. SCRIPTNAME=/etc/init.d/$NAME
  22.  
  23. FS_USER=freeswitch
  24. FS_GROUP=daemon
  25.  
  26. # Exit if the package is not installed
  27. [ -x "$DAEMON" ] || exit 0
  28.  
  29. # Read configuration variable file if it is present
  30. [ -r /etc/default/$NAME ] && . /etc/default/$NAME
  31.  
  32. # Load the VERBOSE setting and other rcS variables
  33. . /lib/init/vars.sh
  34.  
  35. # Define LSB log_* functions.
  36. # Depend on lsb-base (>= 3.0-6) to ensure that this file is present.
  37. . /lib/lsb/init-functions
  38.  
  39. #
  40. # Function that sets ulimit values for the daemon
  41. #
  42. do_setlimits() {
  43. ulimit -c unlimited
  44. ulimit -d unlimited
  45. ulimit -f unlimited
  46. ulimit -i unlimited
  47. ulimit -n 999999
  48. ulimit -q unlimited
  49. ulimit -u unlimited
  50. ulimit -v unlimited
  51. ulimit -x unlimited
  52. ulimit -s 240
  53. ulimit -l unlimited
  54. return 0
  55. }
  56.  
  57. #
  58. # Function that starts the daemon/service
  59. #
  60. do_start()
  61. {
  62. # Set user to run as
  63. if [ $FS_USER ] ; then
  64. DAEMON_ARGS="`echo $DAEMON_ARGS` -u $FS_USER"
  65. fi
  66. # Set group to run as
  67. if [ $FS_GROUP ] ; then
  68. DAEMON_ARGS="`echo $DAEMON_ARGS` -g $FS_GROUP"
  69. fi
  70.  
  71. # Return
  72. # 0 if daemon has been started
  73. # 1 if daemon was already running
  74. # 2 if daemon could not be started
  75. start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON --test > /dev/null -- \
  76. || return 1
  77. do_setlimits
  78. start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON --background -- \
  79. $DAEMON_ARGS \
  80. || return 2
  81. # Add code here, if necessary, that waits for the process to be ready
  82. # to handle requests from services started subsequently which depend
  83. # on this one. As a last resort, sleep for some time.
  84. }
  85.  
  86. #
  87. # Function that stops the daemon/service
  88. #
  89. do_stop()
  90. {
  91. # Return
  92. # 0 if daemon has been stopped
  93. # 1 if daemon was already stopped
  94. # 2 if daemon could not be stopped
  95. # other if a failure occurred
  96. start-stop-daemon --stop --quiet --retry=TERM/30/KILL/5 --pidfile $PIDFILE --name $NAME
  97. RETVAL="$?"
  98. [ "$RETVAL" = 2 ] && return 2
  99. # Wait for children to finish too if this is a daemon that forks
  100. # and if the daemon is only ever run from this initscript.
  101. # If the above conditions are not satisfied then add some other code
  102. # that waits for the process to drop all resources that could be
  103. # needed by services started subsequently. A last resort is to
  104. # sleep for some time.
  105. start-stop-daemon --stop --quiet --oknodo --retry=0/30/KILL/5 --exec $DAEMON
  106. [ "$?" = 2 ] && return 2
  107. # Many daemons don't delete their pidfiles when they exit.
  108. rm -f $PIDFILE
  109. return "$RETVAL"
  110. }
  111.  
  112. #
  113. # Function that sends a SIGHUP to the daemon/service
  114. #
  115. do_reload() {
  116. #
  117. # If the daemon can reload its configuration without
  118. # restarting (for example, when it is sent a SIGHUP),
  119. # then implement that here.
  120. #
  121. start-stop-daemon --stop --signal 1 --quiet --pidfile $PIDFILE --name $NAME
  122. return 0
  123. }
  124.  
  125. case "$1" in
  126. start)
  127. [ "$VERBOSE" != no ] && log_daemon_msg "Starting $DESC" "$NAME"
  128. do_start
  129. case "$?" in
  130. 0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
  131. 2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
  132. esac
  133. ;;
  134. stop)
  135. [ "$VERBOSE" != no ] && log_daemon_msg "Stopping $DESC" "$NAME"
  136. do_stop
  137. case "$?" in
  138. 0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
  139. 2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
  140. esac
  141. ;;
  142. status)
  143. status_of_proc -p $PIDFILE $DAEMON $NAME && exit 0 || exit $?
  144. ;;
  145. #reload|force-reload)
  146. #
  147. # If do_reload() is not implemented then leave this commented out
  148. # and leave 'force-reload' as an alias for 'restart'.
  149. #
  150. #log_daemon_msg "Reloading $DESC" "$NAME"
  151. #do_reload
  152. #log_end_msg $?
  153. #;;
  154. restart|force-reload)
  155. #
  156. # If the "reload" option is implemented then remove the
  157. # 'force-reload' alias
  158. #
  159. log_daemon_msg "Restarting $DESC" "$NAME"
  160. do_stop
  161. case "$?" in
  162. 0|1)
  163. do_start
  164. case "$?" in
  165. 0) log_end_msg 0 ;;
  166. 1) log_end_msg 1 ;; # Old process is still running
  167. *) log_end_msg 1 ;; # Failed to start
  168. esac
  169. ;;
  170. *)
  171. # Failed to stop
  172. log_end_msg 1
  173. ;;
  174. esac
  175. ;;
  176. *)
  177. #echo "Usage: $SCRIPTNAME {start|stop|restart|reload|force-reload}" >&2
  178. echo "Usage: $SCRIPTNAME {start|stop|restart|force-reload}" >&2
  179. exit 3
  180. ;;
  181. esac
  182.  
  183. exit 0
Add Comment
Please, Sign In to add comment