当前位置:   article > 正文

linux 设置开机自启_@reboot

@reboot

现在我会两种方式开机自启:

1. /etc/rc.local

  1. (base) [jianming_ge@localhost ~]$ cat /etc/rc.local
  2. #!/bin/bash
  3. # THIS FILE IS ADDED FOR COMPATIBILITY PURPOSES
  4. #
  5. # It is highly advisable to create own systemd services or udev rules
  6. # to run scripts during boot instead of using this file.
  7. #
  8. # In contrast to previous versions due to parallel execution during boot
  9. # this script will NOT be run after all other services.
  10. #
  11. # Please note that you must run 'chmod +x /etc/rc.d/rc.local' to ensure
  12. # that this script will be executed during boot.
  13. touch /var/lock/subsys/local
  14. 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 下干了什么

  1. (base) [jianming_ge@localhost ~]$ cat /home/jianming_ge/jm_chongli/chongli4_flask/start_43115.sh
  2. cd /home/jianming_ge/jm_chongli/chongli4_flask
  3. 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 中干了些什么?
 

  1. (base) [root@localhost ~]# cat workplace/shapan_alg/start_all_project_130.sh
  2. #!/bin/bash # 注释
  3. CURRENT_DIR=$(dirname $(readlink -f "$0"))
  4. DATE=$(date +%Y%m%d) # 注释 不然有回车换行
  5. work_path=$(dirname $(readlink -f $0)) # 当前绝对路径
  6. cd $work_path # 注释
  7. source ~/.bashrc # 注释
  8. #conda activate base # 注释 ---------------
  9. #conda activate py38_18 # 注释 ---------------
  10. conda activate py38_torch180 # 注释 ---------------
  11. dir=$work_path"/log" # 注释
  12. if [ ! -d $dir ] # 注释
  13. then # 注释
  14. mkdir $dir # 注释
  15. chmod 777 -R ${dir} # 注释
  16. fi # 注释
  17. # 开启手动触发报警
  18. sh $CURRENT_DIR/start_handle_alarm_130.sh
  19. echo "开启手动触发报警 success!"
  20. # 开启算法层服务
  21. sh $CURRENT_DIR/start_all_docker.sh
  22. echo " 开启算法层服务 docker success!"
  23. #sleep 20s
  24. #echo "sleep 20s end start 开启算法层服务 success!"
  25. ## 开启 5 个摄像头
  26. nohup python $CURRENT_DIR/stream_to_pic/stimulate_pic_multi_process.py >> log/stimulate_pic_multi_process.${DATE}.log 2>&1 &
  27. ### 开启摄像头抽帧 虚拟摄像头
  28. nohup python $CURRENT_DIR/stream_to_pic/stimulate_pic_multi_process2.py >> log/stimulate_pic_multi_process2.${DATE}.log 2>&1 &
  29. #sleep 20s
  30. echo " 摄像头拉流 success!"
  31. #echo "start 开启业务层服务 success!"
  32. sleep 20s
  33. # 开启监控摄像头监控的服务
  34. nohup python $CURRENT_DIR/monitor_stream/monitor_stream.py >> log/monitor_stream.${DATE}.log 2>&1 &
  35. echo "摄像拉流监控success!"
  36. # 开启业务层
  37. nohup python $CURRENT_DIR/01demo_thread_130/main.py >> log/01demo_thread_main.${DATE}.log 2>&1 &
  38. echo "开启业务层success!"(base) [root@localhost ~]#

备注:这里同时也要注意用户的问题,

我的是因为只有root一个用户 所以没问题

crontab -e -u jianming_ge 可以切换用户,编辑jianming_ge 用户下的定时任务

在某个用户下查看crontab的命令 具体我也没研究,猜测是这样的。

持续的ping,看其是否连同

ping ip -t

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/不正经/article/detail/72977
推荐阅读
相关标签
  

闽ICP备14008679号