systemd添加自定义系统服务设置自定义开机启动的方法

2019-10-13 12:39:33王振洲

RemainAfterExit:如果设置这个选择为真,服务会被认为是在激活状态,即使所以的进程已经退出,默认的值为假,这个选项只有在Type=oneshot时需要被配置。

[Install]

Alias:为单元提供一个空间分离的附加名字。

RequiredBy:单元被允许运行需要的一系列依赖单元,RequiredBy列表从Require获得依赖信息。

WantBy:单元被允许运行需要的弱依赖性单元,Wantby从Want列表获得依赖信息。

Also:指出和单元一起安装或者被协助的单元。

DefaultInstance:实例单元的限制,这个选项指定如果单元被允许运行默认的实例。

3.重载服务

systemctl enable nginx.service

就会在/etc/systemd/system/multi-user.target.wants/目录下新建一个/usr/lib/systemd/system/nginx.service 文件的链接。

4.操作服务

#启动服务
$ sudo systemctl start nginx.service
 
#查看日志
$ sudo journalctl -f -u nginx.service
— Logs begin at 四 2015-06-25 17:32:20 CST. —
6月 25 10:28:24 Leco.lan systemd[1]: Starting nginx – high performance web server…
6月 25 10:28:24 Leco.lan nginx[7976]: nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
6月 25 10:28:24 Leco.lan nginx[7976]: nginx: configuration file /etc/nginx/nginx.conf test is successful
6月 25 10:28:24 Leco.lan systemd[1]: Started nginx – high performance web server.
 
#重启
$ sudo systemctl restart nginx.service
 
#重载
$ sudo systemctl reload nginx.service
 
#停止
$ sudo systemctl stop nginx.service

以上就是小编为大家带来的systemd添加自定义系统服务设置自定义开机启动的方法全部内容了,希望大家多多支持易采站长站~