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.
All Inits
This section will compare three init systems; sysv, upstart, and systemd.
Command Table
- The service name “foo” will be used in all examples.
- systemctl assumes “.service” appended to unit name if left off
Command | Sysv | Upstart | Systemd |
---|---|---|---|
Status of Service | service foo status | initctl status foo | systemctl status foo |
Start Service | service foo start | initctl start foo | systemctl start foo |
Stop Service | service foo stop | initctl stop foo | systemctl stop foo |
Restart Service | service foo restart | initctl restart foo | systemctl restart foo |
Reload config file | service foo reload | initctl reload foo | systemctl reload foo |
List services | ls /etc/init.d/ | initctl list | systemctl (or) systemctl list-unit-files (or) systemctl list-unit-files –type=service |
Enable Service At Boot | chkconfig foo on | Edit /etc/init/<jobname>.conf “start on” field | systemctl enable foo |
Disable Service At Boot | chkconfig foo off | Edit /etc/init/<jobname>.conf “start on” field | systemctl disable foo |
List services and enabled run levels | chkconfig –list | initctl show-config | systemctl list-unit-files –type=service (or) ls /etc/systemd/system/*.wants/ |
All Inits Run Levels
Description | Sysv | Upstart | Systemd |
---|---|---|---|
Halt system | 0 | runlevel [0] | poweroff.target |
Single user mode | 1,s,single | runlevel [1] | rescue.target |
User defined. Same as 3 by default. | 2,4 | runlevel [24] | multi-user.target |
Multi-user, non-graphical | 3 | runlevel [3] | multi-user.target |
Multi-user, graphical | 5 | runlevel [5] | graphical.target |
Reboot | 6 | runlevel [6] | reboot.target |
Emergency shell | emergency | ? | emergency.target |
- Note: Upstart has many different “events” besides runlevels that can trigger jobs to start, such as “start on file-system” or “start on startup”
SysV Init (init)
Sysv init details not contained in All Inits section.
Distributions: RHEL/CentOS ⇐ 6 (RHEL 6 uses an init/upstart combination), Debian ⇐ 7
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
- service command: RedHat and Debian (service status/stop/start/restart)
- chkconfig: Red Hat based systems (enable/disable services)
- update-rc.d: Debian/Ubuntu (enable/disable services)
Upstart
Upstart details not contained in All Inits section.
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 compatibility with init.
- Job Definition Files Location: /etc/init/
- Job control: initctl
Systemd
Systemd details not contained in All Inits section.
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/
- Unit control: systemctl
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