root/freepbx/branches/2.5/start_asterisk

Revision 7552, 3.2 kB (checked in by mickecarlsson, 4 years ago)

Added GPL license text to various files

  • Property svn:eol-style set to native
  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
Line 
1 #!/usr/bin/env bash
2 # This file is part of FreePBX.
3 #
4 #    FreePBX is free software: you can redistribute it and/or modify
5 #    it under the terms of the GNU General Public License as published by
6 #    the Free Software Foundation, either version 2 of the License, or
7 #    (at your option) any later version.
8 #
9 #    FreePBX is distributed in the hope that it will be useful,
10 #    but WITHOUT ANY WARRANTY; without even the implied warranty of
11 #    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 #    GNU General Public License for more details.
13 #
14 #    You should have received a copy of the GNU General Public License
15 #    along with FreePBX.  If not, see <http://www.gnu.org/licenses/>.
16 #
17 #    Copyright 2007, Philippe Lindheimer
18 #
19 ROOT_UID=0   # root uid is 0
20 E_NOTROOT=67   # Non-root exit error
21
22 echo
23 # check to see if we are root
24 if [ "$UID" -ne "$ROOT_UID" ]
25 then
26   echo "Sorry, you must be root to run this script."
27   echo
28   exit $E_NOTROOT
29 fi
30
31 check_asterisk() {
32 # check to see if asterisk is running
33 # Note, this isn't fool-proof.  If safe_asterisk is constantly restarting a dying asterisk, then there is a chance pidof will return non zero.  We call this twice to reduce chances of this happening
34 pid_length=`pidof asterisk|awk '{print length($0)}'`
35   if [ "$pid_length" == "0" -a "$pid_length" != "" ]
36     then
37         killall -9 safe_asterisk
38         killall -9 mpg123 > /dev/null
39         echo
40         echo "-----------------------------------------------------"
41         echo "Asterisk could not start!"
42         echo "Use 'tail $ASTLOGDIR/full' to find out why."
43         echo "-----------------------------------------------------"
44         exit 0
45     fi
46 }
47
48 run_asterisk() {
49 # check to see if asterisk is running
50 echo
51 echo "STARTING ASTERISK"
52 pid_length=`pidof asterisk|awk '{print length($0)}'`
53   if [ "$pid_length" != "0" -a "$pid_length" != "" ]
54     then
55       echo "Asterisk is already running"
56     else
57       # su - asterisk -c "export PATH=$PATH:/usr/sbin && export LD_LIBRARY_PATH=/usr/local/lib && /usr/sbin/safe_asterisk"
58       export LD_LIBRARY_PATH=/usr/local/lib
59       /usr/sbin/safe_asterisk -U asterisk -G asterisk
60       sleep 5
61       check_asterisk
62       sleep 1
63       check_asterisk
64       echo "Asterisk Started"
65     fi
66 }
67
68 stop_asterisk() {
69 echo
70 echo "STOPPING ASTERISK"
71 pid_length=`pidof asterisk|awk '{print length($0)}'`
72   if [ "$pid_length" != "0" -a "$pid_length" != "" ]
73     then
74       /usr/sbin/asterisk -rx "stop gracefully"
75       echo "Asterisk Stopped"
76     fi
77 }
78
79 kill_amp() {
80   echo
81   echo "KILLING AMP PROCESSES"
82   killall -9 safe_asterisk
83   killall -9 asterisk
84   killall -9 mpg123
85   ps -ef | grep safe_opserver | grep -v grep | awk '{print $2}' | xargs kill -9
86   killall -9 op_server.pl
87 }
88
89 case "$1" in
90   start)
91     run_asterisk
92   ;;
93   stop)
94     stop_asterisk
95   ;;
96   restart)
97     stop_asterisk
98     sleep 1
99     run_asterisk
100   ;;
101   kill)
102     kill_amp
103   ;;
104   *)
105     echo "-------------FreePBX Control Script-----------------------------------------------"
106     echo
107     echo "Usage:       amportal start|stop|restart|start_fop|stop_fop|restart_fop|kill|chown"
108     echo
109     echo "start:       Starts Asterisk and Flash Operator Panel server if enabled"
110     echo "stop:        Gracefully stops Asterisk and the FOP server"
111     echo "restart:     Stop and Starts"
112     echo "kill:        Kills Asterisk and the FOP server"
113     echo
114     exit 1
115   ;;
116 esac
117
Note: See TracBrowser for help on using the browser.