Linux设置开机启动的三种方式 |
您所在的位置:网站首页 › clashlinux使用方法 › Linux设置开机启动的三种方式 |
开机启动三种方法方式一 添加命令 编辑文件 /etc/rc.local vi /etc/rc.local在文件末尾加上你开机需要执行的命令即可(写绝对路径,添加到系统环境变量的除外),如: nohup /usr/local/srs2/objs/srs -c /usr/local/srs2/conf/z.conf>/usr/local/srs2/log.txt &方式二 添加脚本自己写一个shell脚本 将写好的脚本(.sh文件)放到目录 /etc/profile.d/ 下,系统启动后就会自动执行该目录下的所有shell脚本。 cd /etc/profile.d/添加脚本srs.sh #!/bin/sh cd /usr/local/srs2 nohup ./objs/srs -c conf/z.conf>./log.txt &方式三 添加服务添加文件新建/etc/init.d/srs.sh 文件 #!/bin/sh # chkconfig: 2345 85 15 # description:auto_run #程序根位置 MY_ROOT=/usr/local/srs2/ #运行程序位置 MY_PATH="${MY_ROOT}objs/srs" #LOG位置 LOG_PATH="$MY_ROOT"log.txt #开始方法 start() { cd $MY_ROOT nohup $MY_PATH -c conf/z.conf>$LOG_PATH & echo "$MY_PATH start success." } #结束方法 stop() { kill -9 `ps -ef|grep $MY_PATH|grep -v grep|grep -v stop|awk '{print $2}'` echo "$MY_PATH stop success." } case "$1" in start) start ;; stop) stop ;; restart) stop start ;; *) echo "Userage: $0 {start|stop|restart}" exit 1 esac添加执行权限给sh文件和jar可执行权限 chmod +x /etc/init.d/srs.sh设置开机启动首先,添加为系统服务 chkconfig --add srs.sh开机自启动 chkconfig srs.sh on查看 chkconfig --list启动 service srs.sh start停用 service srs.sh stop查看启动情况 lsof -i:1935 |
今日新闻 |
推荐新闻 |
CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3 |