OpenMediaVault-Plugin-Developers / openmediavault-autoshutdown

OpenMediaVault plugin to provide frontend for autoshutdown script
37 stars 31 forks source link

Cannot parse IP address from ifconfig #32

Closed yo1frenchtoast closed 7 years ago

yo1frenchtoast commented 7 years ago

Hello,

I noticed that my server did not want to suspend with autoshutdown enabled (was working before), here is the log output on service restart :

Aug 28 09:57:07 openmediavault logger: autoshutdown[15256]: INFO: ' XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX' Aug 28 09:57:07 openmediavault autoshutdown.sh[15256]: logger: autoshutdown[15256]: INFO: ' XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX' Aug 28 09:57:07 openmediavault autoshutdown.sh[15256]: logger: autoshutdown[15256]: INFO: ' XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX' Aug 28 09:57:07 openmediavault logger: autoshutdown[15256]: INFO: ' XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX' Aug 28 09:57:07 openmediavault autoshutdown.sh[15256]: logger: autoshutdown[15256]: INFO: ' XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX' Aug 28 09:57:07 openmediavault logger: autoshutdown[15256]: INFO: ' XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX' Aug 28 09:57:07 openmediavault logger: autoshutdown[15256]: INFO: ' X Version: 0.9.9.10' Aug 28 09:57:07 openmediavault autoshutdown.sh[15256]: logger: autoshutdown[15256]: INFO: ' X Version: 0.9.9.10' Aug 28 09:57:07 openmediavault logger: autoshutdown[15256]: INFO: ' Initialize logging to local6' Aug 28 09:57:07 openmediavault autoshutdown.sh[15256]: logger: autoshutdown[15256]: INFO: ' Initialize logging to local6' Aug 28 09:57:07 openmediavault logger: autoshutdown[15256]: INFO: ' /etc/autoshutdown.conf loaded' Aug 28 09:57:07 openmediavault logger: autoshutdown[15256]: INFO: ' ------------------------------------------------------' Aug 28 09:57:07 openmediavault logger: autoshutdown[15256]: INFO: ' Checking config' Aug 28 09:57:07 openmediavault logger: autoshutdown[15256]: INFO: ' LOADPROCNAMES is set to: 'smbd,nfsd,transmission-daemon,mt-daapd,forked-daapd' (default)' Aug 28 09:57:07 openmediavault logger: autoshutdown[15256]: INFO: ' TEMPPROCNAMES is set to: in.'tftpd' (default)' Aug 28 09:57:07 openmediavault logger: autoshutdown[15256]: INFO: ' If you want more processes monitored, please have a look at the expert-settings' Aug 28 09:57:07 openmediavault logger: autoshutdown[15256]: INFO: ' PINGLIST is set in the conf, reading IPs from '/root/lib/PINGLIST'' Aug 28 09:57:07 openmediavault logger: autoshutdown[15256]: INFO: ' SHUTDOWNCOMMAND is set to 'pm-suspend'' Aug 28 09:57:07 openmediavault logger: autoshutdown[15256]: INFO: ' Your Kernel supports the following modes from pm-utils:' Aug 28 09:57:07 openmediavault logger: autoshutdown[15256]: INFO: ' Kernel supports SUSPEND (SUSPEND to RAM)' Aug 28 09:57:07 openmediavault logger: autoshutdown[15256]: INFO: ' Kernel supports HIBERNATE (SUSPEND to DISK)' Aug 28 09:57:07 openmediavault logger: autoshutdown[15256]: INFO: ' Kernel supports HYBRID-SUSPEND (to DISK & to RAM)' Aug 28 09:57:07 openmediavault logger: autoshutdown[15256]: INFO: ' ------------------------------------------------------' Aug 28 09:57:07 openmediavault logger: autoshutdown[15256]: INFO: ' Reading NICs ,IPs, ...' Aug 28 09:57:07 openmediavault logger: autoshutdown[15256]: INFO: ' FORCE_NIC found: NIC is now eth2' Aug 28 09:57:07 openmediavault logger: autoshutdown[15256]: INFO: ' If the following checks fail, then try to uncomment FORCE_NIC to do a normal network-check' Aug 28 09:57:07 openmediavault logger: autoshutdown[15256]: INFO: ' NIC 'eth2' found: try to get IP' Aug 28 09:57:07 openmediavault logger: autoshutdown[15256]: INFO: ' _check_networkconfig(): Run: #1: IP-Adress found' Aug 28 09:57:07 openmediavault logger: autoshutdown[15256]: INFO: ' 'eth2' has IP: inet 192.168.10.5 netmask 255.255.255.0 broadcast 192.168.10.255' Aug 28 09:57:07 openmediavault logger: autoshutdown[15256]: WARN: ' Invalid parameter format: Class: nnn.nnn.nnn]' Aug 28 09:57:07 openmediavault logger: autoshutdown[15256]: WARN: ' It is set to 'inet 192.168.10.5 netmask 255.255.255.0 broadcast 192.168.10', which is not a correct syntax. Maybe parsing 'ifconfig ' did something wrong' Aug 28 09:57:07 openmediavault logger: autoshutdown[15256]: WARN: ' Please report this Bug and the CLI-output of 'ifconfig'' Aug 28 09:57:07 openmediavault logger: autoshutdown[15256]: WARN: ' unsetting NIC[1]: eth2 ...' Aug 28 09:57:07 openmediavault logger: autoshutdown[15256]: WARN: ' Invalid parameter format: SERVERIP [iii]' Aug 28 09:57:07 openmediavault logger: autoshutdown[15256]: WARN: ' It is set to '255', which is not a correct syntax. Maybe parsing 'ifconfig' did something wrong' Aug 28 09:57:07 openmediavault logger: autoshutdown[15256]: WARN: ' Please report this Bug and the CLI-output of 'ifconfig'' Aug 28 09:57:07 openmediavault logger: autoshutdown[15256]: WARN: ' unsetting NIC[1]: ...' Aug 28 09:57:07 openmediavault logger: autoshutdown[15256]: INFO: '---------------- script started ----------------------' Aug 28 09:57:07 openmediavault logger: autoshutdown[15256]: INFO: ' 6 test cycles until shutdown is issued.' Aug 28 09:57:07 openmediavault logger: autoshutdown[15256]: INFO: ' Waiting 5 min until the first check'

yo1frenchtoast commented 7 years ago

Found that the output of ifconfig doesn't match the regex in _check_networkconfig function

root@openmediavault:~# ifconfig eth2 eth2: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500 inet 192.168.10.5 netmask 255.255.255.0 broadcast 192.168.10.255 ether 20:cf:30:1c:c8:cc txqueuelen 1000 (Ethernet) RX packets 44312279 bytes 36885282010 (34.3 GiB) RX errors 0 dropped 494 overruns 0 frame 0 TX packets 51503648 bytes 55086391015 (51.3 GiB) TX errors 0 dropped 9 overruns 0 carrier 0 collisions 0

it must be like inet adr:192.168.20.252 Bcast:192.168.20.255 Masque:255.255.255.0 to match

yo1frenchtoast commented 7 years ago

Changed regex to IPFROMIFCONFIG[$NICNR]="$(ifconfig ${NIC[$NICNR]} | egrep "inet " | sed -r 's/[ ]*(Bcast|netmask).*//g; s/[ ]*inet[ ](adr:)?//g')" works like a charm