I'm currently writing a python app forking with Pyro4 and flask. In order to start up the app I to need :
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
You don't need four systemd services; three should do.
pyro-nameserver.service
: The Pyro nameservermysvc-objects.service
: The server for your custom Pyro objects. Use Requires=pyro-nameserver.service
and After=pyro-nameserver.service
mysvc.service
: The actual Flask webapp. Uses Requires=mysvc-objects.service
and After=mysvc-objects.service
to ensure that it only tries to start when the nameserver is already up and your objects are registered.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.