自己的服务开机自启动
第一步: 准备配置文件
[Unit]
Description=你的服务名称 Service
ConditionPathExists=/home/user/install/xxxxxxx
After=network.target
[Service]
Type=simple
User=root
EnvironmentFile=/home/user/install/env // 环境变量, 不需要则置为空
WorkingDirectory=/home/user/install
ExecStart=/home/user/install/xxxxxxx -c /home/user/install/config.yml
Restart=on-failure
RestartSec=10
StandardOutput=syslog
StandardError=syslog
SyslogIdentifier=xxxxxxx
[Install]
WantedBy=multi-user.target
LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/home/user/project
第二步:启动服务
sudo cp xxx.service /etc/systemd/system
sudo systemctl start xxx.service
sudo systemctl enable xxx.service
备注
/etc/systemd/system
systemctl start xxx.service
systemctl enable xxx.service 加入开机自启动
systemctl disable xxx.service 移除开机自启动
systemctl start xxx.service 启动
systemctl daemon-reload 修改了文件后重新加载
查询日志
- 查看指定服务日志
journalctl -u 服务名
- 查看指定日期日志
journalctl --since="2021-10-10 10:10:00" --until="2021-10-11 10:10:00" -u 服务名
- 类似tail -f
journalctl -f -n 20 -u 服务名
- 查看日志占用的磁盘空间
journalctl --disk-usage