**
今天在使用openwrt時,需要將scp到上面的程式設定為開機自動啟動。按照linux下設定自動啟動的方法並不有效。後來在官方wiki下發現了介紹文章,具體可見openwrt下
1. 在/etc/init.d/中按照以下格式編寫shell指令碼
1234567
891011
1213
#!/bin/sh /etc/rc.commonstart=99
stop=15
start()
stop()
以上便是乙份在自啟動的shell指令碼模板。在start方法中寫入執行程式的命令,而stop方法中寫入終止程式執行的命令即可。在上面的**中,第一行稱為shebang line,它使用/etc/rc.common指令碼作為包裝器。第二行和第三行的start=99, stop=15指的是優先順序,優先順序的指令碼會先執行。數字越大,優先順序越低。
2. 當前僅有上面的指令碼是不夠的。我們還需要以下的命令
1)使用chmod命令將指令碼變為可執行指令碼:chmod +x ***
2) 使用*** enable使得指令碼開機自啟動。其中,***為前面編寫的指令碼檔名。
*** enable的命令實質上是為指令碼檔案建立乙個軟鏈結,軟鏈結存放於/etc/rc.d/下,如果我們不想使用rc.common的enable命令也可以,我們可以自己建立鏈結。
3)通過以上的步驟就可以建立程式自啟動指令碼,將程式設定為自啟動。
3. 另外,如果在開機boot期間,需要執行程式,我們可以使用boot方法。使用方法類似於start方法和stop方法。
Linux下設定Redis開機自啟
1 設定redis.conf 中daemonize 為yes 確保守護程序開啟。2 vi etc init.d redis 內容如下,然後儲存退出。chkconfig 2345 10 90 description start and stop redis path usr local bin sbi...
Linux下設定Nginx開機自啟
1 本地環境 root dev cat etc redhat release centos linux release 7.5.1804 core 2 在 etc init.d建立nginx檔案,並新增如下內容 root dev vim etc init.d nginx指令碼內容如下 esac3 儲...
設定openwrt應用程式開機和崩潰時自動啟動
設定openwrt應用程式開機和崩潰時自動啟動 在 etc init.d 中新增helloworld啟動指令碼,內容如下 bin sh etc rc.common start 90 use procd 1 prog helloworld helloworld start service 這是乙個最簡...