Skip to content

Commit

Permalink
Fix systemd startup (#1541)
Browse files Browse the repository at this point in the history
## Problem

Problem description is in issue #1539 


## Solution

Implement sd_notify for agama-web-service to notify systemd when web
service is ready to serve requests.
Improve systemd dependencies to better reflect dependencies. For
agama-auto adapt dependencies to reflect that CLI switch from direct
systemd communication to HTTP API. related PR is
#1438


## Testing

- *Tested manually*


## Screenshots

snippet from log before change ( truncated, but to demonstrate that
agama-auto runs too soon):

```
Aug 14 13:10:47 dhcp118.suse.cz systemd[1]: Started Agama Installer Service.
Aug 14 13:10:47 dhcp118.suse.cz systemd[1]: Started Agama Web Server.
Aug 14 13:10:47 dhcp118.suse.cz systemd[1]: Started Agama automatic profile runner.
Aug 14 13:10:47 dhcp118.suse.cz systemd[1]: Starting Postpone login prompt after the SSL fingerprint issue is generated...
Aug 14 13:10:47 dhcp118.suse.cz agama-auto[2689]: + export YAST_SKIP_XML_VALIDATION=1
Aug 14 13:10:47 dhcp118.suse.cz agama-auto[2689]: + YAST_SKIP_XML_VALIDATION=1
Aug 14 13:10:47 dhcp118.suse.cz agama-auto[2689]: + '[' -z '' ']'
Aug 14 13:10:47 dhcp118.suse.cz agama-auto[2691]: ++ awk -F agama.auto= '{sub(/ .*$/, "", $2); print $2}'
Aug 14 13:10:47 dhcp118.suse.cz agama-auto[2689]: + url=
Aug 14 13:10:47 dhcp118.suse.cz agama-auto[2689]: + '[' -z '' ']'
Aug 14 13:10:47 dhcp118.suse.cz agama-auto[2689]: + echo 'no autoinstallation profile'
Aug 14 13:10:47 dhcp118.suse.cz agama-auto[2689]: no autoinstallation profile
Aug 14 13:10:47 dhcp118.suse.cz agama-auto[2689]: + exit 0
Aug 14 13:10:47 dhcp118.suse.cz systemd[1]: agama-auto.service: Deactivated successfully.
Aug 14 13:10:47 dhcp118.suse.cz sshd-gen-keys-start[2683]: ssh-keygen: generating new host keys: RSA ECDSA ED25519
Aug 14 13:10:47 dhcp118.suse.cz sshd[2702]: Server listening on 0.0.0.0 port 22.
Aug 14 13:10:47 dhcp118.suse.cz sshd[2702]: Server listening on :: port 22.
Aug 14 13:10:47 dhcp118.suse.cz systemd[1]: Started OpenSSH Daemon.
Aug 14 13:10:47 dhcp118.suse.cz systemd[1]: Starting Generate issue file for SSH host keys...
Aug 14 13:10:47 dhcp118.suse.cz systemd[1]: agama-ssh-issue.service: Deactivated successfully.
Aug 14 13:10:47 dhcp118.suse.cz systemd[1]: Finished Generate issue file for SSH host keys.
Aug 14 13:10:47 dhcp118.suse.cz agama-web-server[2688]: registering event source with poller: token=Token(94923250365696), interests=READABLE | WRITABLE
Aug 14 13:10:47 dhcp118.suse.cz agama-web-server[2688]: Initializing
Aug 14 13:10:47 dhcp118.suse.cz agama-web-server[2688]: Waiting for DATA or OK from server
Aug 14 13:10:47 dhcp118.suse.cz agama-web-server[2688]: Received OK from server
Aug 14 13:10:47 dhcp118.suse.cz agama-web-server[2688]: Waiting for Unix FD passing agreement from server
Aug 14 13:10:47 dhcp118.suse.cz agama-web-server[2688]: Unix FD passing agreed by server
```

and now after change:

```
Aug 15 10:19:15 dhcp118.suse.cz systemd[1]: Started Agama Web Server.
Aug 15 10:19:15 dhcp118.suse.cz agama-web-server[12467]: Starting Agama web server at :::80
Aug 15 10:19:15 dhcp118.suse.cz agama-web-server[12467]: Starting Agama web server at :::443
...
Aug 15 10:19:15 dhcp118.suse.cz agama-web-server[12467]: Waiting for message on the socket..
...
Aug 15 10:19:15 dhcp118.suse.cz agama-web-server[12467]: Listening for property changes on org.freedesktop.NetworkManager.Device...
Aug 15 10:19:15 dhcp118.suse.cz systemd[1]: Started Agama automatic profile runner.
Aug 15 10:19:15 dhcp118.suse.cz agama-web-server[12467]: Message received on the socket: Msg { type: Signal, sender: UniqueName(Str(Borrowed(":1.2"))), path: ObjectPath("/org/freedesktop/systemd1/unit/agama_2dauto_2eservice"), iface: InterfaceName(Str(Borrowed("org.freedesktop.DBus.Properties"))), member: MemberName(Str(Borrowed("PropertiesChanged"))), body: Signature("sa{sv}as") }
Aug 15 10:19:15 dhcp118.suse.cz agama-auto[12479]: + export YAST_SKIP_XML_VALIDATION=1
Aug 15 10:19:15 dhcp118.suse.cz agama-auto[12479]: + YAST_SKIP_XML_VALIDATION=1
Aug 15 10:19:15 dhcp118.suse.cz agama-auto[12479]: + '[' -z '' ']'
...
Aug 15 10:19:15 dhcp118.suse.cz agama-web-server[12467]: Waiting for message on the socket..
Aug 15 10:19:15 dhcp118.suse.cz agama-auto[12482]: ++ awk -F agama.auto= '{sub(/ .*$/, "", $2); print $2}'
Aug 15 10:19:15 dhcp118.suse.cz agama-auto[12479]: + url=
Aug 15 10:19:15 dhcp118.suse.cz agama-auto[12479]: + '[' -z '' ']'
Aug 15 10:19:15 dhcp118.suse.cz agama-auto[12479]: + echo 'no autoinstallation profile'
Aug 15 10:19:15 dhcp118.suse.cz agama-auto[12479]: no autoinstallation profile
Aug 15 10:19:15 dhcp118.suse.cz agama-auto[12479]: + exit 0
Aug 15 10:19:15 dhcp118.suse.cz systemd[1]: agama-auto.service: Deactivated successfully.
```
  • Loading branch information
jreidinger authored Aug 19, 2024
2 parents d7eec2a + facecdd commit fc0f3a2
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 7 deletions.
8 changes: 8 additions & 0 deletions autoinstallation/package/agama-auto.changes
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
-------------------------------------------------------------------
Thu Aug 15 08:35:31 UTC 2024 - Josef Reidinger <jreidinger@suse.com>

- change agama-auto systemd service depedencies to reflect changes
in agama CLI communication and ensure that it runs when
agama-auto runs
(gh#openSUSE/agama#1539)

-------------------------------------------------------------------
Wed Jul 3 15:24:48 UTC 2024 - Imobach Gonzalez Sosa <igonzalezsosa@suse.com>

Expand Down
8 changes: 3 additions & 5 deletions autoinstallation/systemd/agama-auto.service
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
[Unit]
Description=Agama automatic profile runner
# it needs to D-Bus, so it has access to Agama D-Bus interface
After=dbus.socket
# it needs to NetworkManager, so it has access to it
After=NetworkManager.service
# it needs agama, of course
# it needs agama web service as it calls CLI which uses its API
# other dependencies are transitive
After=agama-web-server.service
BindsTo=agama-web-server.service

[Service]
ExecStart=/usr/bin/agama-auto
Expand Down
7 changes: 7 additions & 0 deletions rust/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions rust/agama-server/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ pam = "0.8.0"
serde_with = "3.6.1"
pin-project = "1.1.5"
openssl = "0.10.64"
sd-notify = "0.4.2"
hyper = "1.2.0"
hyper-util = "0.1.3"
tokio-openssl = "0.6.4"
Expand Down
6 changes: 6 additions & 0 deletions rust/agama-server/src/agama-web-server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,12 @@ async fn serve_command(args: ServeArgs) -> anyhow::Result<()> {
})
.collect();

// notify systemd that web server start serving
if let Ok(true) = sd_notify::booted() {
sd_notify::notify(true, &[sd_notify::NotifyState::Ready])
.context("Failed to notify systemd")?;
}

futures_util::future::join_all(servers).await;

Ok(())
Expand Down
9 changes: 9 additions & 0 deletions rust/package/agama.changes
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
-------------------------------------------------------------------
Thu Aug 15 08:33:02 UTC 2024 - Josef Reidinger <jreidinger@suse.com>

- Use sd_notify for starting agama-web-service to notify systemd
when service is ready. It helps with race condition in agama-auto
(gh#openSUSE/agama#1539)
- improve systemd dependencies of agama-web-service to ensure that
agama service runs

-------------------------------------------------------------------
Fri Aug 9 08:50:31 UTC 2024 - Martin Vidner <mvidner@suse.com>

Expand Down
4 changes: 2 additions & 2 deletions rust/share/agama-web-server.service
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ Description=Agama Web Server
# agama-hostname might change the host name which is used when creating
# a self signed certificate, run it before the web server
After=network-online.target agama.service agama-hostname.service
PartOf=agama.service
BindsTo=agama.service

[Service]
Type=simple
Type=notify
ExecStart=/usr/bin/agama-web-server serve --address :::80 --address2 :::443
PIDFile=/run/agama/web.pid
User=root
Expand Down

0 comments on commit fc0f3a2

Please sign in to comment.