How to Reload Modified systemd Unit Files: When and How to Use systemctl daemon-reload


3 views

When working with systemd services, a common question arises about whether modifications to unit files require explicit reloading. The short answer is yes, but the behavior differs depending on whether the service is currently running.

Systemd maintains an internal representation of unit files in memory. For changes to take effect in these cases:

  • After creating a new unit file
  • When modifying an existing unit file's configuration
  • When changing dependencies or ordering directives

The proper way to notify systemd about configuration changes is:

sudo systemctl daemon-reload

This command:

  • Re-parses all unit files
  • Maintains existing process states
  • Doesn't restart any services automatically

Let's examine a complete example with a custom service:

# Create/edit the service file
sudo nano /etc/systemd/system/mine.service

[Unit]
Description=My Custom Service
After=network.target

[Service]
ExecStart=/usr/local/bin/mine
Restart=on-failure

[Install]
WantedBy=multi-user.target

After saving changes, run:

sudo systemctl daemon-reload
sudo systemctl restart mine.service  # If you want changes applied immediately

Some important nuances to consider:

  • Enabled services (via systemctl enable) will automatically pick up changes after reload
  • For running services, a restart is needed to apply changes to the running process
  • Consider using systemctl edit --full servicename which handles reload automatically

Always verify your changes:

systemctl show mine.service | grep ExecStart
systemctl status mine.service

This confirms the new configuration is active.


When working with systemd services, a common question arises: do modifications to unit files require explicit reloading? The short answer is yes, but let's explore the details.

systemd maintains an internal representation of unit files in memory. When you modify a unit file on disk (like mine.service), these changes aren't automatically recognized by the running systemd instance. This is where daemon-reload comes into play.

# After modifying /etc/systemd/system/mine.service
sudo systemctl daemon-reload

Consider these common situations where reloading is necessary:

  • Adding new environment variables to the service
  • Changing execution commands or paths
  • Modifying dependency chains (After/Before directives)

It's crucial to distinguish between these operations:

# Reloads unit definitions without affecting running services
sudo systemctl daemon-reload

# Restarts a specific service (stops and starts it)
sudo systemctl restart mine.service

For development workflows, I recommend this sequence:

  1. Edit the unit file
  2. Reload the daemon
  3. Restart the service (if needed)
  4. Check status
sudo nano /etc/systemd/system/mine.service
sudo systemctl daemon-reload
sudo systemctl restart mine.service
sudo systemctl status mine.service

For frequent modifications, consider adding a reload trigger to your editor. For vim users:

autocmd BufWritePost /etc/systemd/system/*.service !sudo systemctl daemon-reload

If changes don't take effect:

  • Verify file permissions (should be 644)
  • Check for syntax errors with systemd-analyze verify
  • Ensure you're modifying the correct file location