Server: Improves systemd support

Closes #499
pull/507/head
Tpt 2 years ago committed by Thomas Tanon
parent cb89166380
commit 38af275451
  1. 19
      server/README.md
  2. 14
      server/src/main.rs

@ -220,6 +220,25 @@ brew install oxigraph
It installs the `oxigraph_server` binary. [See the usage documentation to know how to use it](#usage).
## Systemd
It is possible to run Oxigraph in the background using systemd.
For that, you can use the following `oxigraph_server.service` file (it might be inserted into `/etc/systemd/system/` or `$HOME/.config/systemd/user`):
```ini
[Unit]
Description=Oxigraph database server
After=network-online.target
Wants=network-online.target
[Service]
Type=notify
ExecStart=/PATH/TO/oxigraph_server serve --location /PATH/TO/OXIGRAPH/DATA
[Install]
WantedBy=multi-user.target
```
## Migration guide
### From 0.2 to 0.3

@ -17,9 +17,13 @@ use sparesults::{QueryResultsFormat, QueryResultsSerializer};
use std::borrow::Cow;
use std::cell::RefCell;
use std::cmp::{max, min};
#[cfg(target_os = "linux")]
use std::env;
use std::ffi::OsStr;
use std::fs::File;
use std::io::{self, stdin, stdout, BufRead, BufReader, BufWriter, Read, Write};
#[cfg(target_os = "linux")]
use std::os::unix::net::UnixDatagram;
use std::path::{Path, PathBuf};
use std::rc::Rc;
use std::str::FromStr;
@ -776,6 +780,8 @@ fn serve(store: Store, bind: String, read_only: bool, cors: bool) -> anyhow::Res
};
server.set_global_timeout(HTTP_TIMEOUT);
server.set_server_name(concat!("Oxigraph/", env!("CARGO_PKG_VERSION")))?;
#[cfg(target_os = "linux")]
systemd_notify_ready()?;
eprintln!("Listening for requests at http://{}", &bind);
server.listen(bind)?;
Ok(())
@ -1698,6 +1704,14 @@ impl Write for ReadForWriteWriter {
}
}
#[cfg(target_os = "linux")]
fn systemd_notify_ready() -> io::Result<()> {
if let Some(path) = env::var_os("NOTIFY_SOCKET") {
UnixDatagram::unbound()?.send_to(b"READY=1", path)?;
}
Ok(())
}
#[cfg(test)]
mod tests {
use super::*;

Loading…
Cancel
Save