Page 1 of 1

Run a script or command during shutdown

Posted: Mon Jan 21, 2019 4:03 pm
by rownie23
Hello, this is my first post here and I'm very to new to Raspberry Pi so please bear with me if I'm asking something simple.

Basically, it's like this:
The application I'm using my Raspberry Pi on needs to issue a command "killall -9 erni" to ensure that particular process is stopped before the safe shut down completes and the SD card is protected as per usual.

Is this something that can be done? Any pointers would be very appreciated!

Thanks! :)

Re: Run a script or command during shutdown

Posted: Wed Jan 23, 2019 9:17 am
by Dave
rownie23 wrote:
Mon Jan 21, 2019 4:03 pm
Hello, this is my first post here and I'm very to new to Raspberry Pi so please bear with me if I'm asking something simple.

Basically, it's like this:
The application I'm using my Raspberry Pi on needs to issue a command "killall -9 erni" to ensure that particular process is stopped before the safe shut down completes and the SD card is protected as per usual.

Is this something that can be done? Any pointers would be very appreciated!

Thanks! :)
You can just chain the two commands together into a single line using the semi-colon ;

Code: Select all

sudo sh -c "killall -9 erni ; shutdown -h now"

Re: Run a script or command during shutdown

Posted: Mon Feb 11, 2019 10:52 am
by rownie23
Thank you for the response, I'm pleased to hear that it can be done. But how do I get a script to run when the PIco UPS starts to safely shutdown?

Re: Run a script or command during shutdown

Posted: Wed Feb 13, 2019 9:27 am
by Dave
You can edit the fssd script

Code: Select all

PiModules\code\python\upspico\picofssd\build\scripts-2.7\picofssd
You should be able to find the shutdown command within the script

Code: Select all

        if not GPIO.input(PULSE_PIN):
            # pin is low, this is shutdown signal from pico
            self.counter += 1
            self.log.warning("Lost power supply, Pi will shutdown")
            self.alert_email()
            time.sleep(2)
            os.system('/sbin/shutdown -h now')

Code: Select all

os.system('/sbin/shutdown -h now')
You can then add your command just before it