General TC > General TC Talk

Run a script as the last thing during shutdown

(1/2) > >>

gilphilbert:
Long time user, first actual post!

I will be executing exitcheck.sh as part of a service that will bring down a Tiny Core system. Once the system is safely down (file systems unmounted, etc.) I want to execute a couple of commands before the actual power down - essentially to send a GPIO message - as the absolute last thing that happens.

I've been studying /opt/shutdown.sh and /etc/init.d/rc.shutdown but I can't work out what happens after them. Since TC is BusyBox, I know there are no standard runlevels, so I can't use /etc/rc.0 for example. Can anyone help with how I can run a script as the very last thing to happen?

Thanks!

Rich:
Hi gilphilbert
Welcome to the forum.

I think the sequence of events is:
exitcheck.sh poweroff -> /opt/shutdown.sh -> /sbin/poweroff -> /etc/inittab -> /etc/init.d/rc.shutdown


--- Quote from: gilphilbert on August 09, 2021, 12:26:57 AM --- ... Once the system is safely down (file systems unmounted, etc.) I want to execute a couple of commands before the actual power down - essentially to send a GPIO message - as the absolute last thing that happens. ...
--- End quote ---
I think that might not work. Where will you load the commands from if all of the file systems are unmounted?

gilphilbert:

--- Quote from: Rich on August 09, 2021, 01:43:42 AM ---I think the sequence of events is:
exitcheck.sh poweroff -> /opt/shutdown.sh -> /sbin/poweroff -> /etc/inittab -> /etc/init.d/rc.shutdown

--- End quote ---
Is it acceptable to have an extension modify those scripts? I'm new to creating my own extensions and I'm trying to work out what's deemed "acceptable" for an extension to do. I'm guessing I would have to add my command to /etc/init.d/rc.shutdown and make sure that script is added to /opt/filetool.lst so the changes are persisted.


--- Quote from: Rich on August 09, 2021, 01:43:42 AM ---
--- Quote from: gilphilbert on August 09, 2021, 12:26:57 AM --- ... Once the system is safely down (file systems unmounted, etc.) I want to execute a couple of commands before the actual power down - essentially to send a GPIO message - as the absolute last thing that happens. ...
--- End quote ---
I think that might not work. Where will you load the commands from if all of the file systems are unmounted?

--- End quote ---
OK, that was stupid, I accept that  :)

curaga:
That would be out of line for an extension in the repo, but for your private ones, anything goes. Though for modifying base scripts, the preferred method is remastering (or adding another initrd, if your bootloader supports that).

Rich:
Hi gilphilbert

--- Quote from: gilphilbert on August 10, 2021, 03:42:17 AM ---Is it acceptable to have an extension modify those scripts? ...
--- End quote ---
For an extension you intend to submit to Tinycore, I would say no.
For a personal extension, sure. Tinycore is a toolkit you can modify to fit your needs.


--- Quote --- ... I'm guessing I would have to add my command to /etc/init.d/rc.shutdown ...
--- End quote ---
You could, but where would you place your commands?  rc.shutdown  goes something like this:

--- Code: ---1. Sync filesystems                        # No problems here.
2. Disable swap space                      # No problems here.
3. Kill all processes                      # Maybe a problems here, could kill a needed daemon.
4. Unmount all extensions                  # Problem if your commands will depend on an extension.
5. Delete extensionssions being updated    # Problem if your commands will depend on those extensions.
6. Unmount tce directory                   # Problem if your commands will depend on the tce directory.
7. Unmount backup directory                # Problem if your commands will depend on the backup directory.
8. Unmount everything else                 # Problem, no place to run commands from.
--- End code ---


--- Quote from: Rich on August 09, 2021, 01:43:42 AM ---exitcheck.sh poweroff -> /opt/shutdown.sh -> /sbin/poweroff -> /etc/inittab -> /etc/init.d/rc.shutdown
--- End quote ---
poweroff  basically just tells  inittab  to run  rc.shutdown, so you can ignore those 2.

I would use  /opt/shutdown.sh  because it's already included in your backup and that's what it's there for.
Place this at the end of  /opt/shutdown.sh:

--- Code: ---sync
--- End code ---

--- Code: ---sleep 1
--- End code ---

--- Code: ---sync
--- End code ---
This will force all writes to storage devices to complete. Then place your commands after that.


--- Quote from: gilphilbert on August 10, 2021, 03:42:17 AM --- ... OK, that was stupid, I accept that
--- End quote ---
Not really, considering the context:

--- Quote from: gilphilbert on August 09, 2021, 12:26:57 AM --- ... Once the system is safely down (file systems unmounted, etc.) ...
--- End quote ---
The first thing that comes to mind is data preservation, not can I still run a command.

Navigation

[0] Message Index

[#] Next page

Go to full version