Many
system uses older SysVinit.
How are services controlled under Linux?
It is driven by script files.
It is not a binary like systemd. It does different way than systemd. It is
since 1970, so still many use it. Amazon Linux is based on CentOS 6 it uses
Upstart which is based on Sysvinit. Latest Amazon Linux uses systemd.
How do we know whether we are using SysVinit?
Kernel will fire off initialization system. It should be either
sysvinit or systemd. Process ID 1 will be either systemd or sysvinit.
Process number 1 says /sbin/init then it will be sysvinit, sometimes
we can't trust. We need to see whether it has symlink to systemd.
Sysvinit starts after the Kernel, what happens next?
BIOS fires up on the system and it does hardware detection, then it
reaches out and finds hard drive partition and finds /boot, finds kernel and
launches it and Kernel starts /sbin/init. Then it runs the script in serial not
in parallel like systemd.
cd /etc/rc.d
rc.sysinit (This script is started first)
rc1.d, rc2.d refers to previous iteration of sysvinit. Now
everything is inside rc.d.
Does one script rc.sysinit calls other scripts?
Yes, it call other script depending on the run level. In Linux we
have 7 run level, each indicates different status of the machine.
rc0.d -> Means shudown
We have runlevel for shutdown because we might need to runs some
script before shutdown like stop all process writing to disk
rc6.d -> Reboot
It is not necessary to have tasks in each runlevel.
1 to 5 runlevels are based on the distro. Check documentation. Lot
of the times it will be same but better check. You can also check in
initialization table
cat /etc/inittab
It tells what each run-level
does. In Centos 1 is for single user mode, 2 multiuser w/0 NFS, 3 Full
multiuser mode, 4 is unused, 5 is X11.
The alternative of runlevel in systemd is target files. By using
isolate command.
Based on the run level we choose it will start all the scripts
inside the specific run-level directory.
rc.local file is just present for backward compatibility.
Do we have to modify the script for each run level?
SSH is setup to run in runlevel 3 and 5 but they skipped in runlevel
2 because it has no networking. Suppose we have web server and we need it in
run level 3 and 5 we can write manual script. But it is handled by using below
commands:
sudo yum install httpd
This installation will create file under the run level. Mostly it is
symlink.
chkconfig allows to turn on/off the service to run and we can also specify runlevel
sudo chkconfig httpd on
sudo chkconfig --level 35 httpd off
But in-order to found out which service is in which run level we DO NOT to go and see in the rc directories.
Because even after turning off there will be symlink. The better way is to use
below command:
chkconfig --list
How does SYSVinit know which run level to boot to?
The run level will be present in /etc/inittab file.
If we want to change the run level temporarily, we can use below
command. Put the run level you want after init.
sudo init 3
Scheduling run level?
We can use cron to schedule or we can also use telinit. Using
telinit we can delay when the runlevel to change.
sudo telinit 3 -t 30
Be careful, this is old command and it not supported
by many distro.
No comments:
Post a Comment