DevOps Bootcamp · Lesson

Manage Services with systemd

Start, stop and enable services.

Lesson 3 of 413 steps

Manage Services with systemd is a free DevOps Bootcamp lesson on CoddyKit. This is lesson 3 of 4. Any 3 lessons of this learning path are free to read in full — after that, CoddyKit PRO unlocks every lesson, plus hands-on practice with a built-in code editor and a 24/7 AI tutor. It is part of the DevOps Bootcamp learning path, and your progress syncs across the web and the CoddyKit app. The DevOps Bootcamp course includes 4 lessons in total.

Manage Long-Running Services

The systemd module controls services managed by systemd, the init system on most modern Linux distros. You start, stop, and enable them with it.

Start a Service

Give the service name and set state: started. The module starts it only if it is not already running, staying idempotent.

ansible.builtin.systemd:
  name: nginx
  state: started

Stop a Service

Use state: stopped to bring a service down. As always, it only acts if the service is currently running.

ansible.builtin.systemd:
  name: nginx
  state: stopped

Restart and Reload

state: restarted fully restarts a service, while reloaded re-reads config without dropping connections. Restart is the safe default.

ansible.builtin.systemd:
  name: nginx
  state: restarted

Start vs Enable Are Different

state controls if a service runs right now. enabled controls whether it starts automatically on boot. They are independent.

Enable at Boot

Set enabled: true so the service launches automatically after a reboot. Combine it with started to cover both now and later.

ansible.builtin.systemd:
  name: nginx
  state: started
  enabled: true

Reload the systemd Daemon

After adding a new unit file, set daemon_reload: true so systemd re-reads its configuration before you act on the unit.

ansible.builtin.systemd:
  name: myapp
  daemon_reload: true

It Stays Idempotent

Ask for started on a running service and you get ok, not changed. The module checks the live state before doing anything.

Root Access Is Required

Controlling services needs privileges, so add become: true. Without it, systemd refuses and the task fails.

- name: Enable nginx
  become: true
  ansible.builtin.systemd:
    name: nginx
    enabled: true

There Is Also the service Module

The generic service module works across init systems. Use systemd directly when you need systemd-only options like daemon_reload.

Pairs Well With Handlers

A common pattern is to restart a service only when its config changes. Handlers, which you meet later, trigger this restart on change.

Quick Check

You want nginx running now and also after every reboot.

Recap

The systemd module starts, stops, restarts, and enables services. Remember that state means now and enabled means on boot. ⚙️

Free to start

Learn DevOps Bootcamp with an AI tutor — free

Write and run real code in your browser, get instant help from a 24/7 AI tutor, and pick up where you left off on the web or in the app.

Courses
142
Lessons
568

Frequently Asked Questions

Is the “Manage Services with systemd” lesson free?

Yes — any 3 lessons of the DevOps Bootcamp learning path, including “Manage Services with systemd”, are free to read in full here on the web. After that, CoddyKit PRO unlocks every lesson, plus interactive practice with a built-in code editor and a 24/7 AI tutor. The DevOps Bootcamp course includes 4 lessons in total.

What will I learn in “Manage Services with systemd”?

Start, stop and enable services. You practise DevOps Bootcamp with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.

Do I need any experience to start DevOps Bootcamp?

No prior experience is required. DevOps Bootcamp on CoddyKit is structured for beginners through advanced learners, so you can start here or from the beginning and move at your own pace. This is lesson 3 of 4.

How long does the “Manage Services with systemd” lesson take?

Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.

Can I write and run code in this DevOps Bootcamp lesson?

Yes. Every DevOps Bootcamp lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.

All lessons in this course

  1. What a Module Actually Is
  2. Install Packages with the package Module
  3. Manage Services with systemd
  4. Read the Docs with ansible-doc
← Back to DevOps Bootcamp