ubuntu16之后甩鳄,系統(tǒng)改成了用systemd來管理服務铜犬,systemd的主要命令是systemctl胶坠。
一. 常用命令的使用
sshd服務為例:
查找自啟服務
$ sudo systemctl list-unit-files | grep enabled
開機自啟
$ sudo systemctl enable sshd
禁止開機自啟
$ sudo systemctl disable sshd
停止服務
$ systemctl stop sshd
啟動服務
$ systemctl start sshd
檢查某個服務的狀態(tài)
$ systemctl status sshd
可以用上面的方法找出和關閉一些不用的服務啼染,如藍牙bluetooth座柱,網絡打印服務cups.service,cups-browsed.service.
二. 配置自啟動服務
配置文件主要放在/usr/lib/systemd/system目錄输吏,也可能在/etc/systemd/system目錄权旷,在該目錄下新建一個文件(如hello.serivce)并修改其內容。
[Unit]
Description=this is hello service
[Service]
Type=simple
ExecStart= <shell command>
ExecStop=<shell command>
[Install]
WantedBy=multi-user.target
主要是在ExecStart和ExecStop中寫啟動和停止服務的shell命令贯溅,ExecStop可缺省拄氯。
配置完成后,reload一下systemd
$ sudo systemctl daemon-reload
然后即可通過systemctl的命令來啟動和停止服務它浅,及實現(xiàn)開機自啟译柏。
具體內容及做法可參考文章:
http://www.ruanyifeng.com/blog/2016/03/systemd-tutorial-part-two.html