Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SIGHUP for reloading configuration

According to signal(7), SIGHUP is used to detect hangup on controlling terminal or death of controlling process.

However, I have come across a lot of OSS daemons(services) where SIGHUP is used to initiate a reload of configuration. Here are a few examples: hostapd, sshd, snort etc.

Is this a standard(or a generally acceptable) way to implement a reload? If not, whats recommended?

like image 291
HAL Avatar asked Sep 27 '13 13:09

HAL


People also ask

What is SIGHUP used for?

The SIGHUP (“hang-up”) signal is used to report that the user's terminal is disconnected, perhaps because a network or telephone connection was broken.

Which signal is used to reload the configuration of a service?

According to signal(7) , SIGHUP is used to detect hangup on controlling terminal or death of controlling process. However, I have come across a lot of OSS daemons(services) where SIGHUP is used to initiate a reload of configuration. Here are a few examples: hostapd , sshd , snort etc.

What sends SIGHUP?

SIGHUP would be sent to programs when the serial line was dropped, often because the connected user terminated the connection by hanging up the modem. The system would detect the line was dropped via the lost Data Carrier Detect (DCD) signal.


2 Answers

SIGHUP as a notification about terminal closing event doesn't make sense for a daemon, because deamons are detached from their terminal. So the system will never send this signal to them. Then it is common practice for daemons to use it for another meaning, typically reloading the daemon's configuration. This is not a rule, just kind of a convention. That's why it's not documented in the manpage.

See the wikipedia entry for SIGHUP and from there, a longer description with implementation example

like image 119
Little Jawa Avatar answered Sep 20 '22 19:09

Little Jawa


In my experience, SIGHUP is commonly used to request that a daemon reload its configuration. Using this well-known technique follows the principle of least surprise. Your users have likely encountered daemons which do exactly this, so they'll immediately understand what SIGHUP means to your daemon.

like image 38
pburka Avatar answered Sep 22 '22 19:09

pburka