You are not logged in.
Goal: write a systemd service to run the ExecStart= line as an unprivileged user BUT have ExecStopPost= and ExecStartPre= lines run as root.
Is this possible? For example, the following will start the program as the unprivileged user:
[Unit]
Description=my service
After=remote-fs.target
[Service]
User=myuser
Group=mygroup
ExecStart=/usr/bin/myscript
Restart=on-failure
[Install]
WantedBy=multi-user.targetBut what I really want is to have root run a 2nd program both before and after (ExecStartPre and ExecStartPost or an equivalent). I can achieve the goal by omitting the User= and Group= lines from the service and by modifying /usr/bin/myscript to run certain lines within as myuser:mygroup but, I'd like to do it with entirely with systemd if possible. I would be OK with a solution involving multiple .service units but am unsure how to make them conditional on this one.
Thoughts are appreciated.
Last edited by graysky (2018-10-08 20:11:06)
Offline
Another option may be using sudo and some NOPASSWD entries in sudoers, but that dosn't fulfil the systemd only criteria either.
That's the best I've got ![]()
Offline
Have you read the Special executable prefixes table in man 5 systemd.service?
Offline
Have you read the Special executable prefixes table in man 5 systemd.service?
Great pointer! Thank you, this fits the bill.
Offline
If that weren't the case, you could still implement privilege dropping by using
/usr/bin/runuser -u username command argssystemd's User and Group keywords make this easier and reduce boilerplate, but it isn't impossible to do without.
Managing AUR repos The Right Way -- aurpublish (now a standalone tool)
Offline