简介
这篇文章主要介绍了linux添加自定义service服务,开机自启动方式,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教,
第一步:准备配置文件
- 配置文件示例:xxx.service
[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
- ps:env示例
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 服务名
-n
查看尾部多少行-f
滚动形式
查看日志占用的磁盘空间
journalctl --disk-usage
以上为个人经验,希望能给大家一个参考,也希望大家多多支持腾创网。
以上本篇文章的全部内容了,感兴趣的小伙伴可以看看,更多精彩内容关注腾创网www.tengchuangw.com
© 版权声明
本站提供的资源,都来自网络,版权争议与本站无关,所有内容及软件的文章仅限用于学习和研究目的。不得将上述内容用于商业或者非法用途,否则,一切后果请用户自负,我们不保证内容的长久可用性,通过使用本站内容随之而来的风险与本站无关,您必须在下载后的24个小时之内,从您的电脑/手机中彻底删除上述内容。如果您喜欢该程序,请支持正版软件,购买注册,得到更好的正版服务。侵删请致信E-mail: 571533527@qq.com
THE END
暂无评论内容