Skip to content

Commit 80c2407

Browse files
committed
phreaknet.sh: Improve reliability of restart command.
* Make 'restart' command work more robustly regardless of current system state (in particular, whether Asterisk is running). * Avoid unnecessary update attempts in an offline environment.
1 parent 733854a commit 80c2407

File tree

2 files changed

+39
-6
lines changed

2 files changed

+39
-6
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
PhreakScript installs:
66

7-
- Asterisk 22.6.0 (latest LTS release[1] of Asterisk)
7+
- Asterisk 22.7.0 (latest LTS release[1] of Asterisk)
88
- DAHDI Linux 3.4.0 (with optional DAHDI install flag)
99
- DAHDI Tools 3.4.0 (with optional DAHDI install flag)
1010
- wanpipe 7.0.38 (with optional wanpipe install flag)

phreaknet.sh

Lines changed: 38 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -730,7 +730,7 @@ get_ast_pid() {
730730
else
731731
astpid=$( ps -aux | grep "asterisk" | grep -v "grep" | head -n 1 | xargs | cut -d' ' -f2 )
732732
fi
733-
return $astpid
733+
echo $astpid
734734
}
735735

736736
stop_telephony() {
@@ -892,9 +892,33 @@ start_telephony() {
892892
# Finally, make sure the DAHDI service is running so that systemd can keep track of it...
893893
service dahdi start
894894

895-
service asterisk start # Start Asterisk if it's not running already
896-
/usr/sbin/rasterisk -x "module load chan_dahdi" # Load chan_dahdi if Asterisk was already running
897-
/usr/sbin/rasterisk -x "dahdi show channels" # The ultimate test is what DAHDI channels actually show up in Asterisk
895+
# Load chan_dahdi if Asterisk was already running
896+
/usr/sbin/rasterisk -x "module load chan_dahdi"
897+
if [ $? -ne 0 ]; then
898+
# Start Asterisk if it's not running already
899+
service asterisk start
900+
if [ ! -f /var/run/asterisk/asterisk.ctl ]; then
901+
printf "Asterisk service file is ineffectual, starting Asterisk manually...\n"
902+
/usr/sbin/asterisk -g # The service didn't do squat, actually start Asterisk
903+
if [ $? -ne 0 ]; then
904+
die "Asterisk failed to start"
905+
fi
906+
printf "Waiting for Asterisk to start...\n"
907+
sleep 3 # Wait for Asterisk to fully boot
908+
# Wait some more if needed...
909+
if [ ! -f /var/run/asterisk/asterisk.ctl ]; then
910+
sleep 3
911+
fi
912+
if [ ! -f /var/run/asterisk/asterisk.ctl ]; then
913+
sleep 3
914+
fi
915+
fi
916+
/usr/sbin/rasterisk -x "module load chan_dahdi"
917+
fi
918+
919+
# The ultimate test is what DAHDI channels actually show up in Asterisk
920+
/usr/sbin/rasterisk -x "dahdi show channels" || die "Telephony initialization failed (Asterisk not started)"
921+
898922
echog "Telephony initialization completed"
899923
}
900924

@@ -3382,7 +3406,16 @@ if which curl > /dev/null && [ "$OFFLINE_INSTALL" != "1" ]; then # only execute
33823406
if [ -f /tmp/phreaknet_upstream_version.txt ]; then
33833407
recent=$( find /tmp/phreaknet_upstream_version.txt -mmin -720 2>/dev/null | wc -l )
33843408
else
3385-
recent=0
3409+
recent=$( find /tmp/phreaknet_no_update_check.txt -mmin -720 2>/dev/null | wc -l )
3410+
if [ "$recent" = "0" ]; then
3411+
# Check if we have Internet connectivity. If not (or if it's not a fast connection), don't bother trying to update right now.
3412+
ping -c 1 -W 3 1.1.1.1 > /dev/null
3413+
if [ $? -ne 0 ]; then
3414+
printf " *** Skipping update check (no Internet connectivity detected)\n"
3415+
echo "1" > /tmp/phreaknet_no_update_check.txt
3416+
recent=1
3417+
fi
3418+
fi
33863419
fi
33873420
if [ "$recent" != "1" ]; then
33883421
printf " *** Checking if a higher numbered version is available..."

0 commit comments

Comments
 (0)