如何讓No-ip Clinet開機時自動啟動

安裝完No-ip之後若是要讓他完全自動啟動可是要自己寫Script的,如此一來接上電源就可以完全自己運作了,十分的方便

首先要在/etc/init.d/建立一個較noip2的檔案

sudo nano /etc/init.d/noip2

接著將以下文字複製貼上

### BEGIN INIT INFO
# Provides: noip2
# Required-Start: $remote_fs $syslog
# Required-Stop: $remote_fs $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Start daemon at boot time
# Description: Enable service provided by daemon.
### END INIT INFO
#! /bin/sh
# /etc/init.d/noip2
# Supplied by no-ip.com
# Modified for Debian GNU/Linux by Eivind L. Rygge <[email protected]>
# Updated by David Courtney to not use pidfile 130130 for Debian stable.
# . /etc/rc.d/init.d/functions # uncomment/modify for your killproc
DAEMON=/usr/local/bin/noip2
NAME=noip2
test -x $DAEMON || exit 0
case “$1” in
start)
echo -n “Starting dynamic address update: “
start-stop-daemon –start –exec $DAEMON
echo “noip2.”
;;
stop)
echo -n “Shutting down dynamic address update:”
start-stop-daemon –stop –oknodo –retry 30 –exec $DAEMON
echo “noip2.”
;;
restart)
echo -n “Restarting dynamic address update: “
start-stop-daemon –stop –oknodo –retry 30 –exec $DAEMON
start-stop-daemon –start –exec $DAEMON
echo “noip2.”
;;
*)
echo “Usage: $0 {start|stop|restart}”
exit 1
esac
exit 0

 

接著輸入

sudo chmod a+rx /etc/init.d/noip2 [讓他可被執行]
sudo update-rc.d noip2 defaults [確認可正常運行]

 

>>>碎碎念<<<
說實在的上面那行真的弄很久,網路上查到的方法都是不正確的代碼,不然就是有缺,問了身邊的人都沒人懂最後用了半天才弄懂….

如果有人跟我一樣sudo update-rc.d noip2 defaults一直出現問題
例如

insserv: warning: current stop runlevel(s) (1 6) of script `noip2′ overwrites defaults (0 1 6 ).

然後你把1 6 改成0 1 6結果錯誤資訊會倒過來,恭喜你跟我一樣進入無限錯誤loop###
為了解決這個花了超久時間…
可參考:https://wiki.debian.org/LSBInitScripts
請先輸入

sudo insserv -r noip2

之後nano noip2確認default start有沒有設定錯誤(我本身附上的script是已經調整過了應該不會遇到)
之後再進行

sudo update-rc.d noip2 defaults

PS. config設定檔refresh時間記得調短一點,不然測試的時候你會等到崩潰#
參考汁尿

http://goo.gl/8vX8Yu
https://goo.gl/KixZCK