我的博客
欢迎来到我的博客
bunny.icu

使用systemd创建自定义服务

使用systemd创建自定义服务

使用systemd创建自定义服务

安装systemd

yum install -y systemd

这里以nginx为例创建自定义服务

创建nginx服务

vim /etc/systemd/system/nginx.service

.service前面的就是服务名称

[Unit]
Description=nginx
After=network.target

[Service]
Type=forking
ExecStart=/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
ExecReload=/usr/local/nginx/sbin/nginx -s reload -c /usr/local/nginx/conf/nginx.conf
ExecStop=/usr/local/nginx/sbin/nginx -s stop
PrivateTmp=true

[Install]
WantedBy=multi-user.target

之后,就可以使用下面这些命令

# 设置开机启动
systemctl enable nginx

systemctl start nginx
systemctl stop nginx
systemctl restart nginx
systemctl status nginx

Reference

ginx -s stop and -s quit 有什么区别? – CSDN
Systemd 添加自定义服务(开机自启动) -博客园
[Linux]如何给Nginx添加服务 – 简书

版权声明


本作品系原创, 转载须遵循 CC BY-NC-ND 4.0 许可协议
本文标题:使用systemd创建自定义服务
本文链接:https://www.bunny.icu/archives/1567

推荐文章

NotFlyLoong进行回复 取消回复

textsms
account_circle
email

bunny.icu

使用systemd创建自定义服务
使用systemd创建自定义服务 安装systemd yum install -y systemd 这里以nginx为例创建自定义服务 创建nginx服务 vim /etc/systemd/system/nginx.service .service前面的就是服务…
扫描二维码继续阅读
2022-10-04