mirror of
https://github.com/freedombox/FreedomBox.git
synced 2026-05-06 10:20:43 +00:00
service: Notify systemd when service starts up
- Run as a Type=notify service with systemd service. - Notify systemd just before blocking in the main thread. - This allows systemd to catch any errors with startup of the service and log appropriately. This also allows clients depending on making DBus calls etc. to know that service is ready to serve requests. - This will increase the boot time slightly as systemd will wait until FreedomBox service to become active. Tests: - Raise an exception in main() during startup. Run 'systemctl start plinth'. No error is thrown without this patch. With the patch, an error is shown. - After 'systemctl start plinth', service shows in 'active' state. Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org> Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
This commit is contained in:
parent
6cc71aa5d7
commit
7c14677277
@ -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]
|
||||
|
||||
@ -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()
|
||||
|
||||
@ -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()
|
||||
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user