2
votes

I hope this isnt a duplicate question. Systemd is really hard to search for....

I have a systemd file that looks like

[Unit]
Description=My Daemon

[Service]
User=root
Type=simple
PIDFile=/var/run/app.pid
ExecStart=/usr/bin/python /opt/app/app.pyc
Restart=always

[Install]
WantedBy=multi-user.target

I want ExecStart to run /usr/bin/python /opt/app/app.pyc if it exists and run /usr/bin/python /opt/app/app.py if it doesnt.

The goal that on the deployed system there will not be a py file only a pyc but on dev systems we might only have a py file. How can I get this to work?

1

1 Answers

5
votes

Make a small bash script which does what you want and then put that script on the ExecStart line.

  #!/bin/bash
  if [ -f  /opt/app/app.pyc ];
  then
    exec /opt/app/app.pyc
  else
    exec /opt/app/app.py
  fi