Jika saya memberi tahu sistem saya untuk menjalankan level 3 apakah itu berarti sistem pertama kali berjalan melalui run level 0, 1, 2, dan akhirnya berjalan melalui run level 3?
Saya pikir jawaban untuk pertanyaan ini adalah ya. Tetapi ketika saya melihat pada sistem RHEL 6 saya, saya melihat bahwa banyak direktori rcX.d berisi tautan simbolik yang sama.
Di /etc/rc.d/rc0.d/ Saya
[[email protected] rc.d]# ls -lah /etc/rc.d/rc0.d/
total 8.0K
drwxr-xr-x. 2 root root 4.0K Jun 27 11:59 .
drwxr-xr-x. 10 root root 4.0K Jul 9 15:06 ..
lrwxrwxrwx. 1 root root 13 Jun 12 13:02 K05atd -> ../init.d/atd
lrwxrwxrwx. 1 root root 14 Jun 12 13:01 K10cups -> ../init.d/cups
lrwxrwxrwx. 1 root root 19 Jun 12 10:57 K10saslauthd -> ../init.d/saslauthd
lrwxrwxrwx. 1 root root 18 Jun 12 12:51 K15svnserve -> ../init.d/svnserve
lrwxrwxrwx. 1 root root 14 Jun 12 10:58 K25sshd -> ../init.d/sshd
lrwxrwxrwx. 1 root root 17 Jun 12 10:57 K30postfix -> ../init.d/postfix
lrwxrwxrwx. 1 root root 17 Jun 12 12:26 K50dnsmasq -> ../init.d/dnsmasq
lrwxrwxrwx. 1 root root 20 Jun 12 10:57 K50netconsole -> ../init.d/netconsole
lrwxrwxrwx. 1 root root 15 Jun 12 10:57 K60crond -> ../init.d/crond
lrwxrwxrwx. 1 root root 25 Jun 27 11:59 K65vboxadd-service -> ../init.d/vboxadd-service
lrwxrwxrwx. 1 root root 17 Jun 27 11:58 K70vboxadd -> ../init.d/vboxadd
lrwxrwxrwx. 1 root root 21 Jun 27 11:59 K70vboxadd-x11 -> ../init.d/vboxadd-x11
lrwxrwxrwx. 1 root root 17 Jun 12 12:26 K73winbind -> ../init.d/winbind
lrwxrwxrwx. 1 root root 19 Jun 12 12:26 K74haldaemon -> ../init.d/haldaemon
lrwxrwxrwx. 1 root root 26 Jun 12 10:58 K75blk-availability -> ../init.d/blk-availability
lrwxrwxrwx. 1 root root 15 Jun 12 11:15 K75netfs -> ../init.d/netfs
lrwxrwxrwx. 1 root root 19 Jun 12 10:57 K75udev-post -> ../init.d/udev-post
lrwxrwxrwx. 1 root root 24 Jun 12 12:26 K84NetworkManager -> ../init.d/NetworkManager
lrwxrwxrwx. 1 root root 24 Jun 27 11:59 K84wpa_supplicant -> ../init.d/wpa_supplicant
lrwxrwxrwx. 1 root root 19 Jun 12 10:58 K85mdmonitor -> ../init.d/mdmonitor
lrwxrwxrwx. 1 root root 20 Jun 12 12:25 K85messagebus -> ../init.d/messagebus
lrwxrwxrwx. 1 root root 20 Jun 12 10:58 K87multipathd -> ../init.d/multipathd
lrwxrwxrwx. 1 root root 21 Jun 12 10:57 K87restorecond -> ../init.d/restorecond
lrwxrwxrwx. 1 root root 16 Jun 12 10:58 K88auditd -> ../init.d/auditd
lrwxrwxrwx. 1 root root 15 Jun 27 11:59 K88iscsi -> ../init.d/iscsi
lrwxrwxrwx. 1 root root 17 Jun 12 10:57 K88rsyslog -> ../init.d/rsyslog
lrwxrwxrwx. 1 root root 16 Jun 12 10:58 K89iscsid -> ../init.d/iscsid
lrwxrwxrwx. 1 root root 21 Jun 12 13:01 K89portreserve -> ../init.d/portreserve
lrwxrwxrwx. 1 root root 15 Jun 12 11:15 K89rdisc -> ../init.d/rdisc
lrwxrwxrwx. 1 root root 17 Jun 12 11:15 K90network -> ../init.d/network
lrwxrwxrwx. 1 root root 19 Jun 12 10:57 K92ip6tables -> ../init.d/ip6tables
lrwxrwxrwx. 1 root root 18 Jun 12 10:57 K92iptables -> ../init.d/iptables
lrwxrwxrwx. 1 root root 22 Jun 12 10:58 K99lvm2-monitor -> ../init.d/lvm2-monitor
lrwxrwxrwx. 1 root root 17 Jun 12 11:15 S00killall -> ../init.d/killall
lrwxrwxrwx. 1 root root 14 Jun 12 11:15 S01halt -> ../init.d/halt
lrwxrwxrwx. 1 root root 15 Jun 26 12:32 S95jexec -> ../init.d/jexec
Dan di /etc/rc.d/rc1.d/ Saya melihat kumpulan tautan simbolik yang sama seperti di rc0.d plus tautan tambahan. Ini tampaknya menunjukkan bahwa direktori rc0.d, rc1.d independen dan untuk menjalankan level 1 itu tidak mengeksekusi hal-hal di run level 0. Yang berarti bahwa hal-hal buruk dapat terjadi jika beberapa bagaimana tautan simbolik di rc0 .d tidak persis direplikasi di rc1.d, … dll.
Jadi bagaimana cara kerjanya? Apakah itu hanya memindai file dalam direktori rc.X tertentu atau menjalankan semua direktori rc.X yang memiliki level lebih rendah dari level rc yang diteruskan ke init?
[ro[email protected] rc.d]# ls -lah /etc/rc.d/rc1.d/
total 8.0K
drwxr-xr-x. 2 root root 4.0K Jun 27 11:59 .
drwxr-xr-x. 10 root root 4.0K Jul 9 15:06 ..
lrwxrwxrwx. 1 root root 13 Jun 12 13:02 K05atd -> ../init.d/atd
lrwxrwxrwx. 1 root root 14 Jun 12 13:01 K10cups -> ../init.d/cups
lrwxrwxrwx. 1 root root 19 Jun 12 10:57 K10saslauthd -> ../init.d/saslauthd
lrwxrwxrwx. 1 root root 18 Jun 12 12:51 K15svnserve -> ../init.d/svnserve
lrwxrwxrwx. 1 root root 14 Jun 12 10:58 K25sshd -> ../init.d/sshd
lrwxrwxrwx. 1 root root 17 Jun 12 10:57 K30postfix -> ../init.d/postfix
lrwxrwxrwx. 1 root root 17 Jun 12 12:26 K50dnsmasq -> ../init.d/dnsmasq
lrwxrwxrwx. 1 root root 20 Jun 12 10:57 K50netconsole -> ../init.d/netconsole
lrwxrwxrwx. 1 root root 15 Jun 12 10:57 K60crond -> ../init.d/crond
lrwxrwxrwx. 1 root root 25 Jun 27 11:59 K65vboxadd-service -> ../init.d/vboxadd-service
lrwxrwxrwx. 1 root root 17 Jun 27 11:58 K70vboxadd -> ../init.d/vboxadd
lrwxrwxrwx. 1 root root 21 Jun 27 11:59 K70vboxadd-x11 -> ../init.d/vboxadd-x11
lrwxrwxrwx. 1 root root 17 Jun 12 12:26 K73winbind -> ../init.d/winbind
lrwxrwxrwx. 1 root root 19 Jun 12 12:26 K74haldaemon -> ../init.d/haldaemon
lrwxrwxrwx. 1 root root 15 Jun 12 11:15 K75netfs -> ../init.d/netfs
lrwxrwxrwx. 1 root root 24 Jun 12 12:26 K84NetworkManager -> ../init.d/NetworkManager
lrwxrwxrwx. 1 root root 24 Jun 27 11:59 K84wpa_supplicant -> ../init.d/wpa_supplicant
lrwxrwxrwx. 1 root root 19 Jun 12 10:58 K85mdmonitor -> ../init.d/mdmonitor
lrwxrwxrwx. 1 root root 20 Jun 12 12:25 K85messagebus -> ../init.d/messagebus
lrwxrwxrwx. 1 root root 20 Jun 12 10:58 K87multipathd -> ../init.d/multipathd
lrwxrwxrwx. 1 root root 21 Jun 12 10:57 K87restorecond -> ../init.d/restorecond
lrwxrwxrwx. 1 root root 16 Jun 12 10:58 K88auditd -> ../init.d/auditd
lrwxrwxrwx. 1 root root 15 Jun 27 11:59 K88iscsi -> ../init.d/iscsi
lrwxrwxrwx. 1 root root 17 Jun 12 10:57 K88rsyslog -> ../init.d/rsyslog
lrwxrwxrwx. 1 root root 16 Jun 12 10:58 K89iscsid -> ../init.d/iscsid
lrwxrwxrwx. 1 root root 21 Jun 12 13:01 K89portreserve -> ../init.d/portreserve
lrwxrwxrwx. 1 root root 15 Jun 12 11:15 K89rdisc -> ../init.d/rdisc
lrwxrwxrwx. 1 root root 17 Jun 12 11:15 K90network -> ../init.d/network
lrwxrwxrwx. 1 root root 19 Jun 12 10:57 K92ip6tables -> ../init.d/ip6tables
lrwxrwxrwx. 1 root root 18 Jun 12 10:57 K92iptables -> ../init.d/iptables
lrwxrwxrwx. 1 root root 22 Jun 12 10:58 S02lvm2-monitor -> ../init.d/lvm2-monitor
lrwxrwxrwx. 1 root root 26 Jun 12 10:58 S25blk-availability -> ../init.d/blk-availability
lrwxrwxrwx. 1 root root 19 Jun 12 10:57 S26udev-post -> ../init.d/udev-post
lrwxrwxrwx. 1 root root 15 Jun 26 12:32 S95jexec -> ../init.d/jexec
lrwxrwxrwx. 1 root root 16 Jun 12 11:15 S99single -> ../init.d/single
Jawaban yang Diterima:
Saat Anda mengganti runlevel, satu-satunya hal yang dieksekusi adalah skrip di /etc/rc.d/rc${NEW_LEVEL}.d/
.
Ini berarti Anda benar:Setiap rc*.d
direktori harus dapat menangani semua proses/layanan berubah saat beralih dari runlevel lain. Jadi setiap direktori rc berisi set lengkap skrip untuk mencapai runlevel tersebut.
Katakanlah Anda beralih ke runlevel 3. /etc/rc.d/rc3.d/K*
skrip akan mencoba untuk menghentikan proses apa pun yang sedang berjalan di runlevel Anda sebelumnya (bisa berupa angka apa saja), dan /etc/rc.d/rc3.d/S*
skrip akan memulai proses apa pun yang perlu dimulai (dan belum dimulai di runlevel sebelumnya).
Jelas, mengelola semua symlink ini akan sangat merepotkan, jadi ada utilitas untuk membantu mengelola ini. Di Debian dan Ubuntu (setidaknya, mungkin yang lain), Anda dapat menggunakan update-rc.d
untuk secara selektif mengaktifkan/menonaktifkan skrip yang ditemukan di /etc/init.d
, atau untuk menyetelnya ke "default" atau setelan yang disarankan untuk setiap skrip. Ini akan membuat dan memperbarui semua symlink untuk Anda, untuk mencerminkan perubahan konfigurasi yang ingin Anda lakukan. Di CentOS, saya mengerti Anda dapat menggunakan ntsysv
atau chkconfig
untuk melakukan hal yang sama.
Secara efektif, Anda tidak pernah sentuh file di /etc/rc*.d/
(atau /etc/rc.d/rc*.d/
) dirimu sendiri; Anda selalu menggunakan alat ini (mis. update-rc.d
, ntsysv
, chkconfig
) untuk membuat perubahan apa pun.