linux添加自定義service服務,開機自啟動方式
更新時間:2024年08月08日 15:21:31 作者:千年恨
這篇文章主要介紹了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 // 環(huán)境變量, 不需要則置為空 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 修改了文件后重新加載
查詢?nèi)罩?/h4>
- 查看指定服務日志
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 -u 服務名
journalctl --since="2021-10-10 10:10:00" --until="2021-10-11 10:10:00" -u 服務名
journalctl -f -n 20 -u 服務名
-n 查看尾部多少行-f 滾動形式查看日志占用的磁盤空間
journalctl --disk-usage
總結
以上為個人經(jīng)驗,希望能給大家一個參考,也希望大家多多支持腳本之家。
相關文章
Linux系統(tǒng)配置sftp服務以及實現(xiàn)免密登錄方式
這篇文章主要介紹了Linux系統(tǒng)配置sftp服務以及實現(xiàn)免密登錄方式,具有很好的參考價值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教2024-06-06
Ubuntu18.04 一鍵升級Python所有第三方包 及安裝python包的方法
pip 是 Python 包管理工具,該工具提供了對Python 包的查找、下載、安裝、卸載的功能。這篇文章給大家介紹Ubuntu18.04 一鍵升級Python所有第三方包 ,感興趣的朋友一起看看吧2019-10-10

