实现开机自启常见的有两种方法:

  • /etc/init.d/下编写脚本命令(有些机子会有问题,比较麻烦)

  • 利用定时任务crontab

本文介绍crontab现实程序开机自启

  1. 编写执行脚本run.sh
#!/bin/sh
# 我这里的脚本跑了两个uwsgi程序、和一个python程序
/usr/local/bin/uwsgi -i /root/you-project-client-api/uwsgi.ini;
/usr/local/bin/uwsgi -i /root/you-project-admin-api/uwsgi.ini;
python3 test.py
  1. 命令行输入crontab -e。进入crontab命令编辑模式
crontab -e
  1. crontab中加入下面
# 开机60秒后自动执行/etc/rcS.d/run.sh里面的脚本。 /etc/rcS.d/run.sh(这个是你脚本文件路径)
@reboot sleep 60; bash /etc/rcS.d/run.sh
  1. 保存、退出。重启系统即可

相关文章:

  • 2022-12-23
  • 2021-05-02
  • 2022-01-27
  • 2021-08-24
  • 2021-08-26
  • 2021-07-31
  • 2021-11-28
  • 2022-01-19
猜你喜欢
  • 2021-11-14
  • 2021-07-17
  • 2022-12-23
  • 2021-05-29
  • 2021-11-12
  • 2021-12-14
  • 2022-12-23
相关资源
相似解决方案