I have script in python that need to be run with "sudo" keyword. Everything because I'm accessing "/dev/mem". Now I need to start this python script on RPi startup. So I create simple service that launch this script it looks like :
[Unit] Description=sendService After=network.target [Service] ExecStart=/usr/bin/python3 -u send.py WorkingDirectory=/home/pi/pywork User=root [Install] WantedBy=multi-user.target
it is inside /etc/systemd/system directory. I observe that this script is trying to work properly but it gives me error about my python script (that access to /dev/mem is denied). Same problem I have when I use to run this script using "python3 send.py" commend but when I use "sudo python3 send.py" it works like charm. Does it means that this service run mine program without sudo privileges even if user is set to root ?
systemctl status gives
● serviceSend.service - sendService Loaded: loaded (/etc/systemd/system/serviceSend.service; enabled; vendor preset: enabled) Active: inactive (dead) since Fri 2018-08-10 10:36:43 UTC; 3min 35s ago Process: 1306 ExecStart=/usr/bin/python3 -u send.py (code=exited, status=0/SUCCESS) Main PID: 1306 (code=exited, status=0/SUCCESS) Aug 10 10:36:42 raspberrypi systemd: Started sendService. Aug 10 10:36:43 raspberrypi sudo: root : TTY=unknown ; PWD=/home/pi/pywork ; USER=root ; COMMAND=/bin/systemctl stop serial-getty@ttyAMA0.service Aug 10 10:36:43 raspberrypi sudo: pam_unix(sudo:session): session opened for user root by (uid=0) Aug 10 10:36:43 raspberrypi sudo: pam_unix(sudo:session): session closed for user root