Rock64 SBC에서 서비스를 실행할 수 없습니다.

Rock64 SBC에서 서비스를 실행할 수 없습니다.

내 장치(Rock64 SBC)에 연결된 LCD 화면에 현재 IP 주소와 시간을 표시하는 Python 스크립트가 있습니다.

Python 스크립트 자체는 잘 작동합니다.

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)

그러면 lcd.service의 서비스 코드는 다음과 같습니다:

[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 상태 LCD.service보여주다:

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[1]: lcd.service: Service hold-off time over, scheduling restart.
Aug 19 15:10:11 rock64 systemd[1]: lcd.service: Scheduled restart job, restart counter is at 15.
Aug 19 15:10:11 rock64 systemd[1]: Stopped LCD IP Display.
Aug 19 15:10:11 rock64 systemd[1]: lcd.service: Start request repeated too quickly.
Aug 19 15:10:11 rock64 systemd[1]: lcd.service: Failed with result 'exit-code'.
Aug 19 15:10:11 rock64 systemd[1]: 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[5029]: Traceback (most recent call last):
Aug 19 15:10:10 rock64 sh[5029]:   File "/home/rock64/pi/lcd_ip.py", line 5, in <module>
Aug 19 15:10:10 rock64 sh[5029]:     lcd = CharLCD('PCF8574', 0x27, auto_linebreaks=False)
Aug 19 15:10:10 rock64 sh[5029]:   File "/home/rock64/.local/lib/python3.6/site-packages/RPLCD/i2c.py", line 168, in __i
Aug 19 15:10:10 rock64 sh[5029]:     auto_linebreaks=auto_linebreaks)
Aug 19 15:10:10 rock64 sh[5029]:   File "/home/rock64/.local/lib/python3.6/site-packages/RPLCD/lcd.py", line 98, in __in
Aug 19 15:10:10 rock64 sh[5029]:     self._init_connection()
Aug 19 15:10:10 rock64 sh[5029]:   File "/home/rock64/.local/lib/python3.6/site-packages/RPLCD/i2c.py", line 173, in _in
Aug 19 15:10:10 rock64 sh[5029]:     self.bus = SMBus(self._port)
Aug 19 15:10:10 rock64 sh[5029]: PermissionError: [Errno 13] Permission denied

나는 chmod +x 기본 Python 파일과 i2c.py 및 lcd.py 파일을 가지고 있습니다.

ls -ls 표시

rock64@rock64:~/pi$ ls -la lcd_ip.py
-rwxr-xr-x 1 rock64 sudo 500 Aug 13 17:08 lcd_ip.py

마지막으로 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

여전히 "오류 13 권한 거부"가 표시됩니다.

어떤 제안이 있으십니까?

답변1

저는 두 가지 작업을 수행해야 했습니다. 서비스 파일에서 ExecStart를 다음으로 변경했습니다.

ExecStart=/usr/bin/python3 /home/rock64/pi/lcd_ip.py

그런 다음 나는 sudo visudo추가하기 위해 달려갔습니다.

rock64 ALL=(ALL) NOPASSWD: ALL

관련 정보