root/freepbx/branches/2.3/start_asterisk

Revision 4599, 2.5 kB (checked in by p_lindheimer, 1 year ago)

added a start_asterisk script for first time installs to make sure asterisk is running as user asterisk, and modified install_amp instructions to use that script. The issue if, if you start with safe_asterisk, it will start as root

  • 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
3 ROOT_UID=0       # root uid is 0
4 E_NOTROOT=67     # Non-root exit error
5
6 echo
7 # check to see if we are root
8 if [ "$UID" -ne "$ROOT_UID" ]
9 then
10         echo "Sorry, you must be root to run this script."
11         echo
12         exit $E_NOTROOT
13 fi
14
15 check_asterisk() {
16 # check to see if asterisk is running
17 # 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
18 pid_length=`pidof asterisk|awk '{print length($0)}'`
19         if [ "$pid_length" == "0" -a "$pid_length" != "" ]
20                 then
21                                 killall -9 safe_asterisk
22                                 killall -9 mpg123 > /dev/null
23                                 echo
24                                 echo "-----------------------------------------------------"
25                                 echo "Asterisk could not start!"
26                                 echo "Use 'tail $ASTLOGDIR/full' to find out why."
27                                 echo "-----------------------------------------------------"
28                                 exit 0
29                 fi
30 }
31
32 run_asterisk() {
33 # check to see if asterisk is running
34 echo
35 echo "STARTING ASTERISK"
36 pid_length=`pidof asterisk|awk '{print length($0)}'`
37         if [ "$pid_length" != "0" -a "$pid_length" != "" ]
38                 then
39                         echo "Asterisk is already running"
40                 else
41                         # su - asterisk -c "export PATH=$PATH:/usr/sbin && export LD_LIBRARY_PATH=/usr/local/lib && /usr/sbin/safe_asterisk"
42                         export LD_LIBRARY_PATH=/usr/local/lib
43                         /usr/sbin/safe_asterisk -U asterisk -G asterisk
44                         sleep 5
45                         check_asterisk
46                         sleep 1
47                         check_asterisk
48                         echo "Asterisk Started"
49                 fi
50 }
51
52 stop_asterisk() {
53 echo
54 echo "STOPPING ASTERISK"
55 pid_length=`pidof asterisk|awk '{print length($0)}'`
56         if [ "$pid_length" != "0" -a "$pid_length" != "" ]
57                 then
58                         /usr/sbin/asterisk -rx "stop gracefully"
59                         echo "Asterisk Stopped"
60                 fi
61 }
62
63 kill_amp() {
64         echo
65         echo "KILLING AMP PROCESSES"
66         killall -9 safe_asterisk
67         killall -9 asterisk
68         killall -9 mpg123
69         ps -ef | grep safe_opserver | grep -v grep | awk '{print $2}' | xargs kill -9
70         killall -9 op_server.pl
71 }
72
73 case "$1" in
74         start)
75                 run_asterisk
76         ;;
77         stop)
78                 stop_asterisk
79         ;;
80         restart)
81                 stop_asterisk
82                 sleep 1
83                 run_asterisk
84         ;;
85         kill)
86                 kill_amp
87         ;;
88         *)
89                 echo "-------------FreePBX Control Script-----------------------------------------------"
90                 echo
91                 echo "Usage:       amportal start|stop|restart|start_fop|stop_fop|restart_fop|kill|chown"
92                 echo
93                 echo "start:       Starts Asterisk and Flash Operator Panel server if enabled"
94                 echo "stop:        Gracefully stops Asterisk and the FOP server"
95                 echo "restart:     Stop and Starts"
96                 echo "kill:        Kills Asterisk and the FOP server"
97                 echo
98                 exit 1
99         ;;
100 esac
Note: See TracBrowser for help on using the browser.