Kill SIGUSR1 kills my init.d service

Hi all,
I have a process say bin. bin is a C99 program and it sleeps a lot. Also it knows how to handle the kill signal SIGUSR1, which I use to wake it up.

I also have a lua script that is handling a http post request (via uhttpd). This script sends a signal to bin whenever it has finished handling a request. It essentially creates a file and bin reads that file to do some work, once it receives a signal.

All is well when bin is just a binary that i invoke from shell directly. When I try to create an init.d service to start this binary with respawn enabled, the service gets killed each time lua sends the SIGUSR1 and bin never seem to have a chance to handle that signal and after 5 respawn attempts, the service is stopped.

Not sure what is wrong here.

I am working on Openwrt Barrier Breaker 14.07.

Looking for any suggestion or ideas where I should drill down.

My two cents:

  • Barrier Breaker is old, very old; consider upgrading.

  • When the process is started from init.d, it has a different environment than when it is run from a shell: different current directory, different path, ...

Thanks for the response eduperez!

I cant help but use 14.07, its a cheap IoT box with some sensors installed.

Found this stuff at https://oldwiki.archive.openwrt.org/inbox/procd-init-scripts

Current versions (LEDE 17.01 and up) support sending signals to procd registered services. (OpenWrt-CC gained support for pidfile writing, which allowed third party monitoring services to send signals) This allows, for instance, reload_config and /etc/init.d/yourapp reload to issue a SIGHUP instead of stop/starting your process.

damn, so looks like using Barrier Breaker I cannot send signals to my service :frowning:

I can stop and restart my service, will have to redesign the application workflow to make it to work.

Or I can write a small supervisor that will be monitored by procd and it will monitor my child process. It might just work.

What about getting the PID from the .pid file and sending the signal to your process directly?

(P.S. If you're looking for an inexpensive replacement, I'm impressed with the GL-iNet AR300M-Lite, under US$18 on US Amazon and comparably priced direct. Has two GPIOs available for I2C or the like on the board and easily accessible.)

my lua script uses pidof to get the pid of the binary and send the SIGUSR1 signal directly to the process. I even tried doing the same manually via shell.

Instead of the actual process being able to handle the signal, the procd service captures it and just dies and attempts respawn.

I couldn't find any tool that would help me debug these signals and see what is happening under the hood.

Writing my own little supervisor seems like the path of lowest effort as of now.

I think you did not understand my second tip: I think the issue could not be on the signaling, but on what tasks are triggered by those signals. Check that your program works properly when launched from init.d.

ok, thanks for the tip. My service seems to be working fine if I use old style init.d script.

so the issue is with procd.

I will dig a bit more into this later to find why.