diff --git a/data/usr/lib/systemd/system/plinth.service b/data/usr/lib/systemd/system/plinth.service index 15a9fd4ed..d84e62b13 100644 --- a/data/usr/lib/systemd/system/plinth.service +++ b/data/usr/lib/systemd/system/plinth.service @@ -7,6 +7,7 @@ After=network.target StartLimitIntervalSec=0 [Service] +Type=notify ExecStart=/usr/bin/plinth Restart=on-failure RestartSec=5 @@ -15,6 +16,7 @@ User=plinth Group=plinth StandardOutput=null StandardError=null +NotifyAccess=main PrivateTmp=yes [Install] diff --git a/plinth/__main__.py b/plinth/__main__.py index fba9fea58..09d062ff2 100644 --- a/plinth/__main__.py +++ b/plinth/__main__.py @@ -6,6 +6,8 @@ import logging import sys import threading +import systemd.daemon + from . import __version__ from . import app as app_module from . import (cfg, frontpage, glib, log, menu, module_loader, setup, @@ -158,6 +160,12 @@ def main(): web_server.init() web_server.run(on_web_server_stop) + # systemd will wait until notification to proceed with other processes. We + # have service Type=notify. + systemd.daemon.notify('READY=1') + + web_server.block() + if __name__ == '__main__': main() diff --git a/plinth/web_server.py b/plinth/web_server.py index 9020c8be4..09eb78bc8 100644 --- a/plinth/web_server.py +++ b/plinth/web_server.py @@ -122,6 +122,10 @@ def run(on_web_server_stop): cherrypy.engine.start() cherrypy.engine.subscribe('stop', on_web_server_stop) + + +def block(): + """Block the calling thread until web server exits.""" cherrypy.engine.block()