SIGHUP for reloading configuration
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
How to know if a SIGHUP signal has been handled?
The inotify-tools C library may solve your problem. Its installation gives you access to new commands: inotifywait
and inotifywatch
.
Let's say you have this /tmp/foo.bar file. You can start watching for any read access on this file with the following command:
inotifywait --event access /tmp/foo.bar
Then, do a cat /tmp/foo.bar
and the program will return.
As I said, it's a C library and I guess there are other language implementations of it. So feel free to not use this Bash example and write you own program using this library.
Logstash configuration reload
Hot Reload is not yet supported. There is a Issue.
The logstash configuration is loaded at startup, so, if you kill your process (to restart it later), there is no reason why it does not work.
Upstart - how to send reload signal to script started as different user?
I ended up running my script as root and then dropping privileges to desired user.
To run script as root I've uncommented exec python app.py
from Upstart config above.
To drop privileges I use slightly modified code from this answer:
def drop_privileges(uid_name, gid_name):
'''If running as root, this function will try to change current uid and gid
to given values.
May raise OSError in case of error.
:param uid_name: Name of the user we need to be running as.
:param gid_name: Name of the group we need to be running as.
'''
starting_uid = os.getuid()
starting_gid = os.getgid()
log.info('drop_privileges: started as %s/%s' %
(pwd.getpwuid(starting_uid).pw_name,
grp.getgrgid(starting_gid).gr_name))
if starting_uid == 0:
# If we started as root, drop privs and become the specified user/group
log.info("drop_privileges: trying to drop provileges to '%s'" % uid_name)
# Get the uid/gid from the name
running_uid = pwd.getpwnam(uid_name).pw_uid
running_gid = grp.getgrnam(gid_name).gr_gid
# Try setting the new uid/gid
# These calls may result in exception, let it propagate back
# Exception thrown is: OSError (e.errno == 1 means 'Operation not
# permitted')
os.setgid(running_gid)
os.setuid(running_uid)
final_uid = os.getuid()
final_gid = os.getgid()
log.info('drop_privileges: running as %s/%s' %
(pwd.getpwuid(final_uid).pw_name,
grp.getgrgid(final_gid).gr_name))
Related Topics
Android Studio 2.3 Using Emulator from Console, "/Dev/Kvm Device: Permission Denied" for Root User
Loading U-Boot in Memory Instead of Flashing It
Bash File Is Running Fine in Windows for Testng But It Is Not Working in Linux/Mac
Exclude .Svn Directories from Grep
Sed Command with -I Option (In-Place Editing) Works Fine on Ubuntu But Not MAC
Update-Alternatives: Warning: /Etc/Alternatives/Java Is Dangling
How to Delete the First Column ( Which Is in Fact Row Names) from a Data File in Linux
Syntax of for Loop in Linux Shell Scripting
How to Programmatically Create Videos
Define Alias That References Other Aliases
Hook Functions for Linux Filesystem
Spidev Linux Driver on Intel Atom Board
Can't Su to User Jenkins After Installing Jenkins
Redirect All Output to File Using Bash on Linux
What Should Linux/Unix 'Make Install' Consist Of
List Supported Ssl/Tls Versions for a Specific Openssl Build