From d41708ee247ce5efc5dc06f2d233e8d620fc6e4a Mon Sep 17 00:00:00 2001 From: Thomas Mangin Date: Sat, 23 May 2020 07:09:10 +0100 Subject: http-api: T2494: always exit with non zero on failure systemd is setup with Restart=on-failure thereforer the service will only be restarted if the daemon died and reported an error. Previously any OsError would cause a exit(0) and therefore the API would not have been restarted. https://www.freedesktop.org/software/systemd/man/systemd.service.html --- src/services/vyos-http-api-server | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/services/vyos-http-api-server b/src/services/vyos-http-api-server index 4c41fa96d..b256add98 100755 --- a/src/services/vyos-http-api-server +++ b/src/services/vyos-http-api-server @@ -400,4 +400,4 @@ if __name__ == '__main__': serve(app, host=server_config["listen_address"], port=server_config["port"]) except OSError as e: - print(f"OSError {e}") + sys.exit(f"OSError {e}") -- cgit v1.2.3 From d9fbad6a6bbba292f31fe50e57af893062c7a584 Mon Sep 17 00:00:00 2001 From: Thomas Mangin Date: Sat, 23 May 2020 07:33:47 +0100 Subject: systemd: T2494: use Type=notify with daemon Notify systemd via the notify API when the python daemon are ready to take connection https://github.com/torfsen/python-systemd-tutorial --- debian/control | 1 + src/services/vyos-hostsd | 1 + src/services/vyos-http-api-server | 2 ++ src/systemd/vyos-hostsd.service | 2 +- src/systemd/vyos-http-api.service | 2 +- 5 files changed, 6 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/debian/control b/debian/control index 5e14340a8..aaf8fa1e7 100644 --- a/debian/control +++ b/debian/control @@ -36,6 +36,7 @@ Depends: python3, python3-xmltodict, python3-pyudev, python3-voluptuous, + python3-systemd, bsdmainutils, cron, etherwake, diff --git a/src/services/vyos-hostsd b/src/services/vyos-hostsd index 0079f7e5c..53ac5a770 100755 --- a/src/services/vyos-hostsd +++ b/src/services/vyos-hostsd @@ -592,6 +592,7 @@ if __name__ == '__main__': socket.bind(SOCKET_PATH) os.umask(o_mask) + systemd.daemon.notify('READY=1') while True: # Wait for next request from client msg_json = socket.recv().decode() diff --git a/src/services/vyos-http-api-server b/src/services/vyos-http-api-server index b256add98..38bf2f8ce 100755 --- a/src/services/vyos-http-api-server +++ b/src/services/vyos-http-api-server @@ -28,6 +28,7 @@ import vyos.config from flask import Flask, request from waitress import serve +import systemd.daemon from functools import wraps @@ -396,6 +397,7 @@ if __name__ == '__main__': signal.signal(signal.SIGTERM, sig_handler) + systemd.daemon.notify('READY=1') try: serve(app, host=server_config["listen_address"], port=server_config["port"]) diff --git a/src/systemd/vyos-hostsd.service b/src/systemd/vyos-hostsd.service index b77335778..418601d1a 100644 --- a/src/systemd/vyos-hostsd.service +++ b/src/systemd/vyos-hostsd.service @@ -14,7 +14,7 @@ WorkingDirectory=/run/vyos-hostsd RuntimeDirectory=vyos-hostsd RuntimeDirectoryPreserve=yes ExecStart=/usr/bin/python3 -u /usr/libexec/vyos/services/vyos-hostsd -Type=idle +Type=notify KillMode=process SyslogIdentifier=vyos-hostsd diff --git a/src/systemd/vyos-http-api.service b/src/systemd/vyos-http-api.service index 4fa68b4ff..636973be7 100644 --- a/src/systemd/vyos-http-api.service +++ b/src/systemd/vyos-http-api.service @@ -6,7 +6,7 @@ Requires=vyos-router.service [Service] ExecStartPre=/usr/libexec/vyos/init/vyos-config ExecStart=/usr/bin/python3 -u /usr/libexec/vyos/services/vyos-http-api-server -Type=idle +Type=notify KillMode=process SyslogIdentifier=vyos-http-api -- cgit v1.2.3 From 8d50cb7a4044049b8287ce9b076fbc6b7bb1cfef Mon Sep 17 00:00:00 2001 From: Thomas Mangin Date: Sat, 23 May 2020 07:52:31 +0100 Subject: http-api: T2494: remove inaccurate systemd comment --- src/systemd/vyos-http-api.service | 1 - 1 file changed, 1 deletion(-) (limited to 'src') diff --git a/src/systemd/vyos-http-api.service b/src/systemd/vyos-http-api.service index 636973be7..e336ed18b 100644 --- a/src/systemd/vyos-http-api.service +++ b/src/systemd/vyos-http-api.service @@ -14,7 +14,6 @@ SyslogFacility=daemon Restart=on-failure -# Does't work but leave it here User=root Group=vyattacfg -- cgit v1.2.3 From 4d6f9a3f803d1f4a5735867ae3ea124deedbdae1 Mon Sep 17 00:00:00 2001 From: Thomas Mangin Date: Sat, 23 May 2020 08:29:16 +0100 Subject: hostsd: T2494: systemd remove inaccurate systemd comment --- src/systemd/vyos-hostsd.service | 1 - 1 file changed, 1 deletion(-) (limited to 'src') diff --git a/src/systemd/vyos-hostsd.service b/src/systemd/vyos-hostsd.service index 418601d1a..560e04052 100644 --- a/src/systemd/vyos-hostsd.service +++ b/src/systemd/vyos-hostsd.service @@ -22,7 +22,6 @@ SyslogFacility=daemon Restart=on-failure -# Does't work in Jessie but leave it here User=root Group=hostsd -- cgit v1.2.3 From 54b92aea418ddca07b9f699466411e58ddfc52c3 Mon Sep 17 00:00:00 2001 From: Thomas Mangin Date: Sat, 23 May 2020 09:03:10 +0100 Subject: hostsd: T2494: vyos-hostsd is part of systemd vyos.target The install section determine if the package should be enabled. vyos-hostd should be install if vyos.target is enabled. --- src/systemd/vyos-hostsd.service | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/systemd/vyos-hostsd.service b/src/systemd/vyos-hostsd.service index 560e04052..d10a0a939 100644 --- a/src/systemd/vyos-hostsd.service +++ b/src/systemd/vyos-hostsd.service @@ -30,4 +30,4 @@ Group=hostsd # Note: After= doesn't actually create a dependency, # it just sets order for the case when both services are to start, # and without RequiredBy it *does not* set vyos-hostsd to start. -RequiredBy=cloud-init-local.service vyos-router.service +WantedBy=vyos.target -- cgit v1.2.3 From 1ecb1d76cd0b149d6381a143adc9907adee47607 Mon Sep 17 00:00:00 2001 From: Thomas Mangin Date: Sat, 23 May 2020 09:05:43 +0100 Subject: http-api: T2494: remove "barrier" PreExec The PreExec is making sure that the vyos-config-status file exists and blocks until it does. This file is created on boot completion and I can see no reason why the http service has to wait for the end of boot to start. Any barrier to start should be done with systemd itself. --- src/systemd/vyos-http-api.service | 1 - 1 file changed, 1 deletion(-) (limited to 'src') diff --git a/src/systemd/vyos-http-api.service b/src/systemd/vyos-http-api.service index e336ed18b..a2920376e 100644 --- a/src/systemd/vyos-http-api.service +++ b/src/systemd/vyos-http-api.service @@ -4,7 +4,6 @@ After=auditd.service systemd-user-sessions.service time-sync.target vyos-router. Requires=vyos-router.service [Service] -ExecStartPre=/usr/libexec/vyos/init/vyos-config ExecStart=/usr/bin/python3 -u /usr/libexec/vyos/services/vyos-http-api-server Type=notify KillMode=process -- cgit v1.2.3 From 8cd23ec0449b3755240b9aebe236fdb66937d7d6 Mon Sep 17 00:00:00 2001 From: Thomas Mangin Date: Sat, 23 May 2020 15:02:47 +0100 Subject: http-api: T2494: systemd http-api has no link getty.target WantedBy is about the service installation and is not related to the boot order, linking to vyos.target instead --- src/systemd/vyos-http-api.service | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'src') diff --git a/src/systemd/vyos-http-api.service b/src/systemd/vyos-http-api.service index a2920376e..74a97d193 100644 --- a/src/systemd/vyos-http-api.service +++ b/src/systemd/vyos-http-api.service @@ -17,6 +17,4 @@ User=root Group=vyattacfg [Install] -# Installing in a earlier target leaves ExecStartPre waiting -WantedBy=getty.target - +WantedBy=vyos.target -- cgit v1.2.3 From be8cda7f711a7a26c85b51976c299a6837750a63 Mon Sep 17 00:00:00 2001 From: Thomas Mangin Date: Mon, 25 May 2020 17:33:07 +0100 Subject: http-api: T2494: start before vyos-router vyos-router may/is requiring access to the service, make sure it starts before, if not is has no consequence to do so anyway. --- src/systemd/vyos-hostsd.service | 1 + 1 file changed, 1 insertion(+) (limited to 'src') diff --git a/src/systemd/vyos-hostsd.service b/src/systemd/vyos-hostsd.service index d10a0a939..26e9c745e 100644 --- a/src/systemd/vyos-hostsd.service +++ b/src/systemd/vyos-hostsd.service @@ -1,5 +1,6 @@ [Unit] Description=VyOS DNS configuration keeper +Before=vyos-router.service # Without this option, lots of default dependencies are added, # among them network.target, which creates a dependency cycle -- cgit v1.2.3