1

I am trying to run python file with arguments from systemd service. So the service file supposed to take argument and pass it to python file in "Execstart".

Here is my systemd file:

[Unit]
Description=test Service On %I
After=multi-user.target
[Service]
WorkingDirectory=/home/user_name/directory
User=user_name
Type=idle

ExecStart=/usr/bin/python3 /home/user_name/directory/test.py %I
Restart=no
[Install]
WantedBy=multi-user.target

test.py:

import sys
print("arguments: "+str(sys.argv))

I tried with following commands:

sudo systemctl start $(systemd-escape --template [email protected] "arg1")

also,

sudo systemctl start [email protected]

I get error: Unit [email protected] not found

7
  • You should locate your systemd service in /etc/systemd/system. Try: sudo cp /path/to/[email protected] /etc/systemd/system Commented Oct 14, 2022 at 15:44
  • Are you update systemd with systemctl daemon-reload?
    – gapsf
    Commented Oct 14, 2022 at 15:46
  • @EdgarMagallon yes, it is /etc/systemd/system
    – sovon
    Commented Oct 14, 2022 at 15:49
  • @gapsf yes, i did
    – sovon
    Commented Oct 14, 2022 at 15:49
  • systemctl enable [email protected] ?
    – gapsf
    Commented Oct 14, 2022 at 16:13

1 Answer 1

1

You need the service file to be named according to the argument you need :

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .