lfs-execline-scripts

Repository for execline scripts used in my linux-from-scratch builds
Log | Files | Refs

rc.shutdown (1486B)


      1 #!/usr/bin/execlineb -S1
      2 
      3 # creating new files
      4 # execline provides `posix-umask` and `execline-umask`
      5 # at the moment i just use posix but will change it if i am wrong
      6 posix-umask 022
      7 
      8 # getting env vars
      9 envfile /etc/rc.conf
     10 
     11 # there's probably a more elegant way to do this but this is all i got :shrug:
     12 case -N -- $1
     13 {
     14   "reboot" {}
     15   "poweroff" {}
     16 } 
     17 # default case
     18 { foreground { printf "Invalid option '%s' for %s" $1 $0 } exit 1 }
     19 
     20 # set linefeed mode to avoid staircase effect
     21 foreground { echo }
     22 foreground { /bin/stty onclr }
     23 
     24 background { printf "Shutting down...\n" }
     25 
     26 # save system clock
     27 foreground { svc -k hwclock }
     28 
     29 background { /bin/printf "Storing random seed...\n" }
     30 
     31 foreground { redirfd -w 2 /dev/null { /bin/dd if=/dev/urandom of=/etc/random-seed count=1 bs=512 } }
     32 
     33 background { /bin/printf "Stopping all svc services...\n" }
     34 foreground { /bin/svc -k }
     35 
     36 background { /bin/printf "Sending TERM to all processes...\n" }
     37 foreground { /bin/killall5 -s TERM }
     38 foreground { sleep 2 }
     39 
     40 background { /bin/printf "Sending KILL to all processes...\n" }
     41 foreground { /bin/killall5 -s KILL }
     42 
     43 background { /bin/printf "Remounting / as read-only...\n" }
     44 foreground { /bin/mount -o remount,ro / }
     45 
     46 background { /bin/printf "Unmounting all fs'es...\n" }
     47 foreground { /bin/umount -a }
     48 foreground { /bin/sync }
     49 foreground { /bin/sleep 2 }
     50 foreground { wait {} }
     51 
     52 background { /bin/printf "BYE BYE!!! \n" }
     53 case -N -- $1
     54 {
     55   "reboot" { /bin/halt -r }
     56   "poweroff" { /bin/halt -p }
     57 }