From b33f1ad1b3ef3654973f2686b32c6bf19f4b0b73 Mon Sep 17 00:00:00 2001 From: postscriptum Date: Thu, 3 Jul 2025 16:09:45 +0300 Subject: [PATCH] add systemd configuration example --- README.md | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/README.md b/README.md index 716eb53..b94e9ba 100644 --- a/README.md +++ b/README.md @@ -74,6 +74,53 @@ snac2nex -s /path/to/snac/storage -t /path/to/nex -u user1 -u user2 Print version ``` +### Systemd + +To use `snac2nex` as the `systemd` service, install binary to the canonical system location: + +* `git clone https://codeberg.org/postscriptum/snac2nex.git && cd snac2nex` +* `cargo build --release` +* `sudo install target/release/snac2nex /usr/local/bin/snac2nex` + * tip: now you may want to clean the `snac2nex` sources folder to free up disk space + +Setup shared access permissions: + +1. `useradd -m snac2nex` - create new user with home dir (for log files) +2. `usermod -aG snac snac2nex` - replace `snac` with the `systemd` group for your [Snac](https://codeberg.org/grunfink/snac2) server + * `chmod -R g+r /path/to/snac/storage` - give the group read permissions to Snac directories +3. `usermod -aG nexy snac2nex` - replace `nexy` with the `systemd` group for your your Nex protocol server (e.g. [Nexy](https://github.com/YGGverse/nexy)) + * `chmod -R g+rw /path/to/nex` - give the group read/write permissions to Nex directories + +Create new `systemd` configuration file `/etc/systemd/system/snac2nex.service`: +``` snac2nex.service +[Unit] +After=network-online.target +Wants=network-online.target + +[Service] +Type=simple +User=snac2nex +Group=snac2nex +# Uncomment if your Snac or Nex unit has ExecStartPre timeout option +# ExecStartPre=/bin/sleep 15 +ExecStart=/usr/local/bin/snac2nex -s /path/to/snac/storage -t /path/to/nex -u user1 -u user2 -r 3600 -d +StandardOutput=file:/home/snac2nex/debug.log +StandardError=file:/home/snac2nex/error.log + +[Install] +WantedBy=multi-user.target +``` +* replace `ExecStart` arguments with your values, where: + * `-s` - Snac `storage` location + * `-u` - Snac `user`(s) to sync + * `-t` - Nex server `target` location for public files + * `-r` - is `rotate` every hour (`3600` seconds) to apply Snac instance updates (instead of export once) + * `-d` - enable `daemon` mode, which disables some debug output, to prevent extra write operations + * optionally, include `-a` (`attachment`) as `c` (`copy`) | `h` (`hard` link) | `s` (`soft` link) +* `systemctl daemon-reload` - apply new `systemd` configuration +* `systemctl enable snac2nex` - auto-start `snac2nex` sync on system boot +* `systemctl start snac2nex` - start `snac2nex` sync now + ## See also * [Nexy](https://github.com/YGGverse/nexy) - Server for the Nex protocol, written in Rust