ubuntu16之后,系统改成了用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
检查某个服务的状态
$ 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的命令来启动和停止服务,及实现开机自启。
具体内容及做法可参考文章:
http://www.ruanyifeng.com/blog/2016/03/systemd-tutorial-part-two.html
网友评论