Skip to content

Commit baf1693

Browse files
committed
restart: Avoid unnecessary full Asterisk restart by default.
Asterisk does not need to be stopped in order to restart DAHDI; only chan_dahdi needs to be unloaded, so take the more lightweight approach by default, unless --force is specified.
1 parent 7012507 commit baf1693

File tree

1 file changed

+28
-11
lines changed

1 file changed

+28
-11
lines changed

phreaknet.sh

Lines changed: 28 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -554,15 +554,23 @@ stop_wanpipe() {
554554

555555
# Completely restart wanpipe, DAHDI (and any DAHDI drivers), and Asterisk
556556
# This is surprisingly complicated, and can be dangerous if done incorrectly
557+
# $1 to restart without completely restarting Asterisk
557558
restart_telephony() {
558-
service asterisk stop # stop Asterisk
559-
astpid=$( ps -aux | grep "asterisk" | grep -v "grep" | head -n 1 | xargs | cut -d' ' -f2 )
560-
if [ "$astpid" != "" ]; then
561-
# if that didn't work, kill it manually
562-
kill -9 $astpid
563-
printf "Killed Asterisk process %s\n" "$astpid"
559+
if [ "$1" = "1" ]; then
560+
rasterisk -x "module unload chan_dahdi" | grep "Unloaded chan_dahdi"
561+
if [ $? -ne 0 ]; then
562+
die "chan_dahdi could not be unloaded"
563+
fi
564564
else
565-
printf "Asterisk not currently running...\n"
565+
service asterisk stop # stop Asterisk
566+
astpid=$( ps -aux | grep "asterisk" | grep -v "grep" | head -n 1 | xargs | cut -d' ' -f2 )
567+
if [ "$astpid" != "" ]; then
568+
# if that didn't work, kill it manually
569+
kill -9 $astpid
570+
printf "Killed Asterisk process %s\n" "$astpid"
571+
else
572+
printf "Asterisk not currently running...\n"
573+
fi
566574
fi
567575
lsmod | grep dahdi
568576
curdrivers=`lsmod | grep "dahdi " | xargs | cut -d' ' -f4-`
@@ -624,9 +632,13 @@ restart_telephony() {
624632
fi
625633
fi
626634
printf "DAHDI is now running normally...\n"
627-
service asterisk start
628-
astpid=$( ps -aux | grep "asterisk" | grep -v "grep" | head -n 1 | xargs | cut -d' ' -f2 )
629-
printf "Asterisk now running on pid %s\n" "$astpid"
635+
if [ "$1" = "1" ]; then
636+
rasterisk -x "module load chan_dahdi"
637+
else
638+
service asterisk start
639+
astpid=$( ps -aux | grep "asterisk" | grep -v "grep" | head -n 1 | xargs | cut -d' ' -f2 )
640+
printf "Asterisk now running on pid %s\n" "$astpid"
641+
fi
630642
}
631643

632644
# Mainly intended to start the telephony drivers on bootup, since this doesn't always happen automatically
@@ -3624,7 +3636,12 @@ elif [ "$cmd" = "forcerestart" ]; then
36243636
echog "Successfully started Asterisk again."
36253637
fi
36263638
elif [ "$cmd" = "restart" ]; then
3627-
restart_telephony
3639+
# not really forcing install of anything, but to use the --force flag
3640+
if [ "$FORCE_INSTALL" = "1" ]; then
3641+
restart_telephony 0
3642+
else
3643+
restart_telephony 1
3644+
fi
36283645
elif [ "$cmd" = "start" ]; then
36293646
start_telephony
36303647
elif [ "$cmd" = "edit" ]; then

0 commit comments

Comments
 (0)