Debian Codegraph @

Install/avr-evtd.init

raw
1 #!/bin/sh
2 #
3 # avr-evtd Linkstation/Kuro AVR daemon
4 #
5 # Files used:
6 # /etc/default/avr-evtd file with defaults for this script
7 # /etc/avr-evtd/EventScript script with emergency mode actions
8 #
9 # Optional files:
10 # /etc/melco/timer_Sleep Standard Melco sleep settings
11 #
12 # Copyright © 2006 Bob Perry <[email protected]>
13 # Copyright © 2008-2010 Rogério Brito <[email protected]>
14 #
15
16 ### BEGIN INIT INFO
17 # Provides: avr-evtd
18 # Required-Start: $remote_fs $syslog
19 # Required-Stop: $remote_fs $syslog
20 # Default-Start: 2 3 4 5
21 # Default-Stop: 0 1 6
22 # Short-Description: Linkstation/Kurobox AVR watchdog daemon
23 ### END INIT INFO
24
25 PATH=/bin:/sbin:/usr/bin:/usr/sbin
26
27 NAME=avr-evtd
28 DAEMON=/usr/sbin/$NAME
29 DESC="AVR watchdog daemon"
30 tag=linkstation
31 facility=user.info
32
33 test -x $DAEMON || exit 0
34 . /lib/lsb/init-functions
35
36 if [ -f /etc/default/$NAME ]; then
37 . /etc/default/$NAME
38 fi
39
40 determine_device()
41 {
42 # Accept the device specified by the system administrator, if set.
43 [ ! -z "$DEVICE" ] && return
44
45 # For MIPS, the situation is simpler: just use /dev/ttyS0 as the UART.
46 # For PowerPC, we need to know which, between ttyS0 or ttyS1 is attached
47 # to port address 0x80004500 and use that.
48 DEVICE=/dev/ttyS0
49 if uname -m | grep -q mips; then
50 MIPS=YES
51 else
52 MIPS=NO
53 PORT_ADDRESS=$($DAEMON -i -d /dev/ttyS1)
54 if [ -n "$PORT_ADDRESS" ] && [ "$PORT_ADDRESS" = "0x80004500" ]; then
55 DEVICE=/dev/ttyS1
56 fi
57 fi
58 }
59
60 start()
61 {
62 # Cumulative string of options to be passed to the daemon
63 # (e.g -d /dev/ttyS1)
64 DAEMONOPTS=""
65
66 CONSOLE=OFF
67
68 determine_device
69
70 # Initialize according to configurations
71 if [ "$EMMODE" = "YES" ]; then
72 DAEMONOPTS=-e
73 fi
74
75 if [ -n "$DEVICE" ] && [ "$MIPS" = "NO" ]; then
76 DAEMONOPTS="$DAEMONOPTS -d $DEVICE"
77 fi
78
79 # If this is a MIPSEL box, then determine if console ttyS0 is in use
80 if [ "$MIPS" = "YES" ] && [ -e /proc/linkstation ]; then
81 CONSOLE=$(grep CONSOLE < /proc/linkstation | cut -d = -f 2)
82 fi
83
84 if [ "$CONSOLE" = "ON" ]; then
85 log_warning_msg "avr-evtd: Not started services as console in-use"
86 logger -t $tag -p $facility -i "Not started avr-evtd as kernel still has console"
87 else
88 log_daemon_msg "Starting $DESC " "$NAME"
89 start-stop-daemon --start --quiet --exec $DAEMON -- $DAEMONOPTS
90 log_end_msg $?
91 logger -t $tag -p $facility -i "Started daemon avr-evtd"
92 fi
93 }
94
95 stop()
96 {
97 determine_device
98
99 # Determine run-level and respond accordingly
100 # Speed-up fan at exit for an extra chill.
101 if [ -n "$RUNLEVEL" ] && [ -n "$DEVICE" ]; then
102 if [ "$RUNLEVEL" -eq 6 ]; then
103 # Send AVR the reboot signal
104 echo -n "]]]]CCCC" > $DEVICE
105 elif [ "$RUNLEVEL" -eq 0 ]; then
106 # Send AVR the shutdown signal
107 echo -n "]]]]EEEE" > $DEVICE
108 fi
109 fi
110
111 log_daemon_msg "Stopping $DESC" "$NAME"
112 start-stop-daemon --stop --quiet --exec $DAEMON
113 log_end_msg $?
114 logger -t $tag -p $facility -i 'Stopped daemon avr-evtd'
115 }
116
117 # Check request
118 case "$1" in
119 start)
120 start
121 ;;
122 stop)
123 stop
124 ;;
125 restart|force-reload)
126 stop
127 sleep 1
128 start
129 ;;
130 *)
131 echo "Usage: $DAEMON {start|stop|restart|force-reload}" >&2
132 exit 1
133 ;;
134 esac
135
136 exit 0