This is an old revision of the document!
Init Systems
General Information
Down and dirty quick info about three different init systems that Linux uses; SysV init, upstart, and systemd.
Checklist
- Distro: Varies, depending upon init system.
SysV Init (init)
Distributions: RHEL/CentOS ⇐ 6 (RHEL 6 uses an init/upstart combination), Debian ⇐ 7
Init run levels
- 0 : shutdown
- 1 and S : single user mode
- 2 - 5 : include networking support (GUI login can start at one of these, distro depending)
- 6 : reboot level
Defualt run level
- Set in file: /etc/inittab
Example with run level 5 as default:
id:5:initdefault
Master Copy of Startup Scripts
/etc/init.d/
rc#.d directories
The rc#.d directories contain symbolic links to the scripts in /etc/init.d.
# = the run level, ie rc0.d, rc1.d, rc2.d, rc3.d, rc4.d, rc5.d, rc6.d
Locations
- /etc/rc.d/rc#.d or
- /etc/rc#.d
Script Names
- Scripts are named for if they are going to Start(S) or Kill(K) the script, a sequence number, and then the name of the script.
- /etc/rc2.d/S80cups = This would Start(S) cups after any scripts numbered S01 to S79
- /etc/rc0.d/K80cups = This would Stop/Kill (K) cups after any scripts numbered K01 to K79
Manage Services
- chkconfig: Red Hat based systems
- update-rc.d: Debian/Ubuntu
List all services and the run levels they will start on:
chkconfig --list
List a single service:
chkconfig --list httpd
Set a service to start on boot
chkconfig httpd on
Control Services
Show service status
service httpd status or /etc/init.d/httpd status
Stop/start/restart a service
service httpd stop service httpd start service httpd restart
Upstart
Distributions: Ubuntu 9.10 - Current (migrating to systemd), RHEL/CentOS 6 (some scripts)
Upstart uses event driven jobs, instead of run levels to executes scripts. It does have events for rc0-6 to maintain comptability with init.
Job Definition Files
- Location: /etc/event.d/
Control Jobs
List all known jobs
initctl list
Show status of a job
initctl status httpd
Stop/start/restart a job
initctl stop httpd initctl start httpd initctl restart httpd
Systemd
Distributions: RHEL/CentOS 7, Debian 8, Ubuntu 15.4?
Location of Unit Scripts
All of systemd unit scripts are located here (and sub folders):
/usr/lib/systemd/
Systemd uses this directory of symlinks to run those scripts:
/etc/systemd/system/
Other systemd configuration:
/etc/systemd/
Control Units
List all loaded units
systemctl list-units or systemctl
List all loaded but inactive too
systemctl --all
List all installed units
systemctl list-unit-files
Show status of a unit
systemctl status NetworkManager.service or systemctl status NetworkManager
Stop/start/restart a unit
systemctl stop NetworkManager systemctl start NetworkManager systemctl restart NetworkManager
Laptop: Disable Suspend
On systemd based systems, the laptop suspend on lid closed can be disabled by changing the logind config.
1) Edit /etc/systemd/logind.conf
2) Uncomment “HandleLidSwitch” and set to ignore
HandleLidSwitch=ignore