Thinking I could clean up my files in a SIGINT handler
Thinking I could clean up my files in a SIGINT handler
Thinking I could clean up my files in a SIGINT handler
You are never guaranteed to be able to do anything during a crash. You are better off handling these kinds of edge cases in a recovery phase during the start of your app.
It’s not a crash. It’s a graceful shutdown. I expected that to also shutdown my app gracefully.
I’m actually trying to store the program state that hasn’t been persisted yet to disk. Good luck doing that after the next boot.
Crash-only software. To be resilient you need some kind of ACID anyway which means that you can let go of your shutdown procedure and just send yourself SIGKILL instead.
This is legitimately the best usage of this meme I’ve seen in years. Termination signals hnnngg
How are you running your script?
(I have no idea how to solve your issue I'm just asking questions to sound smart and helpful)
It’s a node process invoked by a run.sh
, which gets executed via a .desktop
file in the ~/.config/autostart
directory.
I went with a systemd unit now and it works.
I can't remember off the top of my head, but your shell script might not be relaying the SIGTERM. Make sure you start your node process with the "exec" statement. This will replace the script's process with node instead of having node be a subprocess of your script.
"SyStEmD iS bLoAt..."
Your DE may be the one not relaying the sigterm, or it may be losing the PID because of the double launching.
Does the LSB have something to call on termination? Or you may want to call an executable there instead of a script.
Can't SIGTERM be observed to react to a poweroff?
That’s what I thought, but my program never receives the signal.
That might be an issue with who invokes your program.
I realise I'm late to the party and you've alreadu gone the systemd unit way, but had your script trapped sigterm to begin with?
When I run the script myself and kill it, it gets the signal and acts correctly. Only when I poweroff the system, this doesn’t work.
Interesting. Is this top answer accurate then?
https://stackoverflow.com/questions/31731980/handling-a-linux-system-shutdown-operation-gracefully
It turns out I’m getting SIGCHLD. It might be related to how my script is started – it is a bash script that starts a node process and is itself run by Cinnamon’s (?) startup applications feature.
Wrong; still investigating
My computer has a problem where occasionally it will become completely unresponsive. (Mouse cursor doesn't move. Keys have no apparently effect. Whatever app is running freezes. I think its a hardware problem with the graphics card, but I don't know what. Logs at the time it freezes say "the GPU has fallen off the bus".)
Anyway... I recently learnt about Magic SysRq. And I've been able to shutdown the computer from this unresponsive state with SysRq, R E I S U O
. Where as I understand it, the "E" tells processes the end nicely if they can; and then the "I" just ends them by force.
(At this point, I'm realising that the E
is SIGTERM, not SIGINT - so that screws up the relevance of my story; but I figure I'll keep going anyway.)
The point is, I've been using key combo with a nice pause between each key, thinking there was some chance that processes might be ending gracefully. But when I tried it while the computer wasn't frozen, the computer was able to inform me that the E and I commands were disabled. (I don't know why.) So even though I wanted to give a nice "please end" signal, in the end that just wasn't happening.
You could try enabling systemd-oomd. It's a userspace OOM killer and seems to be aggressive enough to mostly stop that from happening.
I didn't know why a person would go to these lengths to deal with a misbehaving computer, as compute devices are generally for work, and need to work in order to do work, and any kind of crash is going to get my entire focus until it is banished to Hades...
...but then, learned something along the way I probably otherwise would not have, because of @bleistift2@sopuli.xyz's tenacity.
Missed opportunity to make the last panel have her eyes closed (or just be fully black).
SIGHUP or SIGPWR, maybe?
nope, SIGCHLD. Wrong.
But thanks.
I thought someone here had mentioned that the environment and user executing the script at startup and you running the script might have differences. The reason it would have worked with systemd might be that the environment was loaded correctly?
That's why you launch them through systemd.
But systemd is the devil and makes nothing better, right?
Right?
Really? I've never had issue with it
openrc exists
The constant nagging by you systemd people worked. I’ve written a unit that does what I need it to do. That was more annoying than I think it needed to be, but well… my solution didn’t work at all.
AFAIK kernel itself doesn't send any signals to processes on shutdown/reboot, it just stops executing them. This is a job service manager (e.g. systemd) that terminates processes using SIGTERM before asking kernel to shutdown.