What can cause a Linux service fail to start at boot, but can be manually started? The project I'm working on involves showing the ip address of each Raspberry Pi/other SBC board so they can be ssh'ed into.
Files....
lcd.service:
[Unit]
Description=LCD ip
Requires=network-online.target
After=network-online.target
[Service]
Type=simple
ExecStart=/usr/bin/python3 /home/kmin/lcd/ip_lcd.py
WorkingDirectory=/opt/ProcLIInfo
StandardOutput=/var/log1Out.log
StandardError=/var/log2Err.log
Restart=always
User=LIInfoUsr
[Install]
WantedBy=network-online.target
ip_lcd.py:
from subprocess import check_output
from time import sleep
from datetime import datetime
from RPLCD.i2c import CharLCD
import miniupnpc
print("Starting lcd update")
sleep(10)
lcd = CharLCD('PCF8574', 0x27, auto_linebreaks=False)
lcd.clear()
def get_ip():
cmd = "hostname -I | cut -d\' \' -f1"
return check_output(cmd, shell=True).decode("utf-8").strip()
def get_ext_ip():
u = miniupnpc.UPnP()
u.discoverdelay = 200
u.discover()
u.selectigd()
return u.externalipaddress()
while True:
lcd_line_1 = get_ext_ip()
lcd_line_2 = get_ip()
lcd.home()
lcd.write_string(f'{lcd_line_1}\r\n{lcd_line_2}')
sleep(10)
print("Ended lcd update")
User / Group details...
kmin@raspberrypi:~ $ id LIInfoUsr uid=999(LIInfoUsr) gid=995(LIInfoGrp) groups=995(LIInfoGrp),46(plugdev),100(users),104(input),108(netdev),999(spi),998(i2c),997(gpio)
kmin@raspberrypi:~ $ id uid=1000(kmin) gid=1000(kmin) groups=1000(kmin),4(adm),20(dialout),24(cdrom),27(sudo),29(audio),44(video),46(plugdev),60(games),100(users),104(input),106(render),108(netdev),117(lpadmin),997(gpio),998(i2c),999(spi)
Observed issues...
- Logs aren't written despite making /var permissive (777)
- systemctl status shows inactive dead when checking status once desktop loads
- Routine is an infinite while loop which shouldn't cause the service to end prematurely
- systemctl status shows it properly running when manually started (and the 2x16 lcd works)