Binding powerdown script to ctrl-alt-del for headless shutdown

From unRAID
Jump to: navigation, search

This script binds /sbin/powerdown to ctrl-alt-del in /etc/inittab upon startup. It's used for those who run headless and want to shutdown in an emergency. It's not necessary, but it helps in a pinch

Put this on your flash in /boot/custom/etc/rc.d as S30-inittab-powerdown Edit your /boot/config/go script and add fromdos < /boot/custom/etc/rc.d/S30-inittab-powerdown | sh


Example

#!/bin/bash
# Start the Management Utility
/usr/local/sbin/emhttp &
fromdos < /boot/custom/bin/powerdown > /sbin/powerdown
chmod u+x /sbin/powerdown
fromdos < /boot/custom/etc/rc.d/S30-inittab-powerdown | sh 


/boot/custom/etc/rc.d/S30-inittab-powerdown

#!/bin/bash

COMMAND=/sbin/powerdown
SRC_COMMAND=/boot/custom/bin/powerdown
INSTALL=1

if [ ${DEBUG:=0} -gt 0 ]
   then set -x -v
fi

if [ -f ${SRC_COMMAND} -a ! -f ${COMMAND} -a "${INSTALL:=0}" -gt 0 ]
   then fromdos < ${SRC_COMMAND} > ${COMMAND}
        chmod u=rwx ${COMMAND}
fi

if [ -x ${COMMAND} ];then
   if ! grep "${COMMAND}" /etc/inittab > /dev/null ; then
      grep -v 'ca::ctrlaltdel:/sbin/shutdown' < /etc/inittab > /etc/inittab.tmp
      echo "ca::ctrlaltdel:/sbin/powerdown" >> /etc/inittab.tmp
      mv /etc/inittab.tmp /etc/inittab
      /sbin/telinit q
   fi
fi

sysctl -w kernel.poweroff_cmd="/sbin/powerdown"