Linux设置开机自启动的三种方式

1,547次阅读
没有评论

Linux设置开机启动的三种方法

方法一 添加命令

编辑文件 /etc/rc.local

vim /ect/rc.local

复制

/ect/rc.local和/ect/rc.d/rc.local是软链接关系

chmod +x /ect/rc.d/rc.local

复制

方法二 添加脚本

自己写一个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
正文完
可以使用微信扫码关注公众号(ID:xzluomor)
post-qrcode
 0
评论(没有评论)

文心AIGC

2024 年 2 月
 1234
567891011
12131415161718
19202122232425
26272829  
文心AIGC
文心AIGC
人工智能ChatGPT,AIGC指利用人工智能技术来生成内容,其中包括文字、语音、代码、图像、视频、机器人动作等等。被认为是继PGC、UGC之后的新型内容创作方式。AIGC作为元宇宙的新方向,近几年迭代速度呈现指数级爆发,谷歌、Meta、百度等平台型巨头持续布局
文章搜索
热门文章
手把手教你用AI 10分钟生成一个APP!零基础也能搞定

手把手教你用AI 10分钟生成一个APP!零基础也能搞定

今日,我将向大家展示DeepSeek的全新玩法——从零开始,利用AI创建一个完整的应用程序。借助DeepSee...
最新评论
ufabet ufabet มีเกมให้เลือกเล่นมากมาย: เกมเดิมพันหลากหลาย ครบทุกค่ายดัง
tornado crypto mixer tornado crypto mixer Discover the power of privacy with TornadoCash! Learn how this decentralized mixer ensures your transactions remain confidential.
ดูบอลสด ดูบอลสด Very well presented. Every quote was awesome and thanks for sharing the content. Keep sharing and keep motivating others.
ดูบอลสด ดูบอลสด Pretty! This has been a really wonderful post. Many thanks for providing these details.
ดูบอลสด ดูบอลสด Pretty! This has been a really wonderful post. Many thanks for providing these details.
ดูบอลสด ดูบอลสด Hi there to all, for the reason that I am genuinely keen of reading this website’s post to be updated on a regular basis. It carries pleasant stuff.
Obrazy Sztuka Nowoczesna Obrazy Sztuka Nowoczesna Thank you for this wonderful contribution to the topic. Your ability to explain complex ideas simply is admirable.
ufabet ufabet Hi there to all, for the reason that I am genuinely keen of reading this website’s post to be updated on a regular basis. It carries pleasant stuff.
ufabet ufabet You’re so awesome! I don’t believe I have read a single thing like that before. So great to find someone with some original thoughts on this topic. Really.. thank you for starting this up. This website is something that is needed on the internet, someone with a little originality!
ufabet ufabet Very well presented. Every quote was awesome and thanks for sharing the content. Keep sharing and keep motivating others.
热评文章
手把手教你用AI 10分钟生成一个APP!零基础也能搞定

手把手教你用AI 10分钟生成一个APP!零基础也能搞定

今日,我将向大家展示DeepSeek的全新玩法——从零开始,利用AI创建一个完整的应用程序。借助DeepSee...