qLinux
… a distribution study


<< Prev
Setup the Boot Process

Next >>
Linux-5.10.85


Setup the Shutdown Process

Lets quick recover how  sinit  works. It runs with pid 1 and waits for a SIGINT ( reboot ) or a SIGUSR1 signal ( poweroff ). If  sinit  receives one of these signals, it calls  /qlnx/bin/shutdown 1) with the corresponding parameter.

Create the file  /qlnx/bin/shutdown  to manage the shutdown process:

cat > /qlnx/bin/shutdown << EOF
#!/qlnx/bin/sh
 
PATH="/qlnx/bin"
 
MODE="R"; [ "$1" = "poweroff" ] && MODE="P"
 
echo Shutting down for $1 now ...
 
echo "Shutting down services ..."
svc -dx /qlnx/etc/init.d/svc.boot/*
 
echo "Sending all processes the term signal ..."
killall5
 
echo "Unmounting filesystems ..."
umount /qlnx/dev/pts
umount /qlnx/dev/shm
#umount /qlnx/dev
#umount /qlnx/sys
swapoff -a
 
echo "Remounting remaining filesystems read-only ..."
mount -o remount,ro /qlnx/dev
mount -o remount,ro /qlnx/run
mount -o remount,ro /qlnx/prc
mount -o remount,ro /qlnx/sys
mount -o remount,ro /
 
[ "$MODE" = "P" ] && /qlnx/bin/libexec/halt -p
/qlnx/bin/libexec/halt -r
EOF

The used tools  halt  and  killall5  are from Ubase-0.1 package. Otherwise the file should be self explaining. There are some commands which doesn't have effect right now, but this does no harm. Make the file executable:

chmod 0750 /qlnx/bin/shutdown

To make the usage of  /qlnx/bin/shutdown  a bit more comfortable we create 2 files to send sinit a SIGINT (again: reboot) or a SIGUSR1 (again: poweroff) signal:

cat > /qlnx/bin/reboot << EOF 
# send sinit (pid 1) a INT signal -> reboot
kill -s SIGINT 1
EOF
cat > /qlnx/bin/poweroff << EOF
# send sinit (pid 1) a SIGUSR1 signal -> poweroff
kill -s SIGUSR1 1
EOF

Make both files executable:

chmod 0750 /qlnx/bin/poweroff /qlnx/bin/reboot

<< Prev
Setup the Boot Process

Next >>
Linux-5.10.85

1)
or whatever name was configured during the installation of sinit