在折騰樹莓派的過程當中,參考教程,也搭建了幾個服務,由於有時會有開關機的須要,因此,很多服務都須要從新開啓,是否是有更好的方式來實現開機啓動呢,因而google找了幾篇教程,也嘗試了幾種方式,終於找到了適合的方式來管理服務了。html
網上不少使用的是 在 /etc/rc.local 中添加開啓語句 或者是在 /etc/init.d 中添加shell腳本,在操做的過程當中發現使用不是很友好, 難道沒有統一的標準來進行方便管理的工具嗎?linux
ps 根據運行級別的不一樣,系統會運行rc0.d到rc6.d中的相應的腳本程序,來完成相應的初始化工做和啓動相應的服務。而 rc0.d~rc6.d 中的文件 均是來自/etc/init.d 文件的軟鏈,當加載完成後 加載 /etc/rc.local (用戶自定義配置)
shell
在CentOS 7 和 Ubuntu 15 中 開始加入 Systemd 做爲系統的啓動和管理的優先解決方案。工具
配置文件主要放在/usr/lib/systemd/system目錄中 主要是用戶定義的啓動google
/lib/systemd/system 則存放系統級別的啓動任務.net
/etc/systemd/system 中存了一些放前者的軟鏈rest
[Unit] Description=aria2 After=network.target [Service] ExecStart= /home/user/tool/aria2/aria2c --conf-path=/home/user/tool/aria2c/aria2.conf ExecStop=/bin/kill $MAINPID RestartSec=5s Restart=on-failure [Install] WantedBy=multi-user.target
sudo systemctl enable aria2 # 設置開機啓動 sudo systemctl start aria2 # 啓動服務 sudo systemctl status aria2 # 查看服務狀態 sudo systemctl stop aria2 # 中止服務 sudo systemctl restart aria2 # 重啓服務 sudo systemctl kill aria2 # 殺死進程
參考連接:code