1. 创建etc/systemd/system/clash.service
sudo vim /etc/systemd/system/clash.service
[Unit]
Description=clash service
After=network.target
[Service]
ExecStart=/usr/bin/clash -d /home/xiaxinkai/.config/clash/
[Install]
WantedBy=multi-user.target
2. systemctl配置开机启动
sudo systemctl daemon-reload # 刷新配置
sudo systemctl start clash # 启动clash.service
sudo systemctl enable clash # 设置开机启动
sudo systemctl status clash # 查看clash.service的状态
可以看到如下log:
xiaxinkai@tuf:~$ sudo systemctl status clash
[sudo] xiaxinkai 的密码:
● clash.service - clash service
Loaded: loaded (/etc/systemd/system/clash.service; enabled; vendor preset: enabled)
Active: active (running) since Thu 2022-03-17 23:15:55 CST; 23s ago
Main PID: 847 (clash)
Tasks: 19 (limit: 18925)
Memory: 17.7M
CGroup: /system.slice/clash.service
└─847 /usr/bin/clash -d /home/xiaxinkai/.config/clash/