freeswitch-sysvinit.freeswitch.init 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. #!/bin/sh
  2. ### -*- mode:shell-script; indent-tabs-mode:nil; sh-basic-offset:2 -*-
  3. ### BEGIN INIT INFO
  4. # Provides: freeswitch
  5. # Required-Start: $network $remote_fs $local_fs
  6. # Required-Stop: $network $remote_fs $local_fs
  7. # Should-Start: postgresql mysql memcached mongodb
  8. # Should-Stop: postgresql mysql memcached mongodb
  9. # Default-Start: 2 3 4 5
  10. # Default-Stop: 0 1 6
  11. # Short-Description: FreeSWITCH Softswitch
  12. # Description: FreeSWITCH Softswitch
  13. ### END INIT INFO
  14. # Author: Travis Cross <tc@traviscross.com>
  15. PATH=/sbin:/usr/sbin:/bin:/usr/bin
  16. DESC=freeswitch
  17. NAME=freeswitch
  18. DAEMON=/usr/bin/freeswitch
  19. USER=freeswitch
  20. DAEMON_ARGS="-u $USER -ncwait"
  21. CONFDIR=/etc/$NAME
  22. RUNDIR=/var/run/$NAME
  23. PIDFILE=$RUNDIR/$NAME.pid
  24. SCRIPTNAME=/etc/init.d/$NAME
  25. WORKDIR=/var/lib/$NAME
  26. [ -x $DAEMON ] || exit 0
  27. [ -r /etc/default/$NAME ] && . /etc/default/$NAME
  28. . /lib/init/vars.sh
  29. . /lib/lsb/init-functions
  30. do_start() {
  31. if ! [ -f $CONFDIR/freeswitch.xml ]; then
  32. echo "$NAME is not configured so not starting.">&2
  33. echo "Please add configuration under /etc/freeswitch">&2
  34. echo "e.g. Install freeswitch-conf-vanilla, then:">&2
  35. echo "cp -a /usr/share/freeswitch/conf/vanilla /etc/freeswitch">&2
  36. return 3
  37. fi
  38. # Directory in /var/run may disappear on reboot (e.g. when tmpfs used for /var/run).
  39. mkdir -p $RUNDIR
  40. chown -R $USER: $RUNDIR
  41. chmod -R ug=rwX,o= $RUNDIR
  42. start-stop-daemon --start --quiet \
  43. --pidfile $PIDFILE --exec $DAEMON --name $NAME --user $USER \
  44. --test > /dev/null \
  45. || return 1
  46. ulimit -s 240
  47. start-stop-daemon --start --quiet \
  48. --pidfile $PIDFILE --exec $DAEMON --name $NAME --user $USER \
  49. --chdir $WORKDIR -- $DAEMON_ARGS $DAEMON_OPTS \
  50. || return 2
  51. return 0
  52. }
  53. stop_fs() {
  54. start-stop-daemon --stop --quiet \
  55. --pidfile $PIDFILE --name $NAME --user $USER \
  56. --retry=TERM/30/KILL/5
  57. }
  58. stop_fs_children() {
  59. start-stop-daemon --stop --quiet \
  60. --exec $DAEMON \
  61. --oknodo --retry=0/30/KILL/5
  62. }
  63. do_stop() {
  64. stop_fs
  65. RETVAL="$?"
  66. [ "$RETVAL" -eq 2 ] && return 2
  67. stop_fs_children
  68. [ "$?" -eq 2 ] && return 2
  69. rm -f $PIDFILE
  70. return "$RETVAL"
  71. }
  72. do_reload() {
  73. start-stop-daemon --stop --quiet \
  74. --pidfile $PIDFILE --name $NAME --user $USER \
  75. --signal HUP
  76. }
  77. case "$1" in
  78. start)
  79. [ "$VERBOSE" != no ] && log_daemon_msg "Starting $DESC " "$NAME"
  80. do_start
  81. case "$?" in
  82. 0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
  83. 2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
  84. esac
  85. ;;
  86. stop)
  87. [ "$VERBOSE" != no ] && log_daemon_msg "Stopping $DESC" "$NAME"
  88. do_stop
  89. case "$?" in
  90. 0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
  91. 2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
  92. esac
  93. ;;
  94. status)
  95. status_of_proc "$DAEMON" "$NAME" && exit 0 || exit $?
  96. ;;
  97. reload|force-reload)
  98. log_daemon_msg "Reloading $DESC" "$NAME"
  99. do_reload
  100. log_end_msg $?
  101. ;;
  102. restart)
  103. log_daemon_msg "Restarting $DESC" "$NAME"
  104. do_stop
  105. case "$?" in
  106. 0|1)
  107. do_start
  108. case "$?" in
  109. 0) log_end_msg 0 ;;
  110. 1|*) log_end_msg 1 ;;
  111. esac
  112. ;;
  113. *) log_end_msg 1 ;;
  114. esac
  115. ;;
  116. *)
  117. echo "Usage: $SCRIPTNAME {start|stop|status|restart|force-reload}" >&2
  118. exit 3
  119. ;;
  120. esac
  121. exit 0