【LIVA】【Ubuntu server14.04】シェルスクリプト自動実行登録

現在iptablesを構築中なわけですが、とりあえず作ったシェルをサーバ再起動時に自動実行できるように登録します。

$sudo chmod 755 iptables.sh

$sudo chown root iptables.sh

$sudo chgrp root iptables.sh

$sudo mv iptables.sh /etc/init.d

$cd /etc/init.d/

$sudo update-rc.d  iptables.sh defaults

update-rc.d: warning: /etc/init.d/iptables.sh missing LSB information
update-rc.d: see http://wiki.debian.org/LSBInitScripts
Adding system startup for /etc/init.d/iptables.sh ...
/etc/rc0.d/K20iptables.sh -> ../init.d/iptables.sh
/etc/rc1.d/K20iptables.sh -> ../init.d/iptables.sh
/etc/rc6.d/K20iptables.sh -> ../init.d/iptables.sh
/etc/rc2.d/S20iptables.sh -> ../init.d/iptables.sh
/etc/rc3.d/S20iptables.sh -> ../init.d/iptables.sh
/etc/rc4.d/S20iptables.sh -> ../init.d/iptables.sh
/etc/rc5.d/S20iptables.sh -> ../init.d/iptables.sh

前半から中盤のコマンドは実行権限をつけたり、ファイルユーザをrootにしたり。

update-rc.dを実行するとwarningが出たけど、とりあえず気にしない・・・

これでリブートすればiptabelsが自動で設定される。

 

【2014/10/31 追記】

自動実行の削除は以下のとおり。

$sudo update-rc.d -f  iptables.sh remove
 Removing any system startup links for /etc/init.d/iptables.sh ...
   /etc/rc0.d/K20iptables.sh
   /etc/rc1.d/K20iptables.sh
   /etc/rc2.d/S20iptables.sh
   /etc/rc3.d/S20iptables.sh
   /etc/rc4.d/S20iptables.sh
   /etc/rc5.d/S20iptables.sh
   /etc/rc6.d/K20iptables.sh

 

自動実行登録の確認は以下のとおり

$ ls /etc/rc2.d 

 ここで出力されていれば自動実行になる。出力されていなければ自動実行しない。

また、頭文字がKであれば停止用、Sであれば起動用になってる。