开机自启动程序脚本(部署)

基于shell脚本的

Linux 脚本开机自启的几种方法

系统启动时需要加载的配置文件

/etc/profile、/root/.bash_profile
/etc/bashrc、/root/.bashrc
/etc/profile.d/*.sh、/etc/profile.d/lang.sh
/etc/sysconfig/i18n、/etc/rc.local(/etc/rc.d/rc.local)

一、修改开机启动文件:/etc/rc.local(或者/etc/rc.d/rc.local)

1.编辑rc.local文件
[root@localhost ~]# vi /etc/rc.local

2.修改rc.local文件,在 exit 0 前面加入以下命令。保存并退出。
/etc/init.d/mysqld start # mysql开机启动
/etc/init.d/nginx start # nginx开机启动
supervisord -c /etc/supervisor/supervisord.conf # supervisord开机启动
/bin/bash /server/scripts/test.sh >/dev/null 2>/dev/null

3.最后修改rc.local文件的执行权限
[root@localhost ~]# chmod +x /etc/rc.local
[root@localhost ~]# chmod 755 /etc/rc.local

二、自己写一个shell脚本

将写好的脚本(.sh文件)放到目录 /etc/profile.d/ 下,系统启动后就会自动执行该目录下的所有shell脚本。

脚本程序

#!/bin/bash
# detetction3d_zs为要杀死的进程名称
#echo "$1"
sudo ./detetction3d_zs

pid=`ps -ef | grep  'detetction3d_zs' | grep -v grep | grep -v bash | awk '{print $2}'`
 
echo "$pid"
 
if [ -n "$pid" ]
then
        echo "kill -9 pid:$pid"
kill -9 $pid
fi
sleep 9
echo "$pid"
#result = /home/nvidia/yolo/runs/detect/exp6
#https://ultralytics.com/assets/Arial.Unicode.ttf

conda activate p36
cd yolo
#python detect.py --weights yolov5s.pt --source /home/nvidia/Leador_storage/zs/xiaomayi/128G/test/data/video/result2last.avi
/home/nvidia/Leador_storage/zs/miniforge-pypy3/envs/p36/bin/python3 detect.py --weights yolov5s.pt --source 0

先启动了程序detetction3d_zs,然后睡眠9秒钟,再启动了yolo检测算法。

猜你喜欢

转载自blog.csdn.net/qq_39523365/article/details/129714364