Annotation of /alx-src/branches/alxconf_20060908/init.d/alxsetstate
Parent Directory | Revision Log
Revision 375 -
(hide annotations)
(download)
Mon Feb 20 14:49:31 2006 UTC (18 years, 7 months ago) by (unknown author)
Original Path: alx-src/tags/alxconf_20060908_1/alxconfig-ng/init.d/alxsetstate
File size: 3484 byte(s)
Mon Feb 20 14:49:31 2006 UTC (18 years, 7 months ago) by (unknown author)
Original Path: alx-src/tags/alxconf_20060908_1/alxconfig-ng/init.d/alxsetstate
File size: 3484 byte(s)
This commit was manufactured by cvs2svn to create tag 'alxconf_20060908_1'.
1 | niro | 221 | #!/bin/bash |
2 | |||
3 | #%rlevels: 3:s 4:s 5:s 0:k 6:k | ||
4 | #%start: 99 | ||
5 | #%stop: 01 | ||
6 | |||
7 | #deps | ||
8 | #%needs: | ||
9 | #%before: | ||
10 | #%after: | ||
11 | |||
12 | niro | 370 | # $Header: /home/cvsd/alx-cvs/alx-src/alxconfig-ng/init.d/alxsetstate,v 1.10 2005-10-26 11:57:00 niro Exp $ |
13 | niro | 222 | |
14 | niro | 221 | source /etc/sysconfig/rc |
15 | source $rc_functions | ||
16 | |||
17 | niro | 347 | # mysql settings |
18 | niro | 226 | source /etc/alxconfig-ng/config.rc |
19 | source /usr/lib/alxconfig-ng/functions/mysqlfunctions | ||
20 | source /usr/lib/alxconfig-ng/functions/serial_functions | ||
21 | niro | 221 | |
22 | niro | 347 | # check if mysql is available |
23 | niro | 221 | [ -x /usr/bin/mysql ] && MYSQL_ALX=true |
24 | |||
25 | niro | 347 | # other needed vars |
26 | niro | 221 | ALX_HW_DETECT=false |
27 | |||
28 | niro | 347 | # unset vars which may kill us |
29 | unset ALX_SERIAL ALX_STATE ALX_IFACE | ||
30 | niro | 221 | |
31 | niro | 347 | # get current system state |
32 | niro | 228 | if [ -f /etc/alxconfig-ng/state/state ] |
33 | niro | 221 | then |
34 | niro | 228 | source /etc/alxconfig-ng/state/state |
35 | niro | 221 | else |
36 | ALX_STATE=error | ||
37 | fi | ||
38 | |||
39 | niro | 370 | if [ -f ${SETTINGSPATH}/confd-networking ] |
40 | then | ||
41 | ALX_IFACE="$(< ${SETTINGSPATH}/confd-networking)" | ||
42 | fi | ||
43 | niro | 347 | [[ -z ${ALX_IFACE} ]] && export ALX_IFACE=eth0 |
44 | |||
45 | niro | 221 | # need to put this to an extra init script which will be |
46 | # executed when the real network is up and not the preliminary. | ||
47 | # nice name is alx_connected_state or sth like this | ||
48 | niro | 347 | set_current_network_state() |
49 | { | ||
50 | niro | 221 | local CUR_IP CUR_MAC ID |
51 | |||
52 | echo -e ${COLMAGENTA}"Register system to database"${COLDEFAULT} | ||
53 | |||
54 | niro | 347 | CUR_IP=$(/sbin/ifconfig ${ALX_IFACE} | sed -n '/addr:/s/ [^r]*..//gp') |
55 | CUR_MAC=$(/sbin/ifconfig ${ALX_IFACE} | grep HWaddr | cut -d ' ' -f11) | ||
56 | niro | 221 | CUR_MTIME=$(date +%s) |
57 | |||
58 | # validate current serial | ||
59 | if ! validate_serial "${ALX_SERIAL}" "${ALX_REG_DATE}" "${CUR_MAC}" | ||
60 | then | ||
61 | niro | 306 | # abort on non valid serial |
62 | niro | 221 | ALX_STATE="invalid serial" |
63 | niro | 306 | echo "ALX_STATE=${ALX_STATE}" > /etc/alxconfig-ng/state/state |
64 | show_invalid_serial_msg | ||
65 | exit 1 | ||
66 | niro | 221 | fi |
67 | |||
68 | niro | 347 | # first check if an entry exist with my serial |
69 | niro | 221 | # if it exist update this entry else insert a new one |
70 | niro | 347 | ID=$(mysqldo "select serial from state_connected where serial=${ALX_SERIAL};") |
71 | niro | 221 | |
72 | if [ -n "${ID}" ] | ||
73 | then | ||
74 | niro | 347 | # run an update |
75 | niro | 221 | |
76 | niro | 347 | # nice status |
77 | niro | 221 | $CURS_UP |
78 | $SET_WCOL | ||
79 | echo "[ U, State: ${ALX_STATE} ]" | ||
80 | |||
81 | niro | 347 | mysqldo "update state_connected set |
82 | niro | 221 | hostname='${HOSTNAME}', |
83 | ip='${CUR_IP}', | ||
84 | mac='${CUR_MAC}', | ||
85 | state='${ALX_STATE}', | ||
86 | mtime='${CUR_MTIME}' | ||
87 | where serial=${ALX_SERIAL};" | ||
88 | else | ||
89 | niro | 347 | # run an insert |
90 | niro | 221 | |
91 | niro | 347 | # nice status |
92 | niro | 221 | $CURS_UP |
93 | $SET_WCOL | ||
94 | echo "[ N, State: ${ALX_STATE} ]" | ||
95 | |||
96 | niro | 347 | mysqldo "insert into state_connected( |
97 | niro | 221 | serial, |
98 | hostname, | ||
99 | ip, | ||
100 | mac, | ||
101 | state, | ||
102 | mtime | ||
103 | ) | ||
104 | values( | ||
105 | '${ALX_SERIAL}', | ||
106 | '${HOSTNAME}', | ||
107 | '${CUR_IP}', | ||
108 | '${CUR_MAC}', | ||
109 | '${ALX_STATE}', | ||
110 | '${CUR_MTIME}' | ||
111 | );" | ||
112 | fi | ||
113 | } | ||
114 | |||
115 | |||
116 | # need to put this to an extra init script which will | ||
117 | # be executed first when the system is going down. | ||
118 | # nice name is alx_connected_state or sth like this | ||
119 | niro | 347 | unset_alx_connected() |
120 | { | ||
121 | niro | 221 | local SQL_OPTS |
122 | niro | 274 | local CUR_MAC |
123 | niro | 221 | |
124 | niro | 347 | CUR_MAC=$(/sbin/ifconfig ${ALX_IFACE} | grep HWaddr | cut -d ' ' -f11) |
125 | niro | 274 | |
126 | niro | 221 | echo -e ${COLMAGENTA}"Unregister system from database"${COLDEFAULT} |
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 | * |