galeb

Једноставна статичка дистрибуција заснована на musl-у
git clone https://git.sr.ht/~strahinja/galeb
Дневник | Датотеке | Референце | ПРОЧИТАЈМЕ | ЛИЦЕНЦА

rc.shutdown (1641B)


      1 #!/bin/sh
      2 
      3 umask 022
      4 
      5 . /etc/rc.conf
      6 . /lib/g_fun.sh
      7 
      8 PATH=/local/bin:/bin:/sucks/bin
      9 export PATH
     10 
     11 if [ "$(id -u)" -ne 0 ]; then
     12 	msg err "You must be root to run $0"
     13 	exit 2
     14 elif intmux; then
     15 	msg err "Exit tmux first"
     16 	exit 2
     17 fi
     18 
     19 prog=${0##*/}
     20 param=$1
     21 case ${prog} in
     22 	rc.shutdown)		;;
     23 	shutdown)		param=shutdown;;
     24 	poweroff)		param=poweroff;;
     25 	reboot)			param=reboot;;
     26 	*)			msg err "Unsupported symlink"
     27 				exit 1;;
     28 esac
     29 
     30 if [ "${param}" = "shutdown" ]; then
     31 	while getopts hpr opt; do
     32 		case ${opt} in
     33 			h)	msg err "-h is not supported"
     34 				exit 1;;
     35 			p)	param=poweroff;;
     36 			r)	param=reboot;;
     37 			?)	msg err "Unsupported option"
     38 				exit 1;;
     39 		esac
     40 	done
     41 fi
     42 
     43 case "${param}" in
     44 	reboot|poweroff)	;;
     45 	*)			msg err "Invalid action"
     46 				exit 1;;
     47 esac
     48 
     49 echo; stty onlcr
     50 
     51 msg info "Shutting down"
     52 
     53 msg info "Storing random seed"
     54 dd if=/dev/urandom of=/etc/random-seed count=1 bs=512 2>/dev/null
     55 
     56 env STATUSDELAY=${STATUSDELAY} \
     57 service stop all
     58 
     59 KILLDELAY=${KILLDELAY:-3}
     60 
     61 msg info "Sending processes the TERM signal..."
     62 killall5 -s TERM
     63 msg info "Waiting %ss" "${KILLDELAY}"
     64 sleep "${KILLDELAY}"
     65 msg info "Sending processes the KILL signal..."
     66 killall5 -s KILL
     67 
     68 msg info "Remounting / as read-only"
     69 # Don't need this if we are going for exclusively root-usable script
     70 #remountroot -q
     71 mount -o ro,remount / >/dev/null 2>&1
     72 
     73 msg info "Unmounting filesystems"
     74 # Don't need this if we are going for exclusively root-usable script
     75 #umountall -q
     76 umount -a >/dev/null 2>&1
     77 sync; sync; sync
     78 sleep 3
     79 wait
     80 
     81 msg info "Done rc.shutdown"
     82 
     83 case "${param}" in
     84 	reboot)		halt -r;;
     85 	poweroff)	halt -p;;
     86 	*)		msg err "Invalid parameter"
     87 			exit 1;;
     88 esac