linux添加自定義service服務(wù),開機(jī)自啟動(dòng)方式
更新時(shí)間:2024年08月08日 15:21:31 作者:千年恨
這篇文章主要介紹了linux添加自定義service服務(wù),開機(jī)自啟動(dòng)方式,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
自己的服務(wù)開機(jī)自啟動(dòng)
第一步:準(zhǔn)備配置文件
- 配置文件示例:xxx.service
[Unit] Description=你的服務(wù)名稱 Service ConditionPathExists=/home/user/install/xxxxxxx After=network.target [Service] Type=simple User=root EnvironmentFile=/home/user/install/env // 環(huán)境變量, 不需要?jiǎng)t置為空 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
第二步:啟動(dòng)服務(wù)
- 命令
sudo cp xxx.service /etc/systemd/system sudo systemctl start xxx.service sudo systemctl enable xxx.service
備注
- 命令
/etc/systemd/system ### 自定義服務(wù)存放路徑 systemctl start xxx.service ### 啟動(dòng) systemctl enable xxx.service 加入開機(jī)自啟動(dòng) systemctl disable xxx.service 移除開機(jī)自啟動(dòng) systemctl start xxx.service 啟動(dòng) systemctl daemon-reload 修改了文件后重新加載
查詢?nèi)罩?/h4>
- 查看指定服務(wù)日志
journalctl -u 服務(wù)名
- 查看指定日期日志
journalctl --since="2021-10-10 10:10:00" --until="2021-10-11 10:10:00" -u 服務(wù)名
- 類似tail -f
journalctl -f -n 20 -u 服務(wù)名
-n 查看尾部多少行-f 滾動(dòng)形式
journalctl -u 服務(wù)名
journalctl --since="2021-10-10 10:10:00" --until="2021-10-11 10:10:00" -u 服務(wù)名
journalctl -f -n 20 -u 服務(wù)名
-n 查看尾部多少行-f 滾動(dòng)形式查看日志占用的磁盤空間
journalctl --disk-usage
總結(jié)
以上為個(gè)人經(jīng)驗(yàn),希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。
相關(guān)文章
Linux系統(tǒng)配置sftp服務(wù)以及實(shí)現(xiàn)免密登錄方式
這篇文章主要介紹了Linux系統(tǒng)配置sftp服務(wù)以及實(shí)現(xiàn)免密登錄方式,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2024-06-06
Ubuntu18.04 一鍵升級(jí)Python所有第三方包 及安裝python包的方法
pip 是 Python 包管理工具,該工具提供了對(duì)Python 包的查找、下載、安裝、卸載的功能。這篇文章給大家介紹Ubuntu18.04 一鍵升級(jí)Python所有第三方包 ,感興趣的朋友一起看看吧2019-10-10
Linux下二進(jìn)制編譯安裝MySql centos7的教程
這篇文章主要介紹了Linux下二進(jìn)制編譯安裝MySql centos7的教程,本文給大家介紹的非常詳細(xì),具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2019-09-09

