Sample Header Ad - 728x90

can't get service to run on Rock64 SBC

0 votes
1 answer
71 views
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}\r\n{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: rock64@rock64:/etc/systemd/system$ systemctl status lcd.service ● lcd.service - LCD IP Display Loaded: loaded (/etc/systemd/system/lcd.service; enabled; vendor preset: enabled) Active: failed (Result: exit-code) since Thu 2021-08-19 15:10:11 CDT; 11s ago Process: 5029 ExecStart=/bin/sh -c python3 /home/rock64/pi/lcd_ip.py (code=exited, status=1/FAILURE) Main PID: 5029 (code=exited, status=1/FAILURE) Aug 19 15:10:11 rock64 systemd: lcd.service: Service hold-off time over, scheduling restart. Aug 19 15:10:11 rock64 systemd: lcd.service: Scheduled restart job, restart counter is at 15. Aug 19 15:10:11 rock64 systemd: Stopped LCD IP Display. Aug 19 15:10:11 rock64 systemd: lcd.service: Start request repeated too quickly. Aug 19 15:10:11 rock64 systemd: lcd.service: Failed with result 'exit-code'. Aug 19 15:10:11 rock64 systemd: Failed to start LCD IP Display. rock64@rock64:/etc/systemd/system$ journalctl _PID=5029 -- Logs begin at Sun 2018-01-28 09:58:18 CST, end at Thu 2021-10-14 12:18:00 CDT. -- Aug 19 15:10:10 rock64 sh: Traceback (most recent call last): Aug 19 15:10:10 rock64 sh: File "/home/rock64/pi/lcd_ip.py", line 5, in Aug 19 15:10:10 rock64 sh: lcd = CharLCD('PCF8574', 0x27, auto_linebreaks=False) Aug 19 15:10:10 rock64 sh: File "/home/rock64/.local/lib/python3.6/site-packages/RPLCD/i2c.py", line 168, in __i Aug 19 15:10:10 rock64 sh: auto_linebreaks=auto_linebreaks) Aug 19 15:10:10 rock64 sh: File "/home/rock64/.local/lib/python3.6/site-packages/RPLCD/lcd.py", line 98, in __in Aug 19 15:10:10 rock64 sh: self._init_connection() Aug 19 15:10:10 rock64 sh: File "/home/rock64/.local/lib/python3.6/site-packages/RPLCD/i2c.py", line 173, in _in Aug 19 15:10:10 rock64 sh: self.bus = SMBus(self._port) Aug 19 15:10:10 rock64 sh: PermissionError: [Errno 13] Permission denied I have chmod +x the main python file and the files i2c.py and lcd.py. ls -ls shows rock64@rock64:~/pi$ ls -la lcd_ip.py -rwxr-xr-x 1 rock64 sudo 500 Aug 13 17:08 lcd_ip.py lastly, I have added the following lines to visudo rock64 ALL=(ALL) NOPASSWD: /etc/systemd/system/lcd.service rock64 ALL=(ALL) NOPASSWD: /home/rock64/pi/lcd_ip.py rock64 ALL=(ALL) NOPASSWD: /home/rock64/.local/lib/python3.6/site-packages/RPLCD/ic2.py rock64 ALL=(ALL) NOPASSWD: /home/rock64/.local/lib/python3.6/site-packages/RPLCD/lcd.py and I still get "error 13 permission denied". Any suggestions?
Asked by Shawn (117 rep)
Aug 16, 2021, 03:28 PM
Last activity: Aug 20, 2021, 04:12 PM