實現開機自啟常見的有兩種方法:
-
/etc/init.d/
下編寫腳本命令(有些機子會有問題,比較麻煩) -
利用定時任務
crontab
本文介紹crontab現實程序開機自啟
- 編寫執行腳本
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
- 命令行輸入
crontab -e
。進入crontab
命令編輯模式
crontab -e
- 在
crontab
中加入下面
# 開機60秒后自動執行/etc/rcS.d/run.sh里面的腳本。 /etc/rcS.d/run.sh(這個是你腳本文件路徑)
@reboot sleep 60; bash /etc/rcS.d/run.sh
- 保存、退出。重啟系統即可