Magellan Linux

Contents of /alx-src/branches/alxconf-060/init.d/alxsetstate

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2007 - (show annotations) (download)
Mon May 9 15:31:56 2011 UTC (12 years, 11 months ago) by niro
File size: 3259 byte(s)
-busybox-initscripts compat
1 #!/bin/bash
2 # $Id$
3
4 #%rlevels: 3:s 0:k
5 #%start: 99
6 #%stop: 01
7
8 #deps
9 #%needs:
10 #%before:
11 #%after:
12
13 source /etc/conf.d/rc
14 source $rc_functions
15
16 # mysql settings
17 source /etc/alxconfig-ng/config.rc
18 source /usr/lib/alxconfig-ng/functions/mysqlfunctions
19 source /usr/lib/alxconfig-ng/functions/serial_functions
20
21 # unset vars which may kill us
22 unset ALX_SERIAL ALX_STATE ALX_IFACE
23
24 # get current system state
25 if [ -f /etc/alxconfig-ng/state/state ]
26 then
27 source /etc/alxconfig-ng/state/state
28 else
29 ALX_STATE=error
30 fi
31
32 if [ -f ${SETTINGSPATH}/confd-networking ]
33 then
34 ALX_IFACE="$(< ${SETTINGSPATH}/confd-networking)"
35 fi
36 [[ -z ${ALX_IFACE} ]] && export ALX_IFACE=eth0
37
38 # need to put this to an extra init script which will be
39 # executed when the real network is up and not the preliminary.
40 # nice name is alx_connected_state or sth like this
41 set_current_network_state()
42 {
43 local CUR_IP CUR_MAC ID
44
45 echo -e ${COLMAGENTA}"Register system to database"${COLDEFAULT}
46
47 CUR_IP=$(/sbin/ifconfig ${ALX_IFACE} | sed -n '/addr:/s/ [^r]*..//gp')
48 CUR_MAC=$(/sbin/ifconfig ${ALX_IFACE} | grep HWaddr | cut -d ' ' -f11)
49 CUR_MTIME=$(date +%s)
50
51 # validate current serial
52 if ! validate_serial "${ALX_SERIAL}" "${ALX_REG_DATE}" "${CUR_MAC}"
53 then
54 # abort on non valid serial
55 ALX_STATE="invalid serial"
56 echo "ALX_STATE=\"${ALX_STATE}\"" > /etc/alxconfig-ng/state/state
57 show_invalid_serial_msg
58 exit 1
59 fi
60
61 # first check if an entry exist with my serial
62 # if it exist update this entry else insert a new one
63 ID=$(mysqldo "select serial from state_connected where serial=${ALX_SERIAL};")
64
65 if [ -n "${ID}" ]
66 then
67 # run an update
68
69 # nice status
70 $CURS_UP
71 $SET_WCOL
72 echo "[ U, State: ${ALX_STATE} ]"
73
74 mysqldo "update state_connected set
75 hostname='${HOSTNAME}',
76 ip='${CUR_IP}',
77 mac='${CUR_MAC}',
78 state='${ALX_STATE}',
79 mtime='${CUR_MTIME}'
80 where serial=${ALX_SERIAL};"
81 else
82 # run an insert
83
84 # nice status
85 $CURS_UP
86 $SET_WCOL
87 echo "[ N, State: ${ALX_STATE} ]"
88
89 mysqldo "insert into state_connected(
90 serial,
91 hostname,
92 ip,
93 mac,
94 state,
95 mtime
96 )
97 values(
98 '${ALX_SERIAL}',
99 '${HOSTNAME}',
100 '${CUR_IP}',
101 '${CUR_MAC}',
102 '${ALX_STATE}',
103 '${CUR_MTIME}'
104 );"
105 fi
106 }
107
108
109 # need to put this to an extra init script which will
110 # be executed first when the system is going down.
111 # nice name is alx_connected_state or sth like this
112 unset_alx_connected()
113 {
114 local SQL_OPTS
115 local CUR_MAC
116
117 CUR_MAC=$(/sbin/ifconfig ${ALX_IFACE} | grep HWaddr | cut -d ' ' -f11)
118
119 echo -e ${COLMAGENTA}"Unregister system from database"${COLDEFAULT}
120
121 mysqldo "delete from state_connected where serial='${ALX_SERIAL}' and mac='${CUR_MAC}';"
122 evaluate_retval
123 }
124
125
126 ########### starts here ################
127
128 # first of all get current system serial
129 if [ -f /etc/alxconfig-ng/serial ]
130 then
131 source /etc/alxconfig-ng/serial
132 else
133 ALX_SERIAL=0
134 fi
135
136 case $1 in
137 start)
138 # check if mysql server is reachable
139 # if not abort this script
140 reach_mysql_server || exit 1
141
142 set_current_network_state
143 evaluate_retval
144 ;;
145
146 stop)
147 # check if mysql server is reachable
148 # if not abort this script
149 reach_mysql_server || exit 1
150
151 unset_alx_connected
152 evaluate_retval
153 ;;
154 *)
155 echo "Usage: $0 {start|stop} ..."
156 ;;
157 esac
158

Properties

Name Value
svn:executable *