FranklinYu / snippets

my Gist
MIT License
0 stars 0 forks source link

run a command in the context of a specific systemd service unit #26

Open FranklinYu opened 1 year ago

FranklinYu commented 1 year ago

When authoring a systemd service file, it is common to specify the Environment and WorkingDirectory, both specified in systemd.exec(5). To help debugging, I want to run a command (frequently a shell) with the environment variables set, and at the specified working directory. The systemd-run --shell looks promising, except that it only creates an empty environment. That said, it does have --working-directory and --setenv, so the values could be extracted via systemctl show, and put into systemd-run. It should be possible to write a script to automate this.