Init process on UNIX and Linux systems
Init is the parent of all processes, executed by the kernel during the booting of a system. Its principle role is to create processes from a script stored in the file /etc/inittab. It usually has entries which cause init to spawn gettys on each line that users can log in. It controls autonomous processes required by any particular system.
After reading this file, how the system should be set up in each runlevel is determined by init and also set default runlevel. Init starts all background process after setting default runlevel for the system.
Runlevels
Runlevel, a software configuration of the system which allows only a selected group of processes to exist. The processes produced by init for each of these runlevels are defined in the /etc/inittab file.
Init can be in one of these eight runlevels: 0-6 and S or s. The runlevel can be changed by having a privileged user run telinit, which sends appropriate signals to init, telling it which runlevel to change to.
S or s are same.
7-9 are valid runlevels. though not really documented as «traditional» Unix variants don’t use them. runlevels S and s are in fact the same. Internally they are aliases for the same runlevel.
Runlevels | Functions |
---|---|
0 | To halt the system |
1 | To get the system down into single user mode |
2 | To get multiuser mode without networking |
3 | To get multiuser mode with networking |
4 | Not used |
5 | To get multiuser mode with networking and X windows |
6 | To reboot the system |
S or s | Not used directly. |
Booting
After invoking init as the last step of the kernel boot sequence, it sees if an entry of the type initdefault is present in the file /etc/inittab. The initdefault entry determines the initial runlevel of the system. If no such entry (or no /etc/inittab at all) is present there, a runlevel must be entered at the system console.
Changing Runlevels
After specifying all the processes, init waits for one of its descendant processes to die, a powerfail signal, or until it is signaled by telinit to change the system’s runlevel. It re-examines the /etc/inittab file, when one of the above three conditions occurs.
init still waits for one of the above three conditions to occur. For providing an instantaneous response, the telinit Q or q command can wake up init to re-examine the/etc/inittab file.
If init is not in single user mode and receives a powerfail signal (SIGPWR), it reads the file /etc/powerstatus. Then it starts a command based on the contents of this file −
Tag | Description |
---|---|
F(AIL) | Power is failing, UPS is providing the power. Execute the powerwait and powerfail entries. |
O(K) | Power has been restored, execute the powerokwait entries. |
L(OW) | The power is failing and the UPS has a low battery. Execute the powerfailnow entries. |
If /etc/powerstatus contains anything else then the letters F, O or L or doesn’t exist, init will behave as if it has read the letter F.
Usage of SIGPWR and /etc/powerstatus is discouraged. If Someone wanting to interact with init should use the /dev/initctl control channel — see the source code of the sysvinit package for more documentation about this.
When init is requested to change the runlevel, it sends the warning signal SIGTERM to all processes that are undefined in the new runlevel. Then It waits 5 seconds before forcibly terminating these processes via the SIGKILL signal.
Init assumes that all these processes and their descendants remain in the same process group which init originally created for them. It will not receive these signals, if any process changes its process group affiliation. Such processes need to be terminated separately.
TELINIT
/sbin/telinit is linked to /sbin/init which takes a one-character argument and signals init to perform the appropriate action. The following arguments serve as directives to telinit −
Tag | Description |
---|---|
0,1,2,3,4,5 or 6 | tell init to switch to the specified run level. |
a, b, c | tell init to process only those /etc/inittab file entries having runlevel a, b or c. |
Q or q | tell init to re-examine the /etc/inittab file. |
S or s | tell init to switch to single user mode. |
U or u | tell init to re-execute itself (preserving the state). No re-examining of/etc/inittab file happens. Request would be silently ignored, if Run level is not one of Ss12345. |
It can also tell init how long it should wait between sending processes the SIGTERM and SIGKILL signals. 5 seconds is the default, but this can be changed with the -t sec option.
Only by users with appropriate privileges can invoke telinit.
By looking at its process id, init binary checks if it is init or telinit; the real init’s process id is always 1. So, instead of calling telinit one can also just use init instead as a shortcut.
Источник
6 шагов загрузки Linux на пальцах
Нажмите кнопку включения питания на вашем системнике, и спустя несколько секунд вы увидите окно входа в систему.
Посмею предположить, что каждого интересовало хоть когда-либо то, что происходит за занавесом заставок и загрузочных экранов с момента включения питания компьютера к моменту, когда предлагается войти в систему.
Я предлагаю вам познакомиться со следующими уровнями типичной загрузки Linux:
1. BIOS
2. MBR
3. GRUB
#boot=/dev/sda
default=0
timeout=5
splashimage=(hd0,0)/boot/grub/splash.xpm.gz
hiddenmenu
title CentOS (2.6.18-194.el5PAE)
root (hd0,0)
kernel /boot/vmlinuz-2.6.18-194.el5PAE ro root=LABEL=/
initrd /boot/initrd-2.6.18-194.el5PAE.img
4. Ядро или Kernel
5. Init
6. Уровень выполнения программ (Runlevel)
- Когда Линукс выполняет свою загрузку, вы можете наблюдать загрузку различных служб. К примеру, это могут быть сообщения типа «starting Postfix … OK» (запускается Postfix). Эти службы — и называются программами уровня выполнения, выполняемые из директории, которая соответствует нужному уровню выполнения.
- Исходя из настроек по умолчанию, система будет выполнять файлы в соответствии с нижеприведенными директориями.
- Выполнение уровня 0 – /etc/rc.d/rc0.d/
- Выполнение уровня 1 – /etc/rc.d/rc1.d/
- Выполнение уровня 2 – /etc/rc.d/rc2.d/
- Выполнение уровня 3 – /etc/rc.d/rc3.d/
- Выполнение уровня 4 – /etc/rc.d/rc4.d/
- Выполнение уровня 5 – /etc/rc.d/rc5.d/
- Выполнение уровня 6 – /etc/rc.d/rc6.d/
- Но имейте ввиду, что еще в каталоге /etc могут быть символические ссылки. Например, /etc/rc0.d залинкован на /etc/rc.d/rc0.d.
- В каталогах /etc/rc.d/rc*.d/ вы можете увидеть список программ, имя которых начинается из букв S и K.
- Программы, начинающиеся на S используются для запуска. S, потому что startup.
- Программы, которые начинаются с литеры K используются — правильно — для завершения работы. K, потому что kill.
- Еще есть номера рядом с буквами S и K в именах программ. Эти номера используются для определения порядка запуска этих программ.
- К примеру, S12syslog предназначен для запуска демона syslog, его порядковый номер 12. S80sendmail — для запуска демона sendmail, имеющего порядковый номер 80. Таким образом, программа syslog будет запущена перед sendmail.
Вот и все. Возможно, некоторым из вас это не ново и особого интереса не было при чтении статью, поскольку она более ориентирована на начально-средний уровень знакомства з Линуксом.
В таком случае могу лишь сказать, что «повторение — мать учения» (с).
Дополнения, исправления, уточнения
В комментариях неоднократно было апеллировано к тексту статьи, поэтому, думаю, стоит учесть некоторые важные комментарии хабрасообщества. (спасибо artemlight, 3al, Tishka17, HhyperH, Next_Alex, Ilya_Shmelykh, Aux, soomrack, Xpeh )
- artemlight:: «Ну скажем прямо — так грузятся далеко не все дистры». С ним согласилось большинство, отмечая и bsd-style init, u-boot, и хоть initrd в статье пропущен, стоить заметить, что он нужен ядру не во всех дистрибутивах. Также отмечено, что в slackware поддержка rc.d осуществляется только в качестве совместимости, а встраиваемые системы грузятся иначе. На декстопах иногда бывает EFI, а кроме того Linux популярен в мире embedded и там ещё куча разных платформ. Линукс в телефоне вообще иначе грузится.
- soomrack, ссылая на википедию: Еще хочется сделать замечание по поводу MBR, первого сектора и пр. Все несколько усложнилось за последние годы. Сейчас уместней говорить о EFI.
Источник
YoLinux.com: Linux Init Process / PC Boot Procedure
This tutorial covers the PC boot process and the Linux Operating System initiation of background applications (daemons/services). The sequence, configuration and administration of the Linux boot process is covered.
Also see the YoLinux Tutorial on Recovery and Boot disks.
Related YoLinux Tutorials:
- BIOS: The Basic Input/Output System is the lowest level interface between the computer and peripherals.
The BIOS performs integrity checks on memory and seeks instructions on the Master Boor Record (MBR) on the floppy drive or hard drive. - The MBR points to the boot loader (GRUB or LILO: Linux boot loader).
- Boot loader (GRUB or LILO) will then ask for the OS label which will identify which kernel to run and where it is located (hard drive and partition specified). The installation process requires to creation/identification of partitions and where to install the OS. GRUB/LILO are also configured during this process. The boot loader then loads the Linux operating system.
- See the YoLinux tutorial on creating a boot disk for more information on GRUB and LILO and also to learn how to put the MBR and boot loader on a floppy for system recovery.
- The first thing the kernel does is to execute init program. Init is the root/parent of all processes executing on Linux.
- The first processes that init starts is a script /etc/rc.d/rc.sysinit
- Based on the appropriate run-level, scripts are executed to start various processes to run the system and make it functional.
SysV init or systemd:
The Linux and Unix SysV heritage began with the «sysvinit» process which used the /etc/inittab configuration file to drive the execution of init scripts and configuration of terminal and GUI interfaces. SysV init launches scripts and «daemon» processes one at a time, in order for a given run level found in /etc/rc.#/ (Where # is a run level number from 0 to 6).
Systemd is used in later versions of Linux (Fedora 15+, RHEL 7, OpenSUSE 12.1+, . ) which is compatible with Unix SysV and Linux Standard Base (LSB) init scripts. Systemd supports parallelization (faster boot), socket management, process tracking, mounting of file systems and dependency-based service control. Daemon processes are categorized into «cgroups» which have categorized resource limits.
Ubuntu 12.04+, 14.04 uses a hybrid system called upstart which includes SysV runlevel specific start scripts in /etc/rc.#/ but also systemd scripts for those services which have been ported in /lib/systemd/system/. See «man 7 upstart-events» for details.
The init process is the last step in the boot procedure and identified by process id «1». Init is responsible for starting system processes as defined in:
- SysV systems like RHEL 1-6, Fedora 1-14: /etc/inittab
- Systemd Fedora 15+: /lib/systemd/system/default.target (This is a symbolic link)
And the files in /etc/systemd/system/ and /lib/systemd/system/
Init typically will start multiple instances of «getty» which waits for console logins which spawn one’s user shell process. Upon shutdown, init controls the sequence and processes for shutdown. The init process is never shut down. It is a user process and not a kernel system process although it does run as root.
Process ID | Description |
---|---|
0 | The Scheduler |
1 | The init process |
2 | kflushd |
3 | kupdate |
4 | kpiod |
5 | kswapd |
6 | mdrecoveryd |
Systemd is becoming the default init system for Linux and has brought the following changes:
- Boot scripts in /etc/systemd/system/ and /lib/systemd/system/
- Service control command:
- Fedora 15+: systemctl
- Ubuntu 12.04+, 14.04: initctl
- initctl list: List all system services and their current state.
- initctl stop service-name: Stop a specified service. See «list» above to list names.
- Requires kernel support: (Kernel compile config options)
- CONFIG_DEVTMPFS=y
- CONFIG_CGROUPS=y
- CONFIG_AUTOFS4_FS=[y|m]
- The kernel command line in GRUB will include «init=/bin/systemd»
- Gnome desktop D-Bus dependency on systemd
Init config file (Red Hat EL6): /etc/inittab
Init config file (Red Hat 7.3-9.0, Fedora 1-14, RHEL5): /etc/inittab
Note that this config file directs the init process to run the shell script /etc/rc.d/rc.sysinit. This script should be used as is and NOT changed. Extend rc.local and NOT this script. This will (not in exact order):
- Run /sbin/initlog (depricated after RHEL5)
- Run devfs to generate/manage system devices
- Run network scripts: /etc/sysconfig/network
- Start graphical boot (If so configured): rhgb (RHEL5)
rhgb is started by the initscripts which drives the boot process, just after the device detections (needed for example to get at least the input devices needed for X recognized) but before the filesystems are checked or mounted. Rhgb is started from /etc/rc.sysinit as soon as device detection is done, and if the binary is found. At that point only the root filesystem is mounted, read-only and we are about running fsck checks on the filesystems. If /usr is not present of if rhgb can’t start X the start is retryed later once the filesystems have been mounted. To make sure X is started on an environment where it is being configured properly we check that the init default from /etc/inittab is 5 or that that init level was passed on the command line. X and rhgb needs a writable filesystem to export communication channels with the boot process. To do this a small memory temporary filesystem is mounted under /etc/rhgb/temp first. To also allow communication at the X level, the network loopback device lo0 is also started and initialized prior to running X. Once both the filesystem and lo0 are ready /usr/bin/X11/X is started using vt8 and display :1 (not :0 to allow smoothing the transition from the temporary X server to the one started when going multiuser). Once X is sucessfully started, the graphic code instanciates the simple display with the progress bar and the detailed view using a vte widget. If a specific /etc/rhgb/xorg.conf configuration file for X under rhgb is provided then it will be passed to the X command line to allow a specific configuration for X boot. - Start console terminals, load keymap, system fonts and print console greeting: mingetty, setsysfonts
The various virtual console sessions can be viewed with the key-stroke:- RHEL6: ctrl-alt-F2 through F7. F1 is reserved for the GUI screen invoked in run level 5.
- Older systems: ctrl-alt-F1 through F6. F7 is reserved for the GUI screen invoked in run level 5.
- Mount /proc and start device controllers.
- Done with boot configuration for root drive. (initrd) Unmount root drive.
- Re-mount root file system as read/write
- Direct kernel to load kernel parameters and modules: sysctl, depmod, modprobe
- Set up clock: /etc/sysconfig/clock
- Perform disk operations based on fsck configuration
- Check/mount/check/enable quotas non-root file systems: fsck, mount, quotacheck, quotaon
- Initialize logical volume management: vgscan, /etc/lvmtab
- Activate syslog, write to log files: dmesg
- Activate PAM
- Activate swapping: swapon
Local system boot processes can be placed in file: /etc/rc.d/rc.local
The system will then boot to the runlevel set by the directive initdefault.
SysV init and systemd both support the notion of run levels but manage them in different ways. SysV init uses symbolically linked start/stop init scrips located in directories defining the services to be run (/etc/rc.d/rc2.d/) while systemd manages the services with «cgroups».
Typical run levels include:
- 0 — Halt
- 1 — Single-user text mode
- 2 — Not used (user-definable)
- 3 — Full multi-user text mode
- 4 — Not used (user-definable)
- 5 — Full multi-user graphical mode (with an X-based login screen)
- 6 — Reboot
The default boot level is set by /etc/systemd/system/default.target which is a symbolic link to the file defining the appropriate run level target.
Fedora 15-19:
- Set run level 3 (multi-user with networking and console only login):
rm /etc/systemd/system/default.target
ln -sf /lib/systemd/system/runlevel3.target /etc/systemd/system/default.target - Set run level 5 (graphic mode):
rm /etc/systemd/system/default.target
ln -sf /lib/systemd/system/runlevel5.target /etc/systemd/system/default.target
The run level targets are defined as runlevel0.target, runlevel1.target, runlevel2.target, runlevel3.target, .
Ubuntu 12.04+: (Upstart: Mix of SysV init and systemd. Not all services have been migrated)
- Run level defined by the services in directory /etc/systemd/system/multi-user.target.wants/
ls -l /etc/systemd/system/multi-user.target.wants/
This will show symbolic links to service files defined in /lib/systemd/system/
Runlevel «3» will boot to text or console mode and «5» will boot to the graphical login mode.
Runlevel | Scripts Directory (Fedora: /lib/systemd/system/) | State |
---|---|---|
0 | runlevel0.target , poweroff.target | shutdown/halt system |
1 | runlevel1.target, rescue.target | Single user mode |
2 | runlevel2.target | Multiuser with no network services exported |
3 | runlevel3.target , multi-user.target | Default text/console only start. Full multiuser |
4 | runlevel4.target | Reserved for local use. Also X-windows (Slackware/BSD) |
5 | runlevel5.target, graphical.target | XDM X-windows GUI mode |
6 | runlevel6.target, reboot.target | Reboot |
Note that the user friendly name is just a symbolic link to the runlevel name:
# ls -l /lib/systemd/system/runlevel3.target
lrwxrwxrwx. 1 root root 17 May 24 10:55 /lib/systemd/system/runlevel3.target -> multi-user.target
Ubuntu names the directories with an additionaol suffix: «.wants». For example multi-user.target on Fedora would be named multi-user.target.wants for an Ubuntu system.
The Linux boot process has six states of operation of which «0» is the shutdown state and «3» and above are fully operational with all essential processes running for user interaction. Upon system boot the LINUX system /sbin/init program starts other processes by performing the following:
- Init will bring up the machine by starting processes as defined in the /etc/inittab file.
The computer will be booted to the runlevel as defined by the initdefault directive in the /etc/inittab file. In this example a runlevel of «5» is chosen. Runlevel «5» will boot the system into GUI mode using XDM and X-Windows. Booting to runlevel «3» (often called console mode) is often used by servers which do not need a graphical user interface. If booted to init level «3» one can promote the run level with the command [root prompt]# init 5. See the more detailed explanation of run levels below.
The inittab file will allow you to capture key sequences (ctrl-alt-del), start dial in internet connections etc.
One of these process started by init is /sbin/rc. This script runs a series of scripts in the directories /etc/rc.d/rc0.d/, /etc/rc.d/rc1.d/, /etc/rc.d/rc2.d/, etc
Runlevel «3» will boot to text or console mode and «5» will boot to the graphical login mode ( «4» for slackware)
Runlevel | Scripts Directory (Red Hat/Fedora Core) | State |
---|---|---|
0 | /etc/rc.d/rc0.d/ | shutdown/halt system |
1 | /etc/rc.d/rc1.d/ | Single user mode |
2 | /etc/rc.d/rc2.d/ | Multiuser with no network services exported |
3 | /etc/rc.d/rc3.d/ | Default text/console only start. Full multiuser |
4 | /etc/rc.d/rc4.d/ | Reserved for local use. Also X-windows (Slackware/BSD) |
5 | /etc/rc.d/rc5.d/ | XDM X-windows GUI mode (Redhat/System V) |
6 | /etc/rc.d/rc6.d/ | Reboot |
s or S | Single user/Maintenance mode (Slackware) | |
M | Multiuser mode (Slackware) |
One may switch init levels by issuing the init command with the appropriate runlevel. Use the command «init #» where # is one of s,S,0,1,3,5,6. The command telinit does the same.
The scripts for a given run level are run during boot and shutdown. The scripts are found in the directory /etc/rc.d/rc#.d/ where the symbol # represents the run level. i.e. the run level «3» will run all the scripts in the directory /etc/rc.d/rc3.d/ which start with the letter «S» during system boot. This starts the background processes required by the system. During shutdown all scripts in the directory which begin with the letter «K» will be executed. This system provides an orderly way to bring the system to different states for production and maintenance modes.
If you installed all demons (background processes), Linux will run them all. To avoid slowing down your machine, remove unneeded services from the start-up procedure. You can start/stop individual demons by running service init scripts located in the /etc/init.d/ directory:
- /etc/rc.d/init.d/ (Red Hat/Fedora) Also /etc/init.d/ which is linked to /etc/rc.d/init.d/
- /etc/init.d/ (S.u.s.e.)
- /etc/init.d/ (Ubuntu / Debian)
and issuing the command and either the start, stop, status, restart or reload option i.e. to stop the web server:
- /etc/init.d/httpd stop
Use the command ps -aux to view all process on your machine.
TIP: List state and run level of all services which can be started by init: chkconfig --list
or
service --status-all | grep running (Red Hat/Fedora Core based systems)
GUI tool: /usr/X11R6/bin/tksysv
Adding a script to the /etc/rc.d/rc#.d/ directory with either an S or K prefix, adds the script to the boot or shutdown process. The scripts are run in numerical order. S20abc is run before S30xyz. The extensibility to the boot and shutdown procedures of the operating system is one of the strengths of UNIX. The orderly sequential initiation of processes can be coordinated for dependent processes. The orderly shutdown of processes is often required of complex programs such as databases. This is how it is done. Individual processes may be monitored, shutdown and started at any time using these scripts. i.e. /etc/rc.d/rc2.d/httpd start. The modifiers start, stop or status may be used.
The start/stop/status scripts actually reside in the directory:
- /etc/rc.d/init.d/ (Red Hat/Fedora) Also /etc/init.d/ which is linked to /etc/rc.d/init.d/
- /etc/init.d/ (S.u.s.e. and Ubuntu / Debian)
and are linked to the appropriate directories. These links may be created or destroyed using the chkconfig command. i.e. chkconfig --del httpd will remove the web server from the startup and shutdown process. Inversely chkconfig --add httpd will add it to the startup/shutdown process by generating links from the script in /etc/rc.d/init.d/ to the appropriate /etc/rc.d/rc#.d/ directory. For more information see the LINUX manual page on init.
Init scripts are found in /etc/init/
List services which are to be turned on at boot time: grep "start on" /etc/init/*
Also see man upstart-events to view events which can be configured.
System Service | Description |
---|---|
anacron | Run jobs which were scheduled for execution while computer was turned off. Catch up with system duties. |
arpwatch | Keeps track of IP address to MAC address pairings |
atd | Run scheduled batch jobs. |
autofs | automounts file systems on demand. |
bluetooth, pand, hidd, dund | Bluetooth netwoork support. |
crond | Job sheduler for periodic tasks. |
gpm | Allows console terminal cut and paste. (Non X-window consoles) |
https | Apache web server. |
iptables | Firewall rules interface to kernel. |
keytable | Loads selected keyboard map as set in /etc/sysconfig/keyboard |
kudzu | New hardware probe/detection during system boot. |
lpd or cups | Network printer services. |
microcode_ctl | Uploads microcode to kernel and ultimately to the Intel Pentium processor. (Hardware specific.) |
mysqld | Database services |
named | DNS name services (Bind) |
network | Active network services during system boot. Required for network connectivity. |
nfs | Network file system. Unix file sharing services. Also uses services: nfslock, portmap, rpcgssd, rpcidmapd, rpcsvcgssd |
nscd | Password and group lookup services for use with network authentication (NIS, LDAP. ). |
ntpd | Network Time Protocol time synchronization services. |
random | Random number generation tool used for encryption. |
rawdevices | Enables raw IO. Useful for Oracle and software which utilizes this for high speed disk access. |
smb | SAMBA: MS/Windows PC file sharing services |
syslog | System log file facility. |
ypbind | NIS file sharing/authentication infrastructure service. |
yppasswd | NIS file sharing/authentication infrastructure service. |
ypserv | NIS file sharing/authentication infrastructure service. |
xfs | X-Windows font server. |
Recommended basic services: anacron, ard, autofs, crond, gpm, iptables, keytable, kudzu, microcode_ctl (Intel32 hardware only), network, random. syslog
Graphics Workstation — add: xfs
File Server for PC clients — add: smb
Print Server — add: lpd or cups (hplip — HP Linux Imaging and Printing)
File server Linux/Unix clients — add: nfs, netfs, nfslock, portmap, ypbind, yppasswd, ypserv; NFSv4 add: rpcgssd, rpcidmapd, rpcsvcgssd
Web Server — add: httpd, tux, xinetdi, sshd
GUI tools can help you configure the appropriate services to start and provide a description of each service available:
- Fedora/RHEL/CentOS: /usr/bin/system-config-services
(Also /usr/sbin/serviceconf) - Red Hat 8.0/9.0: /usr/bin/redhat-config-services
- Ubuntu / Debian:
- bum (Boot Up Manager) (GUI image)
- /usr/bin/services-admin (GUI image)
- /usr/sbin/sysv-rc-conf (console program — see below)
Red Hat Configuration GUI:
- Fedora/RHEL/CentOS: /usr/bin/system-config-services
- Red Hat 8.0/9.0: /usr/bin/redhat-config-services
Red Hat/Fedora Core text console services selection tool: /usr/sbin/ntsysv
Debian/Ubuntu 12.04, 14.04: sysv-rc-conf
(Install: aptget install sysv-rc-conf)
This command can also be used in command line mode to control services:
- sysv-rc-conf --list : List services
- sysv-rc-conf service-name on : Start service
- sysv-rc-conf service-name off : Stop service
A single copy of the script is located in the directory: /etc/rc.d/init.d/script-name (Red Hat/Fedora) or /etc/init.d/script-name (Ubuntu / Debian).
Use the command chkconfig to generate soft links to the appropriate directories for the various run levels.
Example: Red Hat
The bash script functions daemon, killproc and status can all be found in the script /etc/rc.d/init.d/functions. (Red Hat/Fedora distributions)
Example: Ubuntu 14.04 See examples in /etc/init.d/ for examples onm how to support start, stop, status, restart, reload, etc.
The script must be executable to work. (chmod +x script-name).
The script may be used to start and stop processes. i.e.:
- /etc/rc.d/init.d/httpd restart
(Ubuntu / Debian / S.u.s.e.: /etc/init.d/apache2 restart) - /etc/rc.d/init.d/httpd stop
- /etc/rc.d/init.d/httpd start
OR use the Red Hat/Fedora core based service command:
- service httpd restart
- service httpd stop
- service httpd start
Note that two lines in the script enable the chkconfig command to control the script for the boot and shutdown process.
When added to the boot process using the «chkconfig --add script-name» command the start order/priority will be set to 80 while the stop/shutdown order will be set to 15. The process will be added to runlevels 3, 4 and 5. This is enabled by generating links from the location of the script (/etc/rc.d/init.d/) to the directory for the appropriate run level: /etc/rc.d/rc#.d/. The file name in the run level directory will reflect if it is used for boot (starts with an «S») or shutdown (starts with a «K»)
Upstart init config files (Ubuntu 14.04 example): /etc/init/*
SysV init files are still in /etc/init.d/*.
The two systems cohabitate on Ubuntu 12.04 and 14.04.
Fedora examples: (Note Ubuntu uses the command initctl with the same arguments)
- Start a specified service: systemctl start name.service
- Stop a specified service: systemctl stop name.service
- Restart a specified service: systemctl restart name.service
- Show status of a specified service: systemctl status name.service
- Enable a specified service to be started upon boot: systemctl enable name.service
- Disable a specified service to NOT be started upon boot: systemctl disable name.service
- Check if a specified service is to be started upon boot: systemctl is-enabled name.service; echo $?
The command «echo $?» shows the return code of the previous command:- 0: enabled
- 1: disabled
- List all active boot services: systemctl list-units --type=target
The (Red Hat/Fedora/IRIX) chkconfig command generates and breaks links between the directory /etc/rc.d/init.d/ and the appropriate run level directory: /etc/rc.d/rc1.d/ to control boot process initiation and process shutdown.
- chkconfig --level 345 httpd on — forces apache to be invoked for run levels 3, 4 and 5.
- chkconfig --add httpd — Start the web server daemon upon system boot.
- chkconfig --del sendmail — Do not start the sendmail daemon upon system boot.
- chkconfig --list — List all services and init levels.
- chkconfig --list | grep on — List all services to be started upon system boot.
Using chkconfig to administer xinetd processes.
Источник