mirror of
https://git.anonymousland.org/anonymousland/synapse-product.git
synced 2024-10-01 08:25:44 -04:00
Merge pull request #5732 from matrix-org/erikj/sdnotify
Add process hooks to tell systemd our state.
This commit is contained in:
commit
841b12867e
1
changelog.d/5732.feature
Normal file
1
changelog.d/5732.feature
Normal file
@ -0,0 +1 @@
|
|||||||
|
Add sd_notify hooks to ease systemd integration and allows usage of Type=Notify.
|
@ -4,7 +4,8 @@ After=matrix-synapse.service
|
|||||||
BindsTo=matrix-synapse.service
|
BindsTo=matrix-synapse.service
|
||||||
|
|
||||||
[Service]
|
[Service]
|
||||||
Type=simple
|
Type=notify
|
||||||
|
NotifyAccess=main
|
||||||
User=matrix-synapse
|
User=matrix-synapse
|
||||||
WorkingDirectory=/var/lib/matrix-synapse
|
WorkingDirectory=/var/lib/matrix-synapse
|
||||||
EnvironmentFile=/etc/default/matrix-synapse
|
EnvironmentFile=/etc/default/matrix-synapse
|
||||||
|
@ -2,7 +2,8 @@
|
|||||||
Description=Synapse Matrix Homeserver
|
Description=Synapse Matrix Homeserver
|
||||||
|
|
||||||
[Service]
|
[Service]
|
||||||
Type=simple
|
Type=notify
|
||||||
|
NotifyAccess=main
|
||||||
User=matrix-synapse
|
User=matrix-synapse
|
||||||
WorkingDirectory=/var/lib/matrix-synapse
|
WorkingDirectory=/var/lib/matrix-synapse
|
||||||
EnvironmentFile=/etc/default/matrix-synapse
|
EnvironmentFile=/etc/default/matrix-synapse
|
||||||
|
@ -14,7 +14,9 @@
|
|||||||
Description=Synapse Matrix homeserver
|
Description=Synapse Matrix homeserver
|
||||||
|
|
||||||
[Service]
|
[Service]
|
||||||
Type=simple
|
Type=notify
|
||||||
|
NotifyAccess=main
|
||||||
|
ExecReload=/bin/kill -HUP $MAINPID
|
||||||
Restart=on-abort
|
Restart=on-abort
|
||||||
|
|
||||||
User=synapse
|
User=synapse
|
||||||
|
@ -15,10 +15,12 @@
|
|||||||
|
|
||||||
import gc
|
import gc
|
||||||
import logging
|
import logging
|
||||||
|
import os
|
||||||
import signal
|
import signal
|
||||||
import sys
|
import sys
|
||||||
import traceback
|
import traceback
|
||||||
|
|
||||||
|
import sdnotify
|
||||||
from daemonize import Daemonize
|
from daemonize import Daemonize
|
||||||
|
|
||||||
from twisted.internet import defer, error, reactor
|
from twisted.internet import defer, error, reactor
|
||||||
@ -242,9 +244,16 @@ def start(hs, listeners=None):
|
|||||||
if hasattr(signal, "SIGHUP"):
|
if hasattr(signal, "SIGHUP"):
|
||||||
|
|
||||||
def handle_sighup(*args, **kwargs):
|
def handle_sighup(*args, **kwargs):
|
||||||
|
# Tell systemd our state, if we're using it. This will silently fail if
|
||||||
|
# we're not using systemd.
|
||||||
|
sd_channel = sdnotify.SystemdNotifier()
|
||||||
|
sd_channel.notify("RELOADING=1")
|
||||||
|
|
||||||
for i in _sighup_callbacks:
|
for i in _sighup_callbacks:
|
||||||
i(hs)
|
i(hs)
|
||||||
|
|
||||||
|
sd_channel.notify("READY=1")
|
||||||
|
|
||||||
signal.signal(signal.SIGHUP, handle_sighup)
|
signal.signal(signal.SIGHUP, handle_sighup)
|
||||||
|
|
||||||
register_sighup(refresh_certificate)
|
register_sighup(refresh_certificate)
|
||||||
@ -260,6 +269,7 @@ def start(hs, listeners=None):
|
|||||||
hs.get_datastore().start_profiling()
|
hs.get_datastore().start_profiling()
|
||||||
|
|
||||||
setup_sentry(hs)
|
setup_sentry(hs)
|
||||||
|
setup_sdnotify(hs)
|
||||||
except Exception:
|
except Exception:
|
||||||
traceback.print_exc(file=sys.stderr)
|
traceback.print_exc(file=sys.stderr)
|
||||||
reactor = hs.get_reactor()
|
reactor = hs.get_reactor()
|
||||||
@ -292,6 +302,25 @@ def setup_sentry(hs):
|
|||||||
scope.set_tag("worker_name", name)
|
scope.set_tag("worker_name", name)
|
||||||
|
|
||||||
|
|
||||||
|
def setup_sdnotify(hs):
|
||||||
|
"""Adds process state hooks to tell systemd what we are up to.
|
||||||
|
"""
|
||||||
|
|
||||||
|
# Tell systemd our state, if we're using it. This will silently fail if
|
||||||
|
# we're not using systemd.
|
||||||
|
sd_channel = sdnotify.SystemdNotifier()
|
||||||
|
|
||||||
|
hs.get_reactor().addSystemEventTrigger(
|
||||||
|
"after",
|
||||||
|
"startup",
|
||||||
|
lambda: sd_channel.notify("READY=1\nMAINPID=%s" % (os.getpid())),
|
||||||
|
)
|
||||||
|
|
||||||
|
hs.get_reactor().addSystemEventTrigger(
|
||||||
|
"before", "shutdown", lambda: sd_channel.notify("STOPPING=1")
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
def install_dns_limiter(reactor, max_dns_requests_in_flight=100):
|
def install_dns_limiter(reactor, max_dns_requests_in_flight=100):
|
||||||
"""Replaces the resolver with one that limits the number of in flight DNS
|
"""Replaces the resolver with one that limits the number of in flight DNS
|
||||||
requests.
|
requests.
|
||||||
|
@ -168,7 +168,9 @@ def start(config_options):
|
|||||||
)
|
)
|
||||||
|
|
||||||
ps.setup()
|
ps.setup()
|
||||||
reactor.callWhenRunning(_base.start, ps, config.worker_listeners)
|
reactor.addSystemEventTrigger(
|
||||||
|
"before", "startup", _base.start, ps, config.worker_listeners
|
||||||
|
)
|
||||||
|
|
||||||
_base.start_worker_reactor("synapse-appservice", config)
|
_base.start_worker_reactor("synapse-appservice", config)
|
||||||
|
|
||||||
|
@ -194,7 +194,9 @@ def start(config_options):
|
|||||||
)
|
)
|
||||||
|
|
||||||
ss.setup()
|
ss.setup()
|
||||||
reactor.callWhenRunning(_base.start, ss, config.worker_listeners)
|
reactor.addSystemEventTrigger(
|
||||||
|
"before", "startup", _base.start, ss, config.worker_listeners
|
||||||
|
)
|
||||||
|
|
||||||
_base.start_worker_reactor("synapse-client-reader", config)
|
_base.start_worker_reactor("synapse-client-reader", config)
|
||||||
|
|
||||||
|
@ -193,7 +193,9 @@ def start(config_options):
|
|||||||
)
|
)
|
||||||
|
|
||||||
ss.setup()
|
ss.setup()
|
||||||
reactor.callWhenRunning(_base.start, ss, config.worker_listeners)
|
reactor.addSystemEventTrigger(
|
||||||
|
"before", "startup", _base.start, ss, config.worker_listeners
|
||||||
|
)
|
||||||
|
|
||||||
_base.start_worker_reactor("synapse-event-creator", config)
|
_base.start_worker_reactor("synapse-event-creator", config)
|
||||||
|
|
||||||
|
@ -175,7 +175,9 @@ def start(config_options):
|
|||||||
)
|
)
|
||||||
|
|
||||||
ss.setup()
|
ss.setup()
|
||||||
reactor.callWhenRunning(_base.start, ss, config.worker_listeners)
|
reactor.addSystemEventTrigger(
|
||||||
|
"before", "startup", _base.start, ss, config.worker_listeners
|
||||||
|
)
|
||||||
|
|
||||||
_base.start_worker_reactor("synapse-federation-reader", config)
|
_base.start_worker_reactor("synapse-federation-reader", config)
|
||||||
|
|
||||||
|
@ -198,7 +198,9 @@ def start(config_options):
|
|||||||
)
|
)
|
||||||
|
|
||||||
ss.setup()
|
ss.setup()
|
||||||
reactor.callWhenRunning(_base.start, ss, config.worker_listeners)
|
reactor.addSystemEventTrigger(
|
||||||
|
"before", "startup", _base.start, ss, config.worker_listeners
|
||||||
|
)
|
||||||
|
|
||||||
_base.start_worker_reactor("synapse-federation-sender", config)
|
_base.start_worker_reactor("synapse-federation-sender", config)
|
||||||
|
|
||||||
|
@ -247,7 +247,9 @@ def start(config_options):
|
|||||||
)
|
)
|
||||||
|
|
||||||
ss.setup()
|
ss.setup()
|
||||||
reactor.callWhenRunning(_base.start, ss, config.worker_listeners)
|
reactor.addSystemEventTrigger(
|
||||||
|
"before", "startup", _base.start, ss, config.worker_listeners
|
||||||
|
)
|
||||||
|
|
||||||
_base.start_worker_reactor("synapse-frontend-proxy", config)
|
_base.start_worker_reactor("synapse-frontend-proxy", config)
|
||||||
|
|
||||||
|
@ -447,7 +447,7 @@ def setup(config_options):
|
|||||||
reactor.stop()
|
reactor.stop()
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
reactor.callWhenRunning(start)
|
reactor.addSystemEventTrigger("before", "startup", start)
|
||||||
|
|
||||||
return hs
|
return hs
|
||||||
|
|
||||||
|
@ -161,7 +161,9 @@ def start(config_options):
|
|||||||
)
|
)
|
||||||
|
|
||||||
ss.setup()
|
ss.setup()
|
||||||
reactor.callWhenRunning(_base.start, ss, config.worker_listeners)
|
reactor.addSystemEventTrigger(
|
||||||
|
"before", "startup", _base.start, ss, config.worker_listeners
|
||||||
|
)
|
||||||
|
|
||||||
_base.start_worker_reactor("synapse-media-repository", config)
|
_base.start_worker_reactor("synapse-media-repository", config)
|
||||||
|
|
||||||
|
@ -216,7 +216,7 @@ def start(config_options):
|
|||||||
_base.start(ps, config.worker_listeners)
|
_base.start(ps, config.worker_listeners)
|
||||||
ps.get_pusherpool().start()
|
ps.get_pusherpool().start()
|
||||||
|
|
||||||
reactor.callWhenRunning(start)
|
reactor.addSystemEventTrigger("before", "startup", start)
|
||||||
|
|
||||||
_base.start_worker_reactor("synapse-pusher", config)
|
_base.start_worker_reactor("synapse-pusher", config)
|
||||||
|
|
||||||
|
@ -451,7 +451,9 @@ def start(config_options):
|
|||||||
)
|
)
|
||||||
|
|
||||||
ss.setup()
|
ss.setup()
|
||||||
reactor.callWhenRunning(_base.start, ss, config.worker_listeners)
|
reactor.addSystemEventTrigger(
|
||||||
|
"before", "startup", _base.start, ss, config.worker_listeners
|
||||||
|
)
|
||||||
|
|
||||||
_base.start_worker_reactor("synapse-synchrotron", config)
|
_base.start_worker_reactor("synapse-synchrotron", config)
|
||||||
|
|
||||||
|
@ -224,7 +224,9 @@ def start(config_options):
|
|||||||
)
|
)
|
||||||
|
|
||||||
ss.setup()
|
ss.setup()
|
||||||
reactor.callWhenRunning(_base.start, ss, config.worker_listeners)
|
reactor.addSystemEventTrigger(
|
||||||
|
"before", "startup", _base.start, ss, config.worker_listeners
|
||||||
|
)
|
||||||
|
|
||||||
_base.start_worker_reactor("synapse-user-dir", config)
|
_base.start_worker_reactor("synapse-user-dir", config)
|
||||||
|
|
||||||
|
@ -72,6 +72,7 @@ REQUIREMENTS = [
|
|||||||
"netaddr>=0.7.18",
|
"netaddr>=0.7.18",
|
||||||
"Jinja2>=2.9",
|
"Jinja2>=2.9",
|
||||||
"bleach>=1.4.3",
|
"bleach>=1.4.3",
|
||||||
|
"sdnotify>=0.3",
|
||||||
]
|
]
|
||||||
|
|
||||||
CONDITIONAL_REQUIREMENTS = {
|
CONDITIONAL_REQUIREMENTS = {
|
||||||
|
Loading…
Reference in New Issue
Block a user