ページ

2016年8月29日

【CentOS6.8】chkconfigのレベルとinit.d/スクリプトの不思議

CentOS6 Logo

 じつは、かなり前から不思議に思っていたのですが、chkconfigでランレベルのon/offの動きちょっと?です。

CentOS6としていますがRHEL6も同じ現象です。

chkconfigのランレベル

chkconfigで制御する/etc/init.dのスクリプトのヘッダにchkcofnig: *があるとその通りにon/offしてくれるものと信じていたのですけど・・・

# chkconfig: 2345 85 15
# description: test.

chkconfig: 345の動き

コマンド行のchkconfig: 2345と書いた場合にはわからないんですけど、chkconfig: 345と書くと違いが出ます。

# chkconfig: 345 85 15
# description: test

addした時は、ランレベル345でonになります。

# chkconfig --add test
# chkconfig --list test
test     0:off  1:off  2:off  3:on   4:on   5:on   6:off

ところが、chkconfig test onしたりchkconfig off test/ chkconfig test onなどをするとランレベル:2345がonになっちゃいます。

# chkconfig test off
# chkconfig test on 
# chkconfig --list test
test     0:off  1:off  2:on   3:on   4:on   5:on   6:off

その後は、on/offの制御は2345でしか出来ません。

add/delすれば345だけでonにすることは出来ますが・・・

 # chkconfig --del test
 # chkconfig --add test
 # chkconfig --list test
 test     0:off  1:off  2:off  3:on   4:on   5:on   6:off

となりますけど、これってなんか変じゃない?

chkconfig: - 85 15

この場合、chkconfig -add testした場合には全てのランレベルでoffのままです。

# chkconfig test on
# chkconfig --list test
test     0:off  1:off  2:on   3:on   4:on   5:on   6:off

まとめ、結論

 スクリプトヘッダのchkconfig: ** *(ランレベルの部分)は、–addした時だけ有効ってことで!

まあ、chkconfigはCentOS6/RHEL6までで終わりだしだんだんCentOS7/RHEL7を使う事のほうが多くなってきましたので、いいっちゃ良いんですけど・・・

たまに古いOS使うと忘れてて・・・ねぇ。