Merge pull request #456 from Deric-W/systemd

Support SystemD `Type=notify`
This commit is contained in:
Robin Appelman 2024-05-28 15:46:12 +02:00 коммит произвёл GitHub
Родитель 61e05584e1 2ed0f7d4f8
Коммит 83ad1acd5c
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: B5690EEEBB952194
6 изменённых файлов: 23 добавлений и 0 удалений

7
Cargo.lock сгенерированный
Просмотреть файл

@ -1367,6 +1367,7 @@ dependencies = [
"rand",
"redis",
"reqwest",
"sd-notify",
"serde",
"serde_json",
"smallvec",
@ -1989,6 +1990,12 @@ dependencies = [
"untrusted",
]
[[package]]
name = "sd-notify"
version = "0.4.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "621e3680f3e07db4c9c2c3fb07c6223ab2fab2e54bd3c04c3ae037990f428c32"
[[package]]
name = "semver"
version = "0.10.0"

Просмотреть файл

@ -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"
@ -49,3 +50,7 @@ opt-level = 3
lto = true
[workspace]
[features]
default = ["systemd"]
systemd = ["dep:sd-notify"]

Просмотреть файл

@ -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.

Просмотреть файл

@ -246,6 +246,7 @@ Description = Push daemon for Nextcloud clients
Environment=PORT=7867
Environment=NEXTCLOUD_URL=$ncUrl
{$selfSigned}ExecStart=$path $config
Type=notify
User=$user
[Install]

Просмотреть файл

@ -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)]

Просмотреть файл

@ -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