In this lesson, you will learn how to trigger a service’s configuration refresh without restarting the process by leveraging SIGHUP signals.
The Problem with Restarts
When you change a configuration file for a long-running service (like nginx or sshd), a full service restart—using systemctl restart—is often destructive. It kills active connections, drops temporary state, and introduces a brief window of downtime. Ideally, we want the process to "re-read" its files while staying alive.
The SIGHUP Trigger
The SIGHUP (Signal Hangup) signal is the standard Linux convention for telling a daemon to reload its configuration. When a process receives this signal, it pauses its work, re-reads its configuration files from disk, and applies the changes—all without dropping existing network sockets or terminating the parent process.
To automate this in a systemd environment, you can use a Reload directive within your service unit. Most modern services support the ExecReload instruction. For example, if your application supports SIGHUP, you can configure your service file like this:
[Service]
Type=forking
ExecStart=/usr/local/bin/my-app --daemon
ExecReload=/bin/kill -HUP $MAINPID
Automation via Signals
Once ExecReload is defined, you can trigger this behavior manually via systemctl reload my-app. However, the real power comes from coupling this with your previous lessons. For example, if you have a Path unit monitoring a configuration file in /etc/my-app/, you can trigger the reload automatically the moment you save a file:
# my-app-watcher.path
[Path]
PathChanged=/etc/my-app/config.conf
Unit=my-app.service
[Install]
WantedBy=multi-user.target
Because systemd is smart, when a Path unit triggers a service that is already running, it executes the ExecReload command rather than restarting the process, provided the unit file explicitly defines the reload logic. This allows for seamless, non-disruptive updates to your system infrastructure based on file changes.
Key Takeaway: Use the SIGHUP signal via ExecReload in your service unit to refresh application state dynamically, ensuring zero-downtime configuration updates.