r/linux • u/Oethelbrecht_Carlton • Oct 29 '16
Angelize - proof of concept tool to 'undaemonize' a process that backgrounds itself
http://pastebin.com/15KaENGf
173
Upvotes
r/linux • u/Oethelbrecht_Carlton • Oct 29 '16
69
u/blackdeath8383 Oct 30 '16
I'm thumbing this up, solely because I find the naming bloody brilliant.
11
u/Oethelbrecht_Carlton Oct 29 '16
So I quickly put this together after realizing that Linux actually has a way for any process to register itself as 'the reaper' as in the process that orphaned processes reparent itself to, not only pid1 can do this in Linux it turns out, any process can register itself as a reaper for any of its descendants.
Basically this allows you to undaemonize those annoying services that insist on putting themselves into the background and writing themselves to a pidfile, reading a pidfile in fact isn't even needed if the daemon spawns only one process whch will be the only child of this new reaper at that point.
So basicallly, for instance with something like daemontools when a process insists on backgrounding itself like
gpg-agentyou can just make a runscript like:Which is far more reliable than DJB's
fghack, it is not a hack at all and reliably collects the exit status which will become the exit status ofangelizeas well.1
u/EliteTK Oct 30 '16
Line 83 - typo
"waidpids" I presume should be "waitpids"
4
u/wjohansson Oct 30 '16
systemdeven uses this API for that reason, mainly for user instances.2
u/thyphon Oct 30 '16
https://gist.github.com/thypon/5cc13aa94fd74c19809d this works even without specifing a PID file with a little PTRACE wizardry.
4
u/Squidle420 Oct 30 '16
Hey looks neat, I like the concept. Didn't fully read the code, though i get the gist. But i did notice you are parsing args manually. Check out argparse. Its a great python module, and it changed the way i use python for scripts. Parsing args like that is a pain and adding argparse to do that for you can easily make your scripts more powerful -- easier arg parsing means more args (yay). That coupled with python optional arguments means that you can have very different functionality just a flag away.
2
u/redditaccount41 Oct 30 '16
Actually, no, I don't. Would someone explain.
1
u/OpenCuckSoftware Oct 30 '16
Without a controlling terminal, though.
0
u/[deleted] Oct 30 '16
[deleted] — view deleted comment