5

How can I send some kind of reload command to a daemon started by upstart without the need to completely stop it?

buschtoens
  • 8,091
  • 9
  • 42
  • 60
  • Services started via `upstart` are either one-time programs that run to handle events or they are long-running daemons. Typically stdin/stdout/stderr for these sorts of programs doesn't exist -- they write to log files when they need to report problems, and read input from specific files. I'm curious why you're trying to work around this normal paradigm -- what _problem_ are you trying to solve? – sarnold May 29 '12 at 00:19
  • I run a node.js script as a daemon via upstart, that needs to run permanently. This script sometimes needs to get a reload command. Sadly upsatrt doesn't support syntax like `reload servercontrol`. So I thought about using stdin, since I can't stop the script for `stop servercontrol & start servercontrol`. – buschtoens May 29 '12 at 00:27
  • `reload service` will send a `SIGHUP` signal to your process; the `SIGHUP` signal is often used by daemons to request re-reading their configuration files... will that work for you? It'd be easy for admins to manage your task similar to all the other jobs that way. – sarnold May 29 '12 at 00:30
  • Oh... wow. That works. I'm flashed. I could swear that it didn't work a few minutes ago. I'll edit my question and you'll post your answer so I can vote and check it? :) – buschtoens May 29 '12 at 00:32

1 Answers1

9

upstart typically manages two types of processes:

  • programs that run once to handle an event
  • daemons that are long-lived and provide a service to something else

Daemons typically provide a signal handler for the SIGHUP signal the ask the daemon to re-read and re-parse their configuration files. (SIGHUP is a hang-up signal, more relevant to terminals that may come and go as telephone lines or SSH protocols are connected or disconnected. For programs that do not have terminals, it doesn't make sense to "hang up" their terminal, so the signal wouldn't be sent to daemon except by system administrator action.)

If you can modify your program to re-read its configuration when it receives a SIGHUP signal, then you can use the standard upstart reload service command to reload the configuration files. (You can do anything on this signal, but system administrators expect daemons to re-read configuration files on this signal -- doing something else may be confusing and annoying.)

sarnold
  • 102,305
  • 22
  • 181
  • 238
  • 4
    You can also configure an upstart script to emit a different signal for the `reload` command. Within the script itself simply declare `reload signal USR2` or whatever your app exepects. – Parker Selbert Nov 03 '14 at 20:50