Welcome to MLink Developer Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
511 views
in Technique[技术] by (71.8m points)

raspbian - systemd, python-service can't copy to /etc/

I have a python service that is running via systemd on a raspberry-pi.

I want to use subprocess.call to copy a file from ~ to /etc/wpa_supplicant/

When I start the python process from the comandline I have no problem executing the subprocess.call, unfortunately when started as systemd service its not working.

service file:

[Unit]
Description=some-description

[Service]
TimeoutSec=infinity
Type=simple
Restart=on-failure
RestartSec=15s
WorkingDirectory=/home/%i/
ExecStart=/home/%i/start_script.sh

[Install]
WantedBy=default.target

Python:

subprocess.call(["sudo", "cp", file_path_str, "/etc/wpa_supplicant/wpa_supplicant.conf.temp"])

But that gives following log-output:

pi : TTY=unknown ; PWD=/home/pi/ ; USER=root ; COMMAND=/bin/cp file_path_str /etc/wpa_supplicant/wpa_supplicant.conf.temp

Then I tried running it without sudo in the call(), that just tells me that permission is denied:

cp: cannot create regular file '/etc/wpa_supplicant/wpa_supplicant.conf.save': Permission denied

I thought that services are run as root anyway, why do I have permission problems? Is there a neat way to solve this?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to MLink Developer Q&A Community for programmer and developer-Open, Learning and Share
...