In this lesson, you’ll learn how to manage system services with Upstart, switch runlevels, and handle system shutdowns and reboots. We’ll cover core commands, scheduling techniques, and best practices for both Upstart and systemd environments.Documentation Index
Fetch the complete documentation index at: https://notes.kodekloud.com/llms.txt
Use this file to discover all available pages before exploring further.
Controlling Services with Upstart
Upstart job definitions reside in/etc/init. You can list all available services and their current states (including PIDs) using initctl list:
Upstart jobs live under
/etc/init. To add or modify a job, create or edit its .conf file in this directory.| Command | Action | Example |
|---|---|---|
start <job> | Start the service | sudo start tty6 |
stop <job> | Stop the service | sudo stop tty6 |
status <job> | Show state and PID | sudo status tty6 |
Querying and Switching Runlevels
Although Upstart doesn’t use/etc/inittab, you can still use the legacy commands:
Note: Runlevels 0 and 6 correspond to halt and reboot in System V–style init.
System Shutdown and Reboot
Theshutdown utility wraps System V runlevel transitions with extra safeguards:
- Broadcasts a warning to all logged-in users
- Blocks new logins during shutdown
- Sends
SIGTERMthenSIGKILLto processes - Transitions to runlevel 0 (halt) or 6 (reboot)
shutdown without -h or -r switches to single-user mode (runlevel 1).
Scheduling a Shutdown
The<time> argument is mandatory and accepts:
| Format | Description | Example |
|---|---|---|
hh:mm | Specific 24-hour time | 02:00 |
+m | Minutes from now | +20 |
now/+0 | Immediate shutdown | now |
Scheduling or initiating a shutdown requires root privileges. Ensure you have the proper permissions before running these commands.
SysV vs. systemd Commands
On System V–based distributions,shutdown handles power actions. On systemd-based systems, use the following equivalents:
| Action | SysV Command | systemd Command |
|---|---|---|
| Reboot | sudo shutdown -r now | sudo systemctl reboot |
| Power off | sudo shutdown -h now | sudo systemctl poweroff |
/etc/shutdown.allow.