Logging shutdown

MymsMan

Ad detector
Warning technical discussion

I have long wished there was a way of telling when a Humax shuts down normally.
We have log records at start up but no corresponding record when the humax shuts down in response to the Power button or after a recording.

Looking at some of the routines in /mod/etc/init.d they are coded to handle both Start and Stop routines so it should be trivial to add shutdown logging but it doesn't appear to work.

A bit of googling indicates that init.d routines are not called at shutdown if they have terminated but some of the init.d routines are long running (eg S54recmon) so I tried adding logging to it
Bash:
    stop)
        echo "Stop Recmon" >> /mod/tmp/recmon.log
        pkill -f /mod/sbin/recmon
        ;;
    *)

But this still doesn't work, why?

The google threads suggest using systemd in preference to init.d routines but that does not appear to be an option for us,

Any other thoughts of ways to achieve a shut down log record.

It would also be nice to detect when the Power button has been pressed but the ir package doesn't have an option to drive a process when a key is pressed.
 
We're using the Busybox init, I suppose. Unless there is a ::shutdown:... action in /etc/inittab (and inittab handling is in the build), the stop actions in /etc/init.d won't be run. The Busybox source code explains how it works.

The /mod/etc/init.d/S... routines are run from /etc/init//rcS.mod with start and I don't know of anything that runs these routines with stop. But obviously there could be such a thing.
 
The version of busybox init that we are using does include the action restart so it may include shutdown as well.
Not sure it will work though because we don't know how the humaxtv app handles the shutdown.

Perhaps the easiest way to detect power off would be to get some external device to ping it.
 
A bit of googling indicates that init.d routines are not called at shutdown if they have terminated but some of the init.d routines are long running (eg S54recmon) so I tried adding logging to it... But this still doesn't work, why?
Because there is (almost *) nothing to call them.
We're using the Busybox init, I suppose.
Yes.
Unless there is a ::shutdown:... action in /etc/inittab
There isn't.
(and inittab handling is in the build),
It is. But it is irrelevant anyway, as init spends all its time stuck in the sysinit phase courtesy of S90settop. If that exits or crashes, it moves to the once phase which calls /sbin/reboot
The /mod/etc/init.d/S... routines are run from /etc/init//rcS.mod with start and I don't know of anything that runs these routines with stop. But obviously there could be such a thing.
* The fast restart (wot I worked out!) calls them with stop, but nothing in the normal course of operation.
The version of busybox init that we are using does include the action restart so it may include shutdown as well.
Yes, easily proved with strings on /usr/bin/humaxtv
Not sure it will work though because we don't know how the humaxtv app handles the shutdown.
It appears not to exit (as it would cause the aforementioned reboot), but just to poke the front panel to turn the power off, having programmed any timed wakeup.
Presumably it unmounts the disk filesystems as well before doing that, having done shutdown thumbnail processing.
 
Because there is (almost *) nothing to call them.

Yes.

There isn't.

It is. But it is irrelevant anyway, as init spends all its time stuck in the sysinit phase courtesy of S90settop. If that exits or crashes, it moves to the once phase which calls /sbin/reboot

* The fast restart (wot I worked out!) calls them with stop, but nothing in the normal course of operation.

Yes, easily proved with strings on /usr/bin/humaxtv

It appears not to exit (as it would cause the aforementioned reboot), but just to poke the front panel to turn the power off, having programmed any timed wakeup.
Presumably it unmounts the disk filesystems as well before doing that, having done shutdown thumbnail processing.
I did wonder whether I could handle the SIGKILL/SIGTERM signals and write a log record but if it is just pulling the virtual plug there won't be any termination signals

My next thought is a heartbeat task that touches a file every few seconds, at next boot we can log the last time the heartbeat task was active which would also work to identify when a system crashed.
 
How doth a Humax crash? Let me count the ways ...
  • humaxtv crashes (and the crash can be logged already)
  • Linux crashes
  • one or the other hangs and is terminated with a reset (HD Fox, or HDR with custom wiring) or power off.

So maybe one challenge is to tell the last of these from humaxtv turning off the power.
 
My next thought is a heartbeat task that touches a file every few seconds, at next boot we can log the last time the heartbeat task was active which would also work to identify when a system crashed.
My first attempt /mod/etc/init.d/S99webiflog
Jim Code:
#!/mod/bin/jimsh
source /mod/webif/lib/setup
require  system.class

set file  "/mod/tmp/heart.beat"

if {[file exists $file]} {
  set mtime [file mtime $file]
  set ftime [clock format $mtime -format "%d/%m/%Y %H:%M:%S"]
  system plog activity "Last Heartbeat activity $ftime"
}

while true {
  sleep 60
  # system plog activity "S99webiflog: Still here"
  exec touch $file
}
 
I added Signal detection and a SYSTERM is received when rebooting the system from the webif but not when powering off using the Remote control confirming @prpr's belief that it just turning the power off
Code:
3494    12/11/2022 12:51:32 - Last Heartbeat activity 12/11/2022 12:44:19
3493    12/11/2022 12:51:24 - System booted (Remote control handset).
3492    12/11/2022 11:50:18 - Last Heartbeat activity 12/11/2022 11:49:20
3491    12/11/2022 11:50:14 - System booted (Remote control handset).
3490    12/11/2022 11:49:20 - S99webiflog: Signal SIGTERM received
3489    12/11/2022 11:47:36 - Scheduled The Brokenwood Mysteries @ 1668276000
3488    12/11/2022 11:46:14 - Last Heartbeat activity 12/11/2022 11:37:35
3487    12/11/2022 11:46:11 - System booted (Remote control handset).

I am also considering logging the transitions between Awake and Stand by and whether the humaxtv process is running or not
 
  • Like
Reactions: /df
Back
Top