Additions to clean-shutdown script

I’ve got the Zero LiPo SHiM hooked up with a Scroll pHAT HD in a badge case. Although the clean-shutdown daemon works fine, I’d like to also get it to kill any scripts currently running before powering off. As it stands the Pi powers down but the LEDs on the display remain lit (until the battery is pulled or dies).

Where is the actual script that the daemon is running?

I’m just thinking of inserting a simple “pkill python” or running a script to clear the display before the actual poweroff.

Also, are the LEDs on the SHiM itself meant to remain lit when the shutdown occurs?

I installed the Zero LiPo stuff from the pimoroni-dashboard.

FOUND IT!

It’s running /usr/bin/cleanshutd

I can dabble with that.

Of course, now I’ve thought about it a better option is putting a link to a script in /etc/rc0.d to kill any running scripts and then clear the screen. From that location, it will run on shutdown (regardless of how the shutdown it triggered).

Oooh, that’s an interesting point. Are running scripts not explicitly killed with a signal of some sort?

I had a similar issue on my Sense Hat. I run it headless showing a continuously scrolling repeating message. It’s actually a series of messages that run one after the other then start over again. I shut down via

os.system("sudo shutdown now -P")

The screen would stop with a partial message on it. I would have to remove power to clear the screen. What I did was use a variable and put the command right at the end of my python file. It executes just when the last message finishes but hasn’t started over again. Pressing the joystick / button on the sense hat sets X to 0. Nothing happens though until it gets the end of the file. At that instant the screen is conveniently blank.

 if x == 0:
      os.system("sudo shutdown now -P")

Not sure that’s going to be of much help to you though?

In these cases I guess trapping and handling SIGTERM would be the “right” approach?

Worth a try, at least!

running = True

def handler(signum, frame):
    global running
    running = False

signal.signal(signal.SIGINT, handler)

while running:
    # Do stuff

# Clean up ( below while loop, so it executes when the loop exits )