Magellan Linux

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2123 - (hide annotations) (download)
Mon May 16 11:16:58 2011 UTC (13 years ago) by niro
File size: 3352 byte(s)
-be more informative in the status messages
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     source /usr/lib/alxconfig-ng/functions/mysqlfunctions
19     source /usr/lib/alxconfig-ng/functions/serial_functions
20 niro 221
21 niro 347 # unset vars which may kill us
22     unset ALX_SERIAL ALX_STATE ALX_IFACE
23 niro 221
24 niro 347 # get current system state
25 niro 228 if [ -f /etc/alxconfig-ng/state/state ]
26 niro 221 then
27 niro 228 source /etc/alxconfig-ng/state/state
28 niro 221 else
29     ALX_STATE=error
30     fi
31    
32 niro 370 if [ -f ${SETTINGSPATH}/confd-networking ]
33     then
34     ALX_IFACE="$(< ${SETTINGSPATH}/confd-networking)"
35     fi
36 niro 347 [[ -z ${ALX_IFACE} ]] && export ALX_IFACE=eth0
37    
38 niro 221 # 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 niro 347 set_current_network_state()
42     {
43 niro 221 local CUR_IP CUR_MAC ID
44    
45     echo -e ${COLMAGENTA}"Register system to database"${COLDEFAULT}
46    
47 niro 347 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 niro 221 CUR_MTIME=$(date +%s)
50    
51     # validate current serial
52     if ! validate_serial "${ALX_SERIAL}" "${ALX_REG_DATE}" "${CUR_MAC}"
53     then
54 niro 306 # abort on non valid serial
55 niro 221 ALX_STATE="invalid serial"
56 niro 1624 echo "ALX_STATE=\"${ALX_STATE}\"" > /etc/alxconfig-ng/state/state
57 niro 306 show_invalid_serial_msg
58     exit 1
59 niro 221 fi
60    
61 niro 347 # first check if an entry exist with my serial
62 niro 221 # if it exist update this entry else insert a new one
63 niro 347 ID=$(mysqldo "select serial from state_connected where serial=${ALX_SERIAL};")
64 niro 221
65     if [ -n "${ID}" ]
66     then
67 niro 347 # run an update
68 niro 221
69 niro 347 # nice status
70 niro 221 $CURS_UP
71     $SET_WCOL
72 niro 2123 echo "[ SN: ${ALX_SERIAL}, U, ${ALX_STATE} ]"
73 niro 221
74 niro 347 mysqldo "update state_connected set
75 niro 221 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 niro 347 # run an insert
83 niro 221
84 niro 347 # nice status
85 niro 221 $CURS_UP
86     $SET_WCOL
87 niro 2123 echo "[ SN: ${ALX_SERIAL}, N, ${ALX_STATE} ]"
88 niro 221
89 niro 347 mysqldo "insert into state_connected(
90 niro 221 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 niro 347 unset_alx_connected()
113     {
114 niro 221 local SQL_OPTS
115 niro 274 local CUR_MAC
116 niro 221
117 niro 347 CUR_MAC=$(/sbin/ifconfig ${ALX_IFACE} | grep HWaddr | cut -d ' ' -f11)
118 niro 274
119 niro 221 echo -e ${COLMAGENTA}"Unregister system from database"${COLDEFAULT}
120    
121 niro 2123 # nice status
122     $CURS_UP
123     $SET_WCOL
124     echo "[ SN: ${ALX_SERIAL} ]"
125    
126 niro 347 mysqldo "delete from state_connected where serial='${ALX_SERIAL}' and mac='${CUR_MAC}';"
127 niro 221 evaluate_retval
128     }
129    
130 niro 347
131 niro 221 ########### starts here ################
132    
133 niro 347 # first of all get current system serial
134 niro 228 if [ -f /etc/alxconfig-ng/serial ]
135 niro 221 then
136 niro 228 source /etc/alxconfig-ng/serial
137 niro 221 else
138     ALX_SERIAL=0
139     fi
140    
141     case $1 in
142     start)
143 niro 283 # check if mysql server is reachable
144     # if not abort this script
145     reach_mysql_server || exit 1
146    
147 niro 221 set_current_network_state
148 niro 283 evaluate_retval
149 niro 221 ;;
150    
151     stop)
152 niro 283 # check if mysql server is reachable
153     # if not abort this script
154     reach_mysql_server || exit 1
155    
156 niro 221 unset_alx_connected
157 niro 283 evaluate_retval
158 niro 221 ;;
159     *)
160     echo "Usage: $0 {start|stop} ..."
161     ;;
162 niro 274 esac
163 niro 283

Properties

Name Value
svn:executable *