source: pkg/main/initscripts-parsix-live/trunk/debian/live-reboot.init @ 2544

Revision 2544, 3.9 KB checked in by alanbach-guest, 6 years ago (diff)
  • Trying to fix final eject problem
Line 
1#!/bin/sh
2### BEGIN INIT INFO
3# Provides: live-reboot
4# Required-Start:   
5# Required-Stop:       
6# Default-Start:     
7# Default-Stop:     
8# Short-Description: halt/reboot service
9# Description: Halt/Reboot Service for Parsix
10### END INIT INFO
11
12PATH=/sbin:/bin:/usr/bin:/usr/sbin
13export PATH
14
15# override tool behaviour through distro-defaults
16FLL_DISTRO_MODE="installed"
17FLL_DISTRO_NAME="PARSIX"
18
19#[ -r /etc/default/distro ] && . /etc/default/distro
20#FLL_DISTRO_NAME="$(echo $FLL_DISTRO_NAME | tr [a-z] [A-Z])"
21
22[ ! "$FLL_DISTRO_MODE" = "live" ] && exit 0
23
24case "$1" in
25        start)
26                ;;
27        stop)
28                ;;
29        restart|force-reload)
30                ;;
31esac
32
33# Clean input/output
34exec > /dev/console 2>&1 < /dev/console
35
36NORMAL="[0;39m"
37RED="[1;31m"
38GREEN="[1;32m"
39YELLOW="[1;33m"
40BLUE="[1;34m"
41MAGENTA="[1;35m"
42CYAN="[1;36m"
43WHITE="[1;37m"
44
45case "$0" in
46        *halt)
47                message="${YELLOW}${FLL_DISTRO_NAME} halted.${NORMAL}"
48                command="halt"
49                options="-p -d -i -f"
50                ;;
51        *reboot)
52                message="${GREEN}Preparing for reboot...${NORMAL}"
53                command="reboot"
54                options="-d -i -f"
55                ;;
56        *)
57                echo "$0: call this script as \"halt\" or \"reboot\" please!"
58                exit 1
59                ;;
60esac
61
62# No sync and no wtmp entry if running from CD
63options="$options -n"
64
65mysleep()
66{
67        for i in $(seq 1 40); do
68                sleep "0.075s"
69                echo -n "$1.${NORMAL}"
70        done
71        echo ""
72}
73
74# Disable kernel messages
75echo "0" > /proc/sys/kernel/printk
76
77# poweroff pcmcia devices
78if lsmod | grep -q pcmcia_core 2>&1 > /dev/null; then
79        echo -n "${BLUE}Shutting down PCMCIA devices...${NORMAL}"
80        pccardctl eject 2>&1 > /dev/null
81        sleep 2
82        echo ""
83fi
84
85# Now kill them all
86killall5 -15
87sleep 1
88echo -n "${BLUE}Sent all processes the TERM signal...${NORMAL}"
89mysleep "$BLUE"
90
91killall5 -9
92sleep 1
93echo -n "${RED}Sent all processes the KILL signal...${NORMAL}"
94mysleep "$RED"
95
96# Unmount network filesystems first before shutting down network
97NETMOUNTS="$(awk '{if($1~/:/){print $2}}' /proc/mounts 2> /dev/null)"
98if [ -n "$NETMOUNTS" ]; then
99        echo "${BLUE}Unmounting network filesystems.${NORMAL}"
100        umount -t nfs -arvf 2> /dev/null
101fi
102
103# Shutdown network
104NETDEVICES="$(awk -F: '/ath.:|eth.:|tr.:|wlan.:/{print $1}' /proc/net/dev 2>/dev/null)"
105if [ -n "$NETDEVICES" ]; then
106        pidof pump 2>&1 > /dev/null && { pump -k ; sleep 2; }
107        echo -n "${BLUE}Shutting down network device${NORMAL}"
108        for n in $NETDEVICES; do
109                echo -n " ${MAGENTA}$n${NORMAL}"
110                ifconfig "$n" down
111        done
112        echo ""
113fi
114
115# read cmdline params
116NOEJECT=""
117NOPROMPT=""
118read CMDLINE <<EOT
119$(cat /proc/cmdline 2> /dev/null)
120EOT
121case "$CMDLINE" in *noeject*)  NOEJECT="yes";  ;; esac
122case "$CMDLINE" in *noprompt*) NOPROMPT="yes"; ;; esac
123
124CDROM="$(awk '/ \/cdrom /{print $1;exit 0;}' /proc/mounts)"
125
126# This uses standard sysvinit
127FINALCMD="/etc/live-hack/$command"
128rm -rf /etc/live-hack 2>&1 > /dev/null
129mkdir -p /etc/live-hack
130[ -x "/etc/live-hack/$command" ]  || cp -p "/sbin/$command" /etc/live-hack/
131[ -x /usr/bin/eject ]             && cp -p /usr/bin/eject /etc/live-hack/eject
132LD_LINUX=ld-linux.so.2
133[ -x /lib/ld-linux-x86-64.so.2 ]  && LD_LINUX=ld-linux-x86-64.so.2
134[ -x "/etc/live-hack/$LD_LINUX" ] || cp -p "/lib/$LD_LINUX" /etc/live-hack/
135
136# Turn off swap, then unmount file systems.
137swapoff -a 2>&1 > /dev/null
138
139echo "${BLUE}Unmounting file systems.${NORMAL}"
140
141cd /
142
143# Umount everything but root
144umount -arvf 2> /dev/null
145if [ "$?" != "0" ] ; then
146        # Free loopback devices if necessary, so we can unmount the host media
147        for i in /dev/loop*; do losetup -d "$i" 2> /dev/null; done
148        # And retry
149        umount -arf 2> /dev/null
150fi
151
152# Remove remaining unused modules
153rmmod -a 2>&1 > /dev/null
154
155echo "$message" > /dev/console
156
157# eject CD-ROM, noprompt implies noeject (backward compatibility)
158if [ -z "$NOPROMPT" ]; then
159        [ -n "$CDROM" -a -z "$NOEJECT" ] && "/etc/live-hack/$LD_LINUX" /etc/live-hack/eject -m -p "$CDROM" 2>&1 >/dev/null
160        echo "${CYAN}Please remove CD, close cdrom drive and hit return.${NORMAL}"
161        read
162fi
163
164# Now halt or reboot.
165exec "/etc/live-hack/$LD_LINUX" "$FINALCMD" $options > /dev/console 2>&1 < /dev/console
166
Note: See TracBrowser for help on using the repository browser.