add sample systemd files
This commit is contained in:
parent
f690d10ead
commit
86925ae262
3 changed files with 116 additions and 0 deletions
60
contrib/systemd/README.md
Normal file
60
contrib/systemd/README.md
Normal file
|
|
@ -0,0 +1,60 @@
|
|||
# systemd unit files
|
||||
|
||||
Two flavours: a per-user service (no root needed) and a system service.
|
||||
|
||||
## Per-user (recommended for personal use)
|
||||
|
||||
Runs under your login, socket lives in `$XDG_RUNTIME_DIR/cubby.sock`.
|
||||
|
||||
```bash
|
||||
go build -o ~/.local/bin/cubby ./cmd/cubby
|
||||
|
||||
mkdir -p ~/.config/systemd/user
|
||||
cp contrib/systemd/cubby.user.service ~/.config/systemd/user/cubby.service
|
||||
|
||||
systemctl --user daemon-reload
|
||||
systemctl --user enable --now cubby.service
|
||||
systemctl --user status cubby.service
|
||||
```
|
||||
|
||||
To survive logout/reboot without an active session:
|
||||
|
||||
```bash
|
||||
sudo loginctl enable-linger "$USER"
|
||||
```
|
||||
|
||||
The socket path is `/run/user/$(id -u)/cubby.sock`.
|
||||
|
||||
## System-wide (shared across users via a group)
|
||||
|
||||
Runs as a dedicated `cubby` user, socket at `/run/cubby/cubby.sock`,
|
||||
readable/writable by members of the `cubby` group.
|
||||
|
||||
```bash
|
||||
sudo useradd --system --no-create-home --shell /usr/sbin/nologin cubby
|
||||
sudo go build -o /usr/local/bin/cubby ./cmd/cubby
|
||||
# or: go build -o ./cubby ./cmd/cubby && sudo install -m 0755 ./cubby /usr/local/bin/cubby
|
||||
|
||||
sudo cp contrib/systemd/cubby.service /etc/systemd/system/cubby.service
|
||||
sudo systemctl daemon-reload
|
||||
sudo systemctl enable --now cubby.service
|
||||
sudo systemctl status cubby.service
|
||||
|
||||
# Add yourself (and others) to the cubby group to connect:
|
||||
sudo usermod -aG cubby "$USER"
|
||||
# log out and back in for new group membership to take effect
|
||||
```
|
||||
|
||||
## Common operations
|
||||
|
||||
```bash
|
||||
# user service
|
||||
systemctl --user restart cubby
|
||||
systemctl --user stop cubby
|
||||
journalctl --user -u cubby -f
|
||||
|
||||
# system service
|
||||
sudo systemctl restart cubby
|
||||
sudo systemctl stop cubby
|
||||
sudo journalctl -u cubby -f
|
||||
```
|
||||
38
contrib/systemd/cubby.service
Normal file
38
contrib/systemd/cubby.service
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
[Unit]
|
||||
Description=Cubby in-memory key-value cache (system-wide)
|
||||
Documentation=https://git.juancwu.dev/juancwu/cubby
|
||||
After=network.target
|
||||
|
||||
[Service]
|
||||
Type=simple
|
||||
# Run as a dedicated user. Create with:
|
||||
# sudo useradd --system --no-create-home --shell /usr/sbin/nologin cubby
|
||||
User=cubby
|
||||
Group=cubby
|
||||
|
||||
# Path to the cubby binary. Build with:
|
||||
# go build -o /usr/local/bin/cubby ./cmd/cubby
|
||||
ExecStart=/usr/local/bin/cubby -socket /run/cubby/cubby.sock -group cubby
|
||||
|
||||
# /run/cubby/ is created automatically and owned by User/Group above.
|
||||
RuntimeDirectory=cubby
|
||||
RuntimeDirectoryMode=0755
|
||||
|
||||
Restart=on-failure
|
||||
RestartSec=2s
|
||||
|
||||
# Hardening
|
||||
NoNewPrivileges=true
|
||||
PrivateTmp=true
|
||||
ProtectSystem=strict
|
||||
ProtectHome=true
|
||||
ProtectKernelTunables=true
|
||||
ProtectKernelModules=true
|
||||
ProtectControlGroups=true
|
||||
RestrictAddressFamilies=AF_UNIX
|
||||
RestrictNamespaces=true
|
||||
LockPersonality=true
|
||||
MemoryDenyWriteExecute=true
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
18
contrib/systemd/cubby.user.service
Normal file
18
contrib/systemd/cubby.user.service
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
[Unit]
|
||||
Description=Cubby in-memory key-value cache (per-user)
|
||||
Documentation=https://git.juancwu.dev/juancwu/cubby
|
||||
After=default.target
|
||||
|
||||
[Service]
|
||||
Type=simple
|
||||
# Path to the cubby binary. Build with:
|
||||
# go build -o ~/.local/bin/cubby ./cmd/cubby
|
||||
ExecStart=%h/.local/bin/cubby -socket %t/cubby.sock
|
||||
# %t expands to $XDG_RUNTIME_DIR (e.g. /run/user/1000), which is private to
|
||||
# the user, so the default 0600 socket permissions are fine.
|
||||
|
||||
Restart=on-failure
|
||||
RestartSec=2s
|
||||
|
||||
[Install]
|
||||
WantedBy=default.target
|
||||
Loading…
Add table
Add a link
Reference in a new issue