pythondebiansystemdpyro4

Create a systemd service script for multiple module app


I'm currently writing a python app forking with Pyro4 and flask. In order to start up the app I to need :

  1. Start pyro4 name server
  2. Register my object in the pyro4 name server
  3. Start a flask web app to access pyro4 objects

I would like to do this with a systemd service file. I first though of using ExecStarPre and ExecStarPost for running pyro4 nameserver and flask web app ; but it seems that those fields are not use for long-running commands...

Do I need to make 3 systemd services which I start in a bash script that i call from a 4th systemd service ?

Thx for helping me

I'm trying to write a systemd service file


Solution

  • You don't need four systemd services; three should do.

    You should never, under any circumstances enable or disable a systemd service from an ExecStartPre or an ExecStartPost.

    BTW, one thing that's a little tricky is controlling when systemd considers something to be "up" for purposes of starting the next service in the chain only after that service is done with initialization and ready to use. In a perfect would you build services with Type=notify that use sd_notify("READY=1") to tell systemd when they finished initialization; but if you haven't built that, it's an option to build an ExecStartPost script that waits until the service it's associated with is actually running before it exits.