sr 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. #!/bin/sh
  2. #
  3. # $Id$
  4. #
  5. #
  6. # 3w-xxxx: Starts the sip_router process
  7. #
  8. # Version: @(#) /etc/rc.d/init.d/3w-xxxx
  9. #
  10. # chkconfig: 2345 20 80
  11. # description: controls execution of SIP router
  12. # processname: sr
  13. # config: /etc/sip-router/iptel.cfg
  14. # Source function library.
  15. . /etc/rc.d/init.d/functions
  16. # we use a sip-router symlink -- that allows us to have a different name
  17. # in process table so that killalls does not start other sip-routers
  18. # run from somewhere else
  19. BINNAME=sr
  20. HM=/home/srouter
  21. SERDIR=$HM/sip_router
  22. ETC=/etc/sip-router/iptel.cfg
  23. PIDFILE=/run/sr.pid
  24. [email protected]
  25. USR=510
  26. GRP=510
  27. MONIT=/usr/local/bin/monit
  28. MONITRC=/usr/local/etc/monitrc
  29. RETVAL=0
  30. BIN=$HM/bin/$BINNAME
  31. MYDIR=$HM/core
  32. CORE=$MYDIR/core
  33. TMP=/tmp/srcore.$$
  34. sip_router_start() {
  35. if [ -r $BIN -a -r $CORE ] ; then
  36. echo "before startup sip-router core found on `date` at `hostname`" > $TMP
  37. echo "----------------------------------" >> $TMP
  38. DATE=`date "+%Y-%m-%d--%H-%M"`
  39. NEWCORE=$MYDIR/core.$DATE
  40. mv $CORE $NEWCORE
  41. echo core stored in $NEWCORE >> $TMP
  42. gdb $BIN $NEWCORE -x test/bt.gdb -batch >> $TMP
  43. chmod a+r $NEWCORE
  44. cd $SERDIR; tar czf $MYDIR/sip-router.$DATE.tgz .
  45. mail -s "sip-router core found" $NOTIFY < $TMP
  46. rm -f $TMP
  47. fi
  48. cd $MYDIR
  49. #ulimit -c 1000000
  50. echo "Starting SIP router: "
  51. $BIN -f $ETC -w $MYDIR -P $PIDFILE
  52. RETVAL=$?
  53. echo
  54. }
  55. sip_router_stop() {
  56. echo "Stopping SIP router: "
  57. killproc $BINNAME
  58. RETVAL=$?
  59. echo
  60. }
  61. monit_start() {
  62. echo "Command Monit to start Ser..."
  63. ${MONIT} -c ${MONITRC} start sip-router
  64. RETVAL=$?
  65. echo
  66. }
  67. monit_stop() {
  68. echo "Command Monit to stop Ser..."
  69. ${MONIT} -c ${MONITRC} stop sip-router
  70. RETVAL=$?
  71. echo
  72. }
  73. # See how we were called.
  74. case "$1" in
  75. serstart)
  76. sip_router_start
  77. ;;
  78. sip-routerstop)
  79. sip_router_stop
  80. ;;
  81. sip-routerrestart)
  82. sip_router_stop
  83. echo
  84. sip_router_start
  85. ;;
  86. start)
  87. monit_start
  88. ;;
  89. stop)
  90. monit_stop
  91. ;;
  92. restart)
  93. monit_stop
  94. sleep 1
  95. monit_start
  96. ;;
  97. *)
  98. echo "Usage: $0 {start|stop|restart}"
  99. exit 1
  100. esac
  101. exit $RETVAL