4. Upstart Jobs

Upstart is an event-based init system used in some upstart linux distributions to manage services and tasks during boot and while the system is running. It operates through a system of jobs and events. While tracing the origin of every event can be complex, often requiring you to explore job configurations in /etc/init, you will more commonly need to manage these jobs directly from the command line. The initctl utility provides a suite of commands for this purpose.

Viewing Job Status

To see a list of all known Upstart jobs and their current states, use the list command.

initctl list

shutdown stop/waiting
console stop/waiting
...

The output displays the job name, its goal, and its current status. In the example shutdown stop/waiting, the job name is shutdown, its goal is stop, and its current status is waiting. The job status and goals will change as you interact with them.

To check the status of a specific job, use the status command.

initctl status networking
networking start/running

Manually Controlling Jobs

While job configuration files in /etc/init define how jobs start, stop, and interact with events, you can manually override these actions using initctl. This is useful for troubleshooting or performing administrative tasks.

To manually start a job:

sudo initctl start networking

To manually stop a job:

sudo initctl stop networking

To manually restart a job, which is a convenient shortcut for stopping and then starting it:

sudo initctl restart networking

Emitting Custom Events

Upstart jobs are triggered by events. You can also manually "emit" an event, which can be useful for triggering custom jobs or for testing purposes. Any job that is configured to start on some_event would be triggered by the following command.

sudo initctl emit some_event

Sign in to save your learning progress

Sign in

Exercises

Practice makes perfect! While there are no specific labs for Upstart, understanding how to schedule and manage tasks is crucial for controlling system processes. Here's a hands-on lab to reinforce your understanding of task management:

  1. Schedule Tasks with at and cron in Linux - Practice creating, managing, and removing one-time and recurring jobs, which are fundamental concepts related to how services and tasks are managed in Linux environments like those handled by Upstart.

This lab will help you apply the concepts of task automation in real scenarios and build confidence with managing system operations.

Quiz

How would you manually restart an Upstart job called `peanuts`? Please provide the full command. (Note: The answer is case-sensitive and must be in English.)