OpenMarine

Full Version: Shutdown and Power Off Delay
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I added a script to the Shut off text in /boot/firmware/config.txt per the process below.  This allows a delay to quietly close OpenCPN and Chromium.  Could this be automated and added to the options in "Raspberry Settings"

Use the Settings app, Raspberry Settings.  Set as below:
 
[attachment=3345]
 
After this do the following:
 
  1. Create a new script file:
Code:
sudo nano /usr/local/bin/custom_shutdown.sh
 
  1. 2.  Add the following content to the script:
 
Code:
#!/bin/bash

# Kill Chromium
pkill chromium

# Kill OpenCPN
pkill opencpn

# Wait for applications to close
sleep 5

# Shutdown the system
shutdown -h now

  1. 3. Make the script executable:
 
Code:
sudo chmod +x /usr/local/bin/custom_shutdown.sh

 
  1. 4. Modify the GPIO shutdown configuration to use your custom script. Edit the /boot/firmware/config.txt file:
 
Code:
sudo nano /boot/firmware/config.txt


  1. 5. Find the line that enables GPIO shutdown and modify it to use your custom script:
 
Code:
dtoverlay=gpio-shutdown,gpio_pin=21,active_low=1,gpio_pull=down,gpio_shutdown_command=/usr/local/bin/custom_shutdown.sh
OpenPlotter is already doing that running this service when a shutdown GPIO is defined in openplotter-settings: https://github.com/openplotter/openplott...hutdown.py

but your approach is very interesting. gpio_shutdown_command is not documented anywhere, where did you get it from?

Add -15 argument to your commands to make sure the configuration files are saved before exiting:

pkill -15 opencpn
(2025-03-21, 01:11 PM)Sailoog Wrote: [ -> ]OpenPlotter is already doing that running this service when a shutdown GPIO is defined in openplotter-settings: https://github.com/openplotter/openplott...hutdown.py

but your approach is very interesting. gpio_shutdown_command is not documented anywhere, where did you get it from?

Add -15 argument to your commands to make sure the configuration files are saved before exiting:

pkill -15 opencpn

Thanks for the '-15' I will add it, although, it seems like Openplotter has it covered - I didn't know that, I see your solution is only shutting down OCPN, could the feature request be to add more applications?  for me OCPN and Chromium is desirable, but is there a way to safely close all open applications before closing or have check boxes for common ones?

as for "gpio_shutdown_command is not documented anywhere, where did you get it from?" 

it must be somewhere... https://www.perplexity.ai/search/my-rasp...7nok1aA6Tg
We could add a loop to kill any running process, but that would be too aggressive because we might kill something that needs to run to completion. However, expanding the list of known applications to kill, in addition to OpenCPN, wouldn't hurt. It makes sense to close Chromium and Firefox, anything else?

I will investigate using gpio_shutdown_command for future versions of OP.
not sure if these have adverse effects if shutdown abruptly but, here are a few I can think of:

SKipper
the Grib viewer
qtVlm
I really need this because I always get the Chromium restore pages message on startup, when I just want it to go to the KIPdashboard I've set as a start page. I've followed your steps but it's not running the script at shutdown. The script works perfectly when run on it's own, so it's not getting triggered for some reason. I'm not good enough on Linus to troublehoot this either!

EDIT: I asked ChatGPT how to do this and it didn#t offer this workaround, so I'm unsure how else to do this.