Linux开机运行nginx、shelll脚本

Nginx开机启动

前提条件:nginx已安装,默认安装路径为:/usr/local/nginx

  1. 制作服务 在/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
  1. 启动关闭指令
设置开机启动     systemctl enable nginx
取消开机自启动   systemctl disable nginx
查看服务当前状态   systemctl status nginx
启动nginx服务   systemctl start nginx
停止nginx服务   systemctl stop nginx
重启nginx服务   systemctl restart nginx

开机执行shell脚本

  1. 切换到/etc/init.d目录下
cd /etc/init.d
  1. 新建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
  1. 将此脚本加入chkconfig命令进行管理
chkconfig --add test.sh
  1. 设置该脚本为开机自运行
chkconfig test.sh on
  1. 若要移除该自启动脚本,依次执行如下两句
chkconfig test.sh off
chkconfig --del test.sh
  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值