freeswitch.init.suse 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  1. #!/bin/sh
  2. #
  3. # Template SUSE system startup script for example service/daemon FREESWITCH
  4. # Copyright (C) 1995--2005 Kurt Garloff, SUSE / Novell Inc.
  5. #
  6. # This library is free software; you can redistribute it and/or modify it
  7. # under the terms of the GNU Lesser General Public License as published by
  8. # the Free Software Foundation; either version 2.1 of the License, or (at
  9. # your option) any later version.
  10. #
  11. # This library is distributed in the hope that it will be useful, but
  12. # WITHOUT ANY WARRANTY; without even the implied warranty of
  13. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. # Lesser General Public License for more details.
  15. #
  16. # You should have received a copy of the GNU Lesser General Public
  17. # License along with this library; if not, write to the Free Software
  18. # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307,
  19. # USA.
  20. #
  21. # /etc/init.d/freeswitch
  22. # and its symbolic link
  23. # /(usr/)sbin/rcfreeswitch
  24. #
  25. # Template system startup script for some example service/daemon FREESWITCH
  26. #
  27. # LSB compatible service control script; see http://www.linuxbase.org/spec/
  28. #
  29. # Note: This template uses functions rc_XXX defined in /etc/rc.status on
  30. # UnitedLinux/SUSE/Novell based Linux distributions. If you want to base your
  31. # script on this template and ensure that it works on non UL based LSB
  32. # compliant Linux distributions, you either have to provide the rc.status
  33. # functions from UL or change the script to work without them.
  34. # See skeleton.compat for a template that works with other distros as well.
  35. #
  36. ### BEGIN INIT INFO
  37. # Provides: freeswitch
  38. # Required-Start: $syslog $remote_fs
  39. # Should-Start: $time ypbind sendmail mysql postgresql
  40. # Required-Stop: $syslog $remote_fs
  41. # Should-Stop: $time ypbind sendmail
  42. # Default-Start: 3 5
  43. # Default-Stop: 0 1 2 6
  44. # Short-Description: FREESWITCH XYZ daemon providing ZYX
  45. # Description: Start FREESWITCH the Open Source
  46. # Voice Platform
  47. ### END INIT INFO
  48. #
  49. FREESWITCH_BIN=/opt/freeswitch/bin/freeswitch
  50. # Check for existence of needed config file and read it
  51. FREESWITCH_CONFIG=/etc/sysconfig/freeswitch
  52. test -r $FREESWITCH_CONFIG || { echo "$FREESWITCH_CONFIG not existing";
  53. if [ "$1" = "stop" ]; then exit 0;
  54. else exit 6; fi; }
  55. # Read config
  56. . $FREESWITCH_CONFIG
  57. # Check for missing binaries (stale symlinks should not happen)
  58. # Note: Special treatment of stop for LSB conformance
  59. test -x $FREESWITCH_BIN || { echo "$FREESWITCH_BIN not installed";
  60. if [ "$1" = "stop" ]; then exit 0;
  61. else exit 5; fi; }
  62. # Source LSB init functions
  63. # providing start_daemon, killproc, pidofproc,
  64. # log_success_msg, log_failure_msg and log_warning_msg.
  65. # This is currently not used by UnitedLinux based distributions and
  66. # not needed for init scripts for UnitedLinux only. If it is used,
  67. # the functions from rc.status should not be sourced or used.
  68. #. /lib/lsb/init-functions
  69. # Shell functions sourced from /etc/rc.status:
  70. # rc_check check and set local and overall rc status
  71. # rc_status check and set local and overall rc status
  72. # rc_status -v be verbose in local rc status and clear it afterwards
  73. # rc_status -v -r ditto and clear both the local and overall rc status
  74. # rc_status -s display "skipped" and exit with status 3
  75. # rc_status -u display "unused" and exit with status 3
  76. # rc_failed set local and overall rc status to failed
  77. # rc_failed <num> set local and overall rc status to <num>
  78. # rc_reset clear both the local and overall rc status
  79. # rc_exit exit appropriate to overall rc status
  80. # rc_active checks whether a service is activated by symlinks
  81. . /etc/rc.status
  82. # Reset status of this service
  83. rc_reset
  84. # Return values acc. to LSB for all commands but status:
  85. # 0 - success
  86. # 1 - generic or unspecified error
  87. # 2 - invalid or excess argument(s)
  88. # 3 - unimplemented feature (e.g. "reload")
  89. # 4 - user had insufficient privileges
  90. # 5 - program is not installed
  91. # 6 - program is not configured
  92. # 7 - program is not running
  93. # 8--199 - reserved (8--99 LSB, 100--149 distrib, 150--199 appl)
  94. #
  95. # Note that starting an already running service, stopping
  96. # or restarting a not-running service as well as the restart
  97. # with force-reload (in case signaling is not supported) are
  98. # considered a success.
  99. case "$1" in
  100. start)
  101. echo -n "Starting FreeSWITCH "
  102. ## Start daemon with startproc(8). If this fails
  103. ## the return value is set appropriately by startproc.
  104. /sbin/startproc $FREESWITCH_BIN $FREESWITCH_PARAMS
  105. # Remember status and be verbose
  106. rc_status -v
  107. ;;
  108. stop)
  109. echo -n "Shutting down FreeSWITCH "
  110. ## Stop daemon with killproc(8) and if this fails
  111. ## killproc sets the return value according to LSB.
  112. /sbin/killproc -TERM $FREESWITCH_BIN
  113. # Remember status and be verbose
  114. rc_status -v
  115. ;;
  116. try-restart|condrestart)
  117. ## Do a restart only if the service was active before.
  118. ## Note: try-restart is now part of LSB (as of 1.9).
  119. ## RH has a similar command named condrestart.
  120. if test "$1" = "condrestart"; then
  121. echo "${attn} Use try-restart ${done}(LSB)${attn} rather than condrestart ${warn}(RH)${norm}"
  122. fi
  123. $0 status
  124. if test $? = 0; then
  125. $0 restart
  126. else
  127. rc_reset # Not running is not a failure.
  128. fi
  129. # Remember status and be quiet
  130. rc_status
  131. ;;
  132. restart)
  133. ## Stop the service and regardless of whether it was
  134. ## running or not, start it again.
  135. $0 stop
  136. $0 start
  137. # Remember status and be quiet
  138. rc_status
  139. ;;
  140. force-reload)
  141. ## Signal the daemon to reload its config. Most daemons
  142. ## do this on signal 1 (SIGHUP).
  143. ## If it does not support it, restart the service if it
  144. ## is running.
  145. echo -n "Reload service FreeSWITCH "
  146. ## if it supports it:
  147. /sbin/killproc -HUP $FREESWITCH_BIN
  148. #touch /var/run/FREESWITCH.pid
  149. rc_status -v
  150. ## Otherwise:
  151. #$0 try-restart
  152. #rc_status
  153. ;;
  154. reload)
  155. ## Like force-reload, but if daemon does not support
  156. ## signaling, do nothing (!)
  157. # If it supports signaling:
  158. echo -n "Reload service FreeSWITCH "
  159. /sbin/killproc -HUP $FREESWITCH_BIN
  160. #touch /var/run/FREESWITCH.pid
  161. rc_status -v
  162. ## Otherwise if it does not support reload:
  163. #rc_failed 3
  164. #rc_status -v
  165. ;;
  166. status)
  167. echo -n "Checking for service FreeSWITCH "
  168. ## Check status with checkproc(8), if process is running
  169. ## checkproc will return with exit status 0.
  170. # Return value is slightly different for the status command:
  171. # 0 - service up and running
  172. # 1 - service dead, but /var/run/ pid file exists
  173. # 2 - service dead, but /var/lock/ lock file exists
  174. # 3 - service not running (unused)
  175. # 4 - service status unknown :-(
  176. # 5--199 reserved (5--99 LSB, 100--149 distro, 150--199 appl.)
  177. # NOTE: checkproc returns LSB compliant status values.
  178. /sbin/checkproc $FREESWITCH_BIN
  179. # NOTE: rc_status knows that we called this init script with
  180. # "status" option and adapts its messages accordingly.
  181. rc_status -v
  182. ;;
  183. probe)
  184. ## Optional: Probe for the necessity of a reload, print out the
  185. ## argument to this init script which is required for a reload.
  186. ## Note: probe is not (yet) part of LSB (as of 1.9)
  187. test ${FREESWITCH_HOME}/conf/freeswitch.xml -nt ${FREESWITCH_HOME}/run/freeswitch.pid && echo reload
  188. ;;
  189. *)
  190. echo "Usage: $0 {start|stop|status|try-restart|restart|force-reload|reload|probe}"
  191. exit 1
  192. ;;
  193. esac
  194. rc_exit