linux添加自定義service服務(wù),開機(jī)自啟動方式
更新時間:2024年08月08日 15:21:31 作者:千年恨
這篇文章主要介紹了linux添加自定義service服務(wù),開機(jī)自啟動方式,具有很好的參考價值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教
自己的服務(wù)開機(jī)自啟動
第一步:準(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)境變量, 不需要則置為空 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
第二步:啟動服務(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 ### 啟動 systemctl enable xxx.service 加入開機(jī)自啟動 systemctl disable xxx.service 移除開機(jī)自啟動 systemctl start xxx.service 啟動 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
滾動形式
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
滾動形式查看日志占用的磁盤空間
journalctl --disk-usage
總結(jié)
以上為個人經(jīng)驗(yàn),希望能給大家一個參考,也希望大家多多支持腳本之家。
相關(guān)文章
Linux IO多路復(fù)用之epoll網(wǎng)絡(luò)編程
今天小編就為大家分享一篇關(guān)于Linux IO多路復(fù)用之epoll網(wǎng)絡(luò)編程,小編覺得內(nèi)容挺不錯的,現(xiàn)在分享給大家,具有很好的參考價值,需要的朋友一起跟隨小編來看看吧2018-12-12阿里云基于CentOS用vsftpd搭建FTP服務(wù)器
這篇文章主要介紹了阿里云CentOS系統(tǒng)yum方式安裝vsftpd的相關(guān)資料,最近想要了解的朋友可以了解一下。2016-10-10CentOS虛擬機(jī)克隆后無法上網(wǎng)(網(wǎng)卡信息不一致)問題的解決方法
這篇文章主要為大家詳細(xì)介紹了CentOS虛擬機(jī)克隆后無法上網(wǎng),即網(wǎng)卡信息不一致問題的解決方法,具有一定的參考價值,感興趣的小伙伴們可以參考一下2017-04-04