ubuntu添加nginx(openresty)service服务和开机启动

栏目: 服务器 · Nginx · 发布时间: 5年前

内容简介:假设启动脚本为:/usr/local/ngx_openresty/nginx/sbin/nginx -c /etc/nginx/nginx.conf第一种方式:传统的/etc/init.d/下面的脚本新建脚本文件start.sh

假设启动脚本为:/usr/local/ngx_openresty/nginx/sbin/nginx -c /etc/nginx/nginx.conf

第一种方式:传统的/etc/init.d/下面的脚本

新建脚本文件start.sh

#!/bin/bash
/usr/local/ngx_openresty/nginx/sbin/nginx -c /etc/nginx/nginx.conf
exit 0

设置权限

sudo chmod 755 start.sh

链接到启动目录下

sudo ln pwd /start.sh -s /etc/init.d/

添加到启动项目

cd /etc/init.d/

99为优先级,越高越晚执行。。。

sudo update-rc.d start.sh defaults 99

移除开机启动项

sudo update-rc.d -f start.sh remove

第二种方式:systemd

[Unit]
Description=The NGINX HTTP and reverse proxy server

[Service]
Type=forking
ExecStartPre=/usr/local/ngx_openresty/nginx/sbin/nginx -c /etc/nginx/nginx.conf -t
ExecStart=//usr/local/ngx_openresty/nginx/sbin/nginx -c /etc/nginx/nginx.conf
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s QUIT $MAINPID
PrivateTmp=true

[Install]
WantedBy=multi-user.target

重启配置列表

systemctl daemon-reload

启动命令为

service nginx start

systemctl start nginx

systemctl start nginx.service

这个是列举所有已经存在配置文件对应的服务状态列表

systemctl list-unit-files | grep nginx

列举出具有加载状态的服务列表

systemctl --all | grep nginx

常用命令:

systemctl start nginx

systemctl start nginx.service

systemctl stop nginx

systemctl reload nginx

systemctl restart nginx

systemctl status nginx

添加为开机启动:

systemctl enable nginx.service

systemctl enable nginx

移除开机启动:

systemctl disable nginx.service

systemctl disable nginx


以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持 码农网

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

算法引论

算法引论

[美]乌迪·曼博(Udi Manber) / 黄林鹏、谢瑾奎、陆首博、等 / 电子工业出版社 / 2010-1 / 36.00元

本书是国际算法大师乌迪·曼博(Udi Manber)博士撰写的一本享有盛誉的著作。全书共分12章:第1章到第4章为介绍性内容,涉及数学归纳法、算法分析、数据结构等内容;第5章提出了与归纳证明进行类比的算法设计思想;第6章到第9章分别给出了4个领域的算法,如序列和集合的算法、图算法、几何算法、代数和数值算法;第10章涉及归约,也是第11章的序幕,而后者涉及NP完全问题;第12章则介绍了并行算法;最后......一起来看看 《算法引论》 这本书的介绍吧!

在线进制转换器
在线进制转换器

各进制数互转换器

UNIX 时间戳转换
UNIX 时间戳转换

UNIX 时间戳转换

HEX CMYK 转换工具
HEX CMYK 转换工具

HEX CMYK 互转工具