Skip to content

Commit

Permalink
restart: Avoid unnecessary full Asterisk restart by default.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
InterLinked1 committed Mar 31, 2024
1 parent 7012507 commit baf1693
Showing 1 changed file with 28 additions and 11 deletions.
39 changes: 28 additions & 11 deletions phreaknet.sh
Original file line number Diff line number Diff line change
Expand Up @@ -554,15 +554,23 @@ stop_wanpipe() {

# Completely restart wanpipe, DAHDI (and any DAHDI drivers), and Asterisk
# This is surprisingly complicated, and can be dangerous if done incorrectly
# $1 to restart without completely restarting Asterisk
restart_telephony() {
service asterisk stop # stop Asterisk
astpid=$( ps -aux | grep "asterisk" | grep -v "grep" | head -n 1 | xargs | cut -d' ' -f2 )
if [ "$astpid" != "" ]; then
# if that didn't work, kill it manually
kill -9 $astpid
printf "Killed Asterisk process %s\n" "$astpid"
if [ "$1" = "1" ]; then
rasterisk -x "module unload chan_dahdi" | grep "Unloaded chan_dahdi"
if [ $? -ne 0 ]; then
die "chan_dahdi could not be unloaded"
fi
else
printf "Asterisk not currently running...\n"
service asterisk stop # stop Asterisk
astpid=$( ps -aux | grep "asterisk" | grep -v "grep" | head -n 1 | xargs | cut -d' ' -f2 )
if [ "$astpid" != "" ]; then
# if that didn't work, kill it manually
kill -9 $astpid
printf "Killed Asterisk process %s\n" "$astpid"
else
printf "Asterisk not currently running...\n"
fi
fi
lsmod | grep dahdi
curdrivers=`lsmod | grep "dahdi " | xargs | cut -d' ' -f4-`
Expand Down Expand Up @@ -624,9 +632,13 @@ restart_telephony() {
fi
fi
printf "DAHDI is now running normally...\n"
service asterisk start
astpid=$( ps -aux | grep "asterisk" | grep -v "grep" | head -n 1 | xargs | cut -d' ' -f2 )
printf "Asterisk now running on pid %s\n" "$astpid"
if [ "$1" = "1" ]; then
rasterisk -x "module load chan_dahdi"
else
service asterisk start
astpid=$( ps -aux | grep "asterisk" | grep -v "grep" | head -n 1 | xargs | cut -d' ' -f2 )
printf "Asterisk now running on pid %s\n" "$astpid"
fi
}

# Mainly intended to start the telephony drivers on bootup, since this doesn't always happen automatically
Expand Down Expand Up @@ -3624,7 +3636,12 @@ elif [ "$cmd" = "forcerestart" ]; then
echog "Successfully started Asterisk again."
fi
elif [ "$cmd" = "restart" ]; then
restart_telephony
# not really forcing install of anything, but to use the --force flag
if [ "$FORCE_INSTALL" = "1" ]; then
restart_telephony 0
else
restart_telephony 1
fi
elif [ "$cmd" = "start" ]; then
start_telephony
elif [ "$cmd" = "edit" ]; then
Expand Down

0 comments on commit baf1693

Please sign in to comment.