systemd 自动启动

路径: /lib/systemd/system/hysteria.service

1
2
3
4
5
6
7
8
9
10
11
[Unit]
Description=Hysteria
After=network.target network-online.target nss-lookup.target

[Service]
Restart=on-failure
Type=simple
ExecStart=/usr/sbin/hysteria -config /etc/hysteria/config.json server

[Install]
WantedBy=multi-user.target
1
2
3
4
systemctl daemon-reload # 重新加载
systemctl enable hysteria # 开机自启
systemctl start hysteria # 启动
systemctl status hysteria # 状态

使用 cat 生成配置文件

1
2
3
4
5
6
7
8
9
10
11
12
13
14
cat > /etc/systemd/system/onedrive.service <<EOF
[Unit]
Description=onedrive
After=network-online.target remote-fs.target nss-lookup.target

[Service]
Type=simple
ExecStart=/usr/bin/rclone mount onedrive: /onedrive --use-mmap --umask 000 --default-permissions --no-check-certificate --allow-other --allow-non-empty --dir-cache-time 24h --cache-dir=/home/cache --vfs-cache-mode full --buffer-size 256M --vfs-read-ahead 512M --vfs-read-chunk-size 32M --vfs-read-chunk-size-limit 128M --vfs-cache-max-size 20G --low-level-retries 200
ExecStop=/usr/bin/fusermount -u /onedriver
Restart=on-abort

[Install]
WantedBy=multi-user.target
EOF

OpenRC 启动项

路径: /etc/init.d/hysteria

1
2
3
4
5
6
7
8
9
10
11
#!/sbin/openrc-run

name="hysteria"
command="/usr/sbin/hysteria"
command_args="-config /etc/hysteria/config.json server"
command_background="yes"
pidfile="/run/hysteria.pid"

depend() {
after sshd
}
1
2
3
4
chmod +x /etc/init.d/hysteria
rc-update add hysteria # 开机自启动
rc-service hysteria start # 启动
service hysteria status # 查看状态

Reference