linuxnohub(后台一直执行)和开机自动启动脚本

标签:
linux开机启动后台运行nohubchkconfig |
如果是linux上跑这个php脚本的话:在项目根目录下:php
think insert
注:(这个insert是configure()方法里的$this->setName('insert'))
windows上的话:就是打开项目根目录:php think insert 就可以了,
如果想一直让当前脚本跑起来并且在后台一直运行不挂断可以使用:nohup
&
nohup php
think insert
>/dev/null 2>&1
&
setsid php think host-report > /home/www/PC-MRST-S20/MQTT.log
&
windows上的话:就是打开项目根目录:php think insert 就可以了,
如果想一直让当前脚本跑起来并且在后台一直运行不挂断可以使用:nohup
nohup
setsid php think host-report > /home/www/PC-MRST-S20/MQTT.log &
方法一
使用 /etc/rc.d/rc.local,自动启动脚本
1 #!/bin/bash 2 # THIS FILE IS ADDED FOR COMPATIBILITY PURPOSES 3 # 4 # It is highly advisable to create own systemd services or udev rules 5 # to run scripts during boot instead of using this file. 6 # 7 # In contrast to previous versions due to parallel execution during boot 8 # this script will NOT be run after all other services. 9 # 10 # Please note that you must run 'chmod +x /etc/rc.d/rc.local' to ensure 11 # that this script will be executed during boot. 12 13 touch /var/lock/subsys/local
1、授予 /etc/rc.d/rc.local 文件执行权限
命令:chmod +x /etc/rc.d/rc.local
2、在文件文件底部添加脚本
3、重启服务器,查看脚本是否启动
注意:/etc/rc.d/rc.local脚本执行,在/etc/profile之前,若/etc/rc.d/rc.local用到/etc/profile的环境变量,Shell无法执行成功
方法二
1、编辑服务脚本
2、给脚本增加可执行权限,命令:chmod a+x /etc/init.d/xxxx
3、注册xxxx服务名,命令:chkconfig
--add
1 注意执行命令:chkconfig --addxxxx 2 常常会出现 3
4 service myservice does not support chkconfig
5 我们一般在脚本开头加入下面两句就好了
6 #vim /etc/init.d/xxxx
7 添加下面两句到 #!/bin/bash 之后。 8
9 # chkconfig: 2345 10 90
10 # description: xxxx ....
11 其中2345是默认启动级别,级别有0-6共7个级别。
12 13 等级0表示:表示关机
14 15 等级1表示:单用户模式
16 17 等级2表示:无网络连接的多用户命令行模式
18 19 等级3表示:有网络连接的多用户命令行模式
20 21 等级4表示:不可用
22 23 等级5表示:带图形界面的多用户模式
24 25 等级6表示:重新启动
26 27 10是启动优先级,90是停止优先级,优先级范围是0-100,数字越大,优先级越低
配置系统启动时该脚本默认启动,命令:chkconfig xxxx
on
配置系统启动时该脚本默认关闭,命令:chkconfig xxxx off
4、列出当前的服务和他们的配置,命令:chkconfig --list
5、重启服务器,查看脚本是否启动