Magellan Linux

Annotation of /alx-src/trunk/alxconfig-ng/init.d/alxsetstate

Parent Directory Parent Directory | Revision Log Revision Log


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

Properties

Name Value
svn:executable *