Skip to content

Commit

Permalink
Merge pull request #456 from Deric-W/systemd
Browse files Browse the repository at this point in the history
Support SystemD `Type=notify`
  • Loading branch information
icewind1991 authored May 28, 2024
2 parents 61e0558 + 2ed0f7d commit 83ad1ac
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 0 deletions.
7 changes: 7 additions & 0 deletions Cargo.lock

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

5 changes: 5 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ derivative = "2.2.0"
nextcloud-config-parser = { version = "0.10.0", features = ["redis-connect"] }
url = "2.5.0"
clap = { version = "4.5.4", features = ["derive"] }
sd-notify = { version = "0.4.1", optional = true }

[dev-dependencies]
mini-redis = "0.4.1"
Expand All @@ -49,3 +50,7 @@ opt-level = 3
lto = true

[workspace]

[features]
default = ["systemd"]
systemd = ["dep:sd-notify"]
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,15 @@ Documentation=https://github.com/nextcloud/notify_push
[Service]
Environment = PORT=7867 # Change if you already have something running on this port
ExecStart = /path/to/push/binary/notify_push /path/to/nextcloud/config/config.php
Type=notify # requires the push server to have been build with the systemd feature
User=www-data

[Install]
WantedBy = multi-user.target
```

If the push server has not been compiled with the optional systemd feature the `Type=notify` line has to be removed.

#### OpenRC

For OpenRC based setups, you can create an OpenRC service by creating a file named `/etc/init.d/notify_push` with the following content.
Expand Down
1 change: 1 addition & 0 deletions lib/SetupWizard.php
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,7 @@ public function generateSystemdService(bool $selfSigned): string {
Environment=PORT=7867
Environment=NEXTCLOUD_URL=$ncUrl
{$selfSigned}ExecStart=$path $config
Type=notify
User=$user
[Install]
Expand Down
3 changes: 3 additions & 0 deletions src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ pub enum Error {
Authentication(#[from] AuthenticationError),
#[error("Error while communicating with Nextcloud: {0}")]
NextCloud(#[from] NextCloudError),
#[cfg(feature = "systemd")]
#[error("Failed to notify SystemD: {0}")]
SystemD(#[from] std::io::Error),
}

#[derive(Debug, Error, Diagnostic)]
Expand Down
4 changes: 4 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,10 @@ async fn run(config: Config, log_handle: LoggerHandle) -> Result<()> {
)?);
}

// tell SystemD that sockets have been bound to their addresses
#[cfg(feature = "systemd")]
sd_notify::notify(true, &[sd_notify::NotifyState::Ready]).map_err(Error::SystemD)?;

spawn(listen_loop(app, listen_cancel_handle));

// wait for either a sigint or sigterm
Expand Down

0 comments on commit 83ad1ac

Please sign in to comment.