Magellan Linux

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3481 - (hide annotations) (download)
Mon Apr 16 08:37:27 2012 UTC (12 years ago) by niro
File size: 3326 byte(s)
-removed unused variable
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 3480 local cur_ip cur_mac cur_mtime id
46 niro 221
47 niro 2141 rc_mecho "Register system to database"
48 niro 221
49 niro 3480 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     cur_mtime=$(date +%s)
52 niro 221
53     # validate current serial
54 niro 3480 if ! validate_serial "${ALX_SERIAL}" "${ALX_REG_DATE}" "${cur_mac}"
55 niro 221 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 3480 id=$(mysqldo "select serial from state_connected where serial=${ALX_SERIAL};")
66 niro 221
67 niro 3480 if [ -n "${id}" ]
68 niro 221 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 niro 3480 ip='${cur_ip}',
79     mac='${cur_mac}',
80 niro 221 state='${ALX_STATE}',
81 niro 3480 mtime='${cur_mtime}'
82 niro 221 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 niro 3480 '${cur_ip}',
103     '${cur_mac}',
104 niro 221 '${ALX_STATE}',
105 niro 3480 '${cur_mtime}'
106 niro 221 );"
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 3480 local cur_mac
117 niro 221
118 niro 3480 cur_mac=$(/sbin/ifconfig ${ALX_IFACE} | grep HWaddr | cut -d ' ' -f11)
119 niro 274
120 niro 2141 rc_mecho "Unregister system from database"
121 niro 221
122 niro 2123 # nice status
123     $CURS_UP
124     $SET_WCOL
125 niro 2141 rc_echo "[ SN: ${ALX_SERIAL} ]"
126    
127 niro 3480 mysqldo "delete from state_connected where serial='${ALX_SERIAL}' and mac='${cur_mac}';"
128 niro 221 evaluate_retval
129     }
130    
131 niro 347
132 niro 221 ########### starts here ################
133    
134 niro 347 # first of all get current system serial
135 niro 228 if [ -f /etc/alxconfig-ng/serial ]
136 niro 221 then
137 niro 228 source /etc/alxconfig-ng/serial
138 niro 221 else
139     ALX_SERIAL=0
140     fi
141    
142     case $1 in
143     start)
144 niro 283 # check if mysql server is reachable
145     # if not abort this script
146     reach_mysql_server || exit 1
147    
148 niro 221 set_current_network_state
149 niro 283 evaluate_retval
150 niro 221 ;;
151    
152     stop)
153 niro 283 # check if mysql server is reachable
154     # if not abort this script
155     reach_mysql_server || exit 1
156    
157 niro 221 unset_alx_connected
158 niro 283 evaluate_retval
159 niro 221 ;;
160     *)
161 niro 3479 rc_echo "Usage: $0 {start|stop} ..."
162 niro 221 ;;
163 niro 274 esac
164 niro 283

Properties

Name Value
svn:executable *