Debian/Ubuntu 安装 Syncthing 及添加服务(自启动)小记
安装 Syncthing
首先,添加软件源 GPG 密钥:
1sudo curl -o /usr/share/keyrings/syncthing-archive-keyring.gpg https://syncthing.net/release-key.gpg
之后添加 APT 软件源:
1echo "deb [signed-by=/usr/share/keyrings/syncthing-archive-keyring.gpg] https://apt.syncthing.net/ syncthing stable" | sudo tee /etc/apt/sources.list.d/syncthing.list
最后更新软件源并安装:
1sudo apt update
2sudo apt install syncthing
服务配置
为 Syncthing 创建服务,直接将以下配置的内容写入到 /etc/systemd/system/syncthing@.service
文件即可:
1[Unit]
2Description=Syncthing - Open Source Continuous File Synchronization for %I
3Documentation=man:syncthing(1)
4After=network.target
5StartLimitIntervalSec=60
6StartLimitBurst=4
7
8[Service]
9User=%i
10ExecStart=/usr/bin/syncthing serve --no-browser --no-restart --logflags=0
11Restart=on-failure
12RestartSec=1
13SuccessExitStatus=3 4
14RestartForceExitStatus=3 4
15
16# Hardening
17ProtectSystem=full
18PrivateTmp=true
19SystemCallArchitectures=native
20MemoryDenyWriteExecute=true
21NoNewPrivileges=true
22
23# Elevated permissions to sync ownership (disabled by default),
24# see https://docs.syncthing.net/advanced/folder-sync-ownership
25#AmbientCapabilities=CAP_CHOWN CAP_FOWNER
26
27[Install]
28WantedBy=multi-user.target
然后使用 systemctl
命令启用服务(注意将 myuser
替换为实际 Syncthing 用户):
1systemctl enable syncthing@myuser.service
2systemctl start syncthing@myuser.service
番外
通过 journalctl
命令可以查看 Syncthing 运行日志:
1journalctl -e -u syncthing@myuser.service
通过 systemctl status
命令可以查看 Syncthing 运行状态:
1systemctl status syncthing@myuser.service