0

I have a python script that displays the current IP address and time to a LCD screen attached to my device (Rock64 SBC).

The python script runs fine on it’s own.

from subprocess import check_output
from time import sleep
from datetime import datetime
from RPLCD.i2c import CharLCD
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()
while True:
    lcd_line_1 = datetime.now().strftime('%b %d  %H:%M:%S')
    lcd_line_2 = "IP " + get_ip()

    lcd.home()
    lcd.write_string(f'{lcd_line_1}rn{lcd_line_2}')
    sleep(10)

Then the service code for lcd.service is this:

[Unit]
Description=LCD IP Display
After=multi-user.target

[Service]
Type=simple
ExecStart=/bin/sh -c "python3 /home/rock64/pi/lcd_ip.py"
WorkingDirectory=/home/rock64/pi
Restart=always
User=rock64

[Install]
WantedBy=multi-user.target

systemctl status lcd.service displays:

● lcd.service - LCD IP Display
   Loaded: loaded (/etc/systemd/system/lcd.service; disabled; vendor preset: enabled)
   Active: failed (Result: exit-code) since Mon 2021-08-16 10:07:11 CDT; 18min ago
 Main PID: 2181 (code=exited, status=1/FAILURE)

Aug 16 10:07:11 rock64 systemd[1]: lcd.service: Service hold-off time over, scheduling restart.
Aug 16 10:07:11 rock64 systemd[1]: lcd.service: Scheduled restart job, restart counter is at 10.
Aug 16 10:07:11 rock64 systemd[1]: Stopped LCD IP Display.
Aug 16 10:07:11 rock64 systemd[1]: lcd.service: Start request repeated too quickly.
Aug 16 10:07:11 rock64 systemd[1]: lcd.service: Failed with result 'exit-code'.
Aug 16 10:07:11 rock64 systemd[1]: Failed to start LCD IP Display.

How can I troubleshoot this?