Contents of /alx-src/tags/alxconf_20060908_8/init.d/alxsetstate
Parent Directory | Revision Log
Revision 370 -
(show annotations)
(download)
Wed Oct 26 11:57:00 2005 UTC (18 years, 11 months ago) by niro
Original Path: alx-src/trunk/alxconfig-ng/init.d/alxsetstate
File size: 3484 byte(s)
Wed Oct 26 11:57:00 2005 UTC (18 years, 11 months ago) by niro
Original Path: alx-src/trunk/alxconfig-ng/init.d/alxsetstate
File size: 3484 byte(s)
fixed confd-networking
1 | #!/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 | # $Header: /home/cvsd/alx-cvs/alx-src/alxconfig-ng/init.d/alxsetstate,v 1.10 2005-10-26 11:57:00 niro Exp $ |
13 | |
14 | source /etc/sysconfig/rc |
15 | source $rc_functions |
16 | |
17 | # mysql settings |
18 | source /etc/alxconfig-ng/config.rc |
19 | source /usr/lib/alxconfig-ng/functions/mysqlfunctions |
20 | source /usr/lib/alxconfig-ng/functions/serial_functions |
21 | |
22 | # check if mysql is available |
23 | [ -x /usr/bin/mysql ] && MYSQL_ALX=true |
24 | |
25 | # other needed vars |
26 | ALX_HW_DETECT=false |
27 | |
28 | # unset vars which may kill us |
29 | unset ALX_SERIAL ALX_STATE ALX_IFACE |
30 | |
31 | # get current system state |
32 | if [ -f /etc/alxconfig-ng/state/state ] |
33 | then |
34 | source /etc/alxconfig-ng/state/state |
35 | else |
36 | ALX_STATE=error |
37 | fi |
38 | |
39 | if [ -f ${SETTINGSPATH}/confd-networking ] |
40 | then |
41 | ALX_IFACE="$(< ${SETTINGSPATH}/confd-networking)" |
42 | fi |
43 | [[ -z ${ALX_IFACE} ]] && export ALX_IFACE=eth0 |
44 | |
45 | # 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 | set_current_network_state() |
49 | { |
50 | local CUR_IP CUR_MAC ID |
51 | |
52 | echo -e ${COLMAGENTA}"Register system to database"${COLDEFAULT} |
53 | |
54 | 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 | CUR_MTIME=$(date +%s) |
57 | |
58 | # validate current serial |
59 | if ! validate_serial "${ALX_SERIAL}" "${ALX_REG_DATE}" "${CUR_MAC}" |
60 | then |
61 | # abort on non valid serial |
62 | ALX_STATE="invalid serial" |
63 | echo "ALX_STATE=${ALX_STATE}" > /etc/alxconfig-ng/state/state |
64 | show_invalid_serial_msg |
65 | exit 1 |
66 | fi |
67 | |
68 | # first check if an entry exist with my serial |
69 | # if it exist update this entry else insert a new one |
70 | ID=$(mysqldo "select serial from state_connected where serial=${ALX_SERIAL};") |
71 | |
72 | if [ -n "${ID}" ] |
73 | then |
74 | # run an update |
75 | |
76 | # nice status |
77 | $CURS_UP |
78 | $SET_WCOL |
79 | echo "[ U, State: ${ALX_STATE} ]" |
80 | |
81 | mysqldo "update state_connected set |
82 | 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 | # run an insert |
90 | |
91 | # nice status |
92 | $CURS_UP |
93 | $SET_WCOL |
94 | echo "[ N, State: ${ALX_STATE} ]" |
95 | |
96 | mysqldo "insert into state_connected( |
97 | 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 | unset_alx_connected() |
120 | { |
121 | local SQL_OPTS |
122 | local CUR_MAC |
123 | |
124 | CUR_MAC=$(/sbin/ifconfig ${ALX_IFACE} | grep HWaddr | cut -d ' ' -f11) |
125 | |
126 | echo -e ${COLMAGENTA}"Unregister system from database"${COLDEFAULT} |
127 | |
128 | mysqldo "delete from state_connected where serial='${ALX_SERIAL}' and mac='${CUR_MAC}';" |
129 | evaluate_retval |
130 | } |
131 | |
132 | |
133 | ########### starts here ################ |
134 | |
135 | # first of all get current system serial |
136 | if [ -f /etc/alxconfig-ng/serial ] |
137 | then |
138 | source /etc/alxconfig-ng/serial |
139 | else |
140 | ALX_SERIAL=0 |
141 | fi |
142 | |
143 | case $1 in |
144 | start) |
145 | # check if mysql server is reachable |
146 | # if not abort this script |
147 | reach_mysql_server || exit 1 |
148 | |
149 | set_current_network_state |
150 | evaluate_retval |
151 | ;; |
152 | |
153 | stop) |
154 | # check if mysql server is reachable |
155 | # if not abort this script |
156 | reach_mysql_server || exit 1 |
157 | |
158 | unset_alx_connected |
159 | evaluate_retval |
160 | ;; |
161 | *) |
162 | echo "Usage: $0 {start|stop} ..." |
163 | ;; |
164 | esac |
165 |
Properties
Name | Value |
---|---|
svn:executable | * |