赞
踩
现在我会两种方式开机自启:
1. /etc/rc.local
- (base) [jianming_ge@localhost ~]$ cat /etc/rc.local
- #!/bin/bash
- # THIS FILE IS ADDED FOR COMPATIBILITY PURPOSES
- #
- # It is highly advisable to create own systemd services or udev rules
- # to run scripts during boot instead of using this file.
- #
- # In contrast to previous versions due to parallel execution during boot
- # this script will NOT be run after all other services.
- #
- # Please note that you must run 'chmod +x /etc/rc.d/rc.local' to ensure
- # that this script will be executed during boot.
-
- touch /var/lock/subsys/local
- sh /home/jianming_ge/jm_chongli/chongli4_flask/start_43115.sh &
sh /home/jianming_ge/jm_chongli/chongli4_flask/start_43115.sh &
这就是开机自启最终的命令了。
看下start_43115.sh 下干了什么
-
- (base) [jianming_ge@localhost ~]$ cat /home/jianming_ge/jm_chongli/chongli4_flask/start_43115.sh
- cd /home/jianming_ge/jm_chongli/chongli4_flask
- nohup /home/jianming_ge/miniconda3/bin/gunicorn app:app -c gunicorn_chongli_kevin.py >> flask.log 2>&1 &
修改完成后,不要忘了修改可执行的权限
chmod +x /etc/rc.local
然而,可能是有问题了,因为这种方式是以root用户执行命令,但是它可能没有jianming下面的安装的python环境之类的,所以切换一下用户喽
su - jianming_ge -c "sh /home/jianming_ge/jm_chongli/chongli4_flask/start_43115.sh &"
2. crontab, 没想到把,crontab的方式也可以开机自启
crontab -e 编辑定时任务,@reboot表示重启的时候只执行一次。
具体@的含义查看下面的博文
crontab 的写法(@reboot, @yearly...) - 齐天_大圣 - 博客园
@reboot sh /root/workplace/shapan_alg/start_all_project_130.sh
同理,我们看下start_all_project_130.sh 中干了些什么?
- (base) [root@localhost ~]# cat workplace/shapan_alg/start_all_project_130.sh
- #!/bin/bash # 注释
- CURRENT_DIR=$(dirname $(readlink -f "$0"))
- DATE=$(date +%Y%m%d) # 注释 不然有回车换行
- work_path=$(dirname $(readlink -f $0)) # 当前绝对路径
- cd $work_path # 注释
- source ~/.bashrc # 注释
- #conda activate base # 注释 ---------------
- #conda activate py38_18 # 注释 ---------------
- conda activate py38_torch180 # 注释 ---------------
- dir=$work_path"/log" # 注释
- if [ ! -d $dir ] # 注释
- then # 注释
- mkdir $dir # 注释
- chmod 777 -R ${dir} # 注释
- fi # 注释
- # 开启手动触发报警
- sh $CURRENT_DIR/start_handle_alarm_130.sh
- echo "开启手动触发报警 success!"
- # 开启算法层服务
- sh $CURRENT_DIR/start_all_docker.sh
- echo " 开启算法层服务 docker success!"
-
- #sleep 20s
- #echo "sleep 20s end start 开启算法层服务 success!"
-
- ## 开启 5 个摄像头
- nohup python $CURRENT_DIR/stream_to_pic/stimulate_pic_multi_process.py >> log/stimulate_pic_multi_process.${DATE}.log 2>&1 &
- ### 开启摄像头抽帧 虚拟摄像头
- nohup python $CURRENT_DIR/stream_to_pic/stimulate_pic_multi_process2.py >> log/stimulate_pic_multi_process2.${DATE}.log 2>&1 &
- #sleep 20s
- echo " 摄像头拉流 success!"
-
-
- #echo "start 开启业务层服务 success!"
-
- sleep 20s
- # 开启监控摄像头监控的服务
- nohup python $CURRENT_DIR/monitor_stream/monitor_stream.py >> log/monitor_stream.${DATE}.log 2>&1 &
- echo "摄像拉流监控success!"
- # 开启业务层
- nohup python $CURRENT_DIR/01demo_thread_130/main.py >> log/01demo_thread_main.${DATE}.log 2>&1 &
- echo "开启业务层success!"(base) [root@localhost ~]#
备注:这里同时也要注意用户的问题,
我的是因为只有root一个用户 所以没问题
crontab -e -u jianming_ge 可以切换用户,编辑jianming_ge 用户下的定时任务
在某个用户下查看crontab的命令 具体我也没研究,猜测是这样的。
持续的ping,看其是否连同
ping ip -t
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。