/etc/rc.localと/etc/init.d/rc.localの違いは何ですか?

/etc/rc.localと/etc/init.d/rc.localの違いは何ですか?

iptables新しいルールに永続的なルールを追加したいのですVPSが、簡単なGoogle検索の後にこのルールを追加できる2つの場所が同じように見えることに気付いて驚きまし/etc/rc.local/etc/init.d/rc.local。簡単なスタートコードを置くことができる場所が2つある理由を知っている人はいますか? Linux版に固有のものです(しかし、Ubuntuには両方あります!)?それとも、そのうちの1つはもう使用されていませんか?

ベストアンサー1

/etc/init.dsysvinitとの下位互換性のために、Ubuntuで維持されています。実際に見ると、次のようなことが/etc/init.d/rc.localわかります(12.04 LTSサーバーでも同様)。

#! /bin/sh
### BEGIN INIT INFORMATION
# Provides:          rc.local
# Required-Start:    $remote_fs $syslog $all
# Required-Stop:
# Default-Start:     2 3 4 5
# Default-Stop:
# Short-Description: Run /etc/rc.local if it exist
### END INIT INFO

そして「/etc/rc.localを実行」まさにそれがすることです。全文/etc/rc.localは次のとおりです。

#!/bin/sh -e
#
# rc.local
#
# This script is executed at the end of each multiuser runlevel.
# Make sure that the script will "exit 0" on success or any other
# value on error.
#
# In order to enable or disable this script just change the execution
# bits.
#
# By default this script does nothing.

exit 0

私の考えでは、これの目的は/etc/init.d/rc.local

したがって、これは実際にはサービスであり、次のように実行できます。私は1行を追加しましたecho/etc/rc.local

»service rc.local start
hello world

しかし、私はupstartの(init.dではありません!)ディレクトリ/etc/initにあるものはそれを参照しているとは思いません。

»initctl start rc.local
initctl: Unknown job: rc.local

upstartにはいくつかの「rc」サービスがあります。

»initctl list | grep rc
rc stop/waiting
rcS stop/waiting
rc-sysinit stop/waiting

しかし、これらのどれもrc.localとは関係がないようです。

おすすめ記事