linux 自定义程序开机自启

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

  • /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. 保存、退出。重启系统即可
此时此刻,非我莫属
原文地址:https://www.cnblogs.com/taozhengquan/p/15406428.html