Nginx开机启动
前提条件:nginx已安装,默认安装路径为:/usr/local/nginx
制作服务
在/etc/systemd/system/路径下创建nginx.service文件
cd /etc/systemd/system/
vim nginx.service
编写以下内容
[Unit]
Description=nginx - high performance web server
After=nginx.service
[Service]
Type=forking
ExecStart=/usr/local/nginx/sbin/nginx
ExecReload=/usr/local/nginx/sbin/nginx -s reload
ExecStop=/usr/local/nginx/sbin/nginx -s stop
Execenable=/usr/local/nginx/sbin/nginx
[Install]
WantedBy=multi-user.target
启动关闭指令
设置开机启动 systemctl enable nginx
取消开机自启动 systemctl disable nginx
查看服务当前状态 systemctl status nginx
启动nginx服务 systemctl start nginx
停止nginx服务 systemctl stop nginx
重启nginx服务 systemctl restart nginx
开机执行shell脚本
切换到/etc/init.d目录下
cd /etc/init.d
新建shell脚本
vim test.sh
编写以下内容
#!/bin/sh
#chkconfig:2345 90 10
#description: 描述#下面写命令
cd /data/plww/wtgp/bin/ (要执行的shell脚本位置)
./start.sh (shell脚本文件名)
#chkconfig:2345 80 90
2345指定脚本运行级别,对应系统的系统初始化启动服务目录 /etc/rc.d下的rc2.d,rc3.d,rc4.d,rc5.d
80为启动序号(数字越小执行顺序越靠前0-100),例如等同于在rc2.d目录下手动创建S80service-test服务
90为关闭序号(数字越小执行顺序越靠前0-100)
3. 为新建的脚本test.sh添加可执行权限
chmod +x test.sh
将此脚本加入chkconfig命令进行管理
chkconfig --add test.sh
设置该脚本为开机自运行
chkconfig test.sh on
若要移除该自启动脚本,依次执行如下两句
chkconfig test.sh off
chkconfig --del test.sh