Skip to content

Commit

Permalink
restart hostapd instead of reboot; do it whenever risk of rfkill bloc…
Browse files Browse the repository at this point in the history
…kage
  • Loading branch information
tim-moody committed Jun 16, 2024
1 parent f57c1e2 commit 87fc7af
Showing 1 changed file with 35 additions and 2 deletions.
37 changes: 35 additions & 2 deletions roles/cmdsrv/files/iiab-cmdsrv3.py
Original file line number Diff line number Diff line change
Expand Up @@ -1514,6 +1514,7 @@ def set_nmcli_connection(cmd, connect_wifi_ssid, connect_wifi_password):
rc = adm.subproc_run('nmcli con up ' + con_name)
if rc.returncode == 0:
resp = cmd_success(cmd)
return resp
elif rc.returncode == 4:
resp = cmd_error(cmd=cmd, msg='Unable to Connect. Check credentials.')
elif rc.returncode == 10:
Expand All @@ -1522,7 +1523,10 @@ def set_nmcli_connection(cmd, connect_wifi_ssid, connect_wifi_password):
resp = cmd_error(cmd=cmd, msg='Unable to Connect.')
except:
resp = cmd_error(cmd=cmd, msg='Error Connecting to Router.')
return resp
if restart_hotspot():
return cmd_success(cmd)
else:
return cmd_error(cmd=cmd, msg='Error Restarting Hotspot.')

def set_wpa_credentials (cmd, connect_wifi_ssid, connect_wifi_password):

Expand Down Expand Up @@ -1639,7 +1643,32 @@ def remove_wifi_connection_params_nm(cmd_info):
except:
return cmd_error(cmd=cmd, msg='Error Removing Router Connections.')

return reboot_server(cmd_info)
#return reboot_server(cmd_info)
if restart_hotspot():
return cmd_success(cmd_info['cmd'])
else:
return cmd_error(cmd=cmd, msg='Error Restarting Hotspot.')

def restart_hotspot():
log(syslog.LOG_ERR, "Restarting hostapd")
blocked_text = 'rfkill: WLAN soft blocked'

if not effective_vars['hostapd_enabled']:
log(syslog.LOG_ERR, "hostapd is not enabled")
return False

# rc = adm.subproc_run('systemctl status hostapd')

try:
rc = adm.subproc_run('systemctl restart hostapd')
if rc.returncode:
log(syslog.LOG_ERR, "Failed to restart hostapd")
return False
else:
return True
except:
log(syslog.LOG_ERR, "Failed to restart hostapd")
return False

def ctl_bluetooth(cmd_info):
if not is_rpi:
Expand Down Expand Up @@ -3557,6 +3586,10 @@ def init():
# Compute variables derived from all of the above
compute_vars()

# restart hostapd in case blocked by rfkill
if effective_vars['hostapd_enabled']:
restart_hotspot()

#get_ansible_tags()
read_kiwix_catalog()
read_oer2go_catalog()
Expand Down

0 comments on commit 87fc7af

Please sign in to comment.