Contents of /alx-src/trunk/alxconfig-ng/init.d/alxsetstate
Parent Directory | Revision Log
Revision 306 -
(show annotations)
(download)
Sun Aug 28 19:30:25 2005 UTC (19 years, 1 month ago) by niro
File size: 3512 byte(s)
Sun Aug 28 19:30:25 2005 UTC (19 years, 1 month ago) by niro
File size: 3512 byte(s)
no aborting on invalid serials
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.8 2005-08-28 19:30:25 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 |
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 | # need to put this to an extra init script which will be |
40 | # executed when the real network is up and not the preliminary. |
41 | # nice name is alx_connected_state or sth like this |
42 | set_current_network_state(){ |
43 | local CUR_IP CUR_MAC ID |
44 | |
45 | echo -e ${COLMAGENTA}"Register system to database"${COLDEFAULT} |
46 | |
47 | CUR_IP=$(/sbin/ifconfig eth0 | sed -n '/addr:/s/ [^r]*..//gp') |
48 | CUR_MAC=$(/sbin/ifconfig eth0 | grep HWaddr | cut -d ' ' -f11) |
49 | CUR_MTIME=$(date +%s) |
50 | |
51 | # validate current serial |
52 | if ! validate_serial "${ALX_SERIAL}" "${ALX_REG_DATE}" "${CUR_MAC}" |
53 | then |
54 | # abort on non valid serial |
55 | ALX_STATE="invalid serial" |
56 | echo "ALX_STATE=${ALX_STATE}" > /etc/alxconfig-ng/state/state |
57 | show_invalid_serial_msg |
58 | exit 1 |
59 | fi |
60 | |
61 | #first check if an entry exist with my serial |
62 | # if it exist update this entry else insert a new one |
63 | ID=$(mysql_command ${SQL_USER} ${SQL_PASS} ${SQL_HOST} ${SQL_DB} \ |
64 | "select serial from state_connected where serial=${ALX_SERIAL};") |
65 | |
66 | if [ -n "${ID}" ] |
67 | then |
68 | #run an update |
69 | |
70 | #nice status |
71 | $CURS_UP |
72 | $SET_WCOL |
73 | echo "[ U, State: ${ALX_STATE} ]" |
74 | |
75 | mysql_command ${SQL_USER} ${SQL_PASS} ${SQL_HOST} ${SQL_DB} \ |
76 | "update state_connected set |
77 | 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 | #run an insert |
85 | |
86 | #nice status |
87 | $CURS_UP |
88 | $SET_WCOL |
89 | echo "[ N, State: ${ALX_STATE} ]" |
90 | |
91 | mysql_command ${SQL_USER} ${SQL_PASS} ${SQL_HOST} ${SQL_DB} \ |
92 | "insert into state_connected( |
93 | serial, |
94 | hostname, |
95 | ip, |
96 | mac, |
97 | state, |
98 | mtime |
99 | ) |
100 | values( |
101 | '${ALX_SERIAL}', |
102 | '${HOSTNAME}', |
103 | '${CUR_IP}', |
104 | '${CUR_MAC}', |
105 | '${ALX_STATE}', |
106 | '${CUR_MTIME}' |
107 | );" |
108 | fi |
109 | } |
110 | |
111 | |
112 | # need to put this to an extra init script which will |
113 | # be executed first when the system is going down. |
114 | # nice name is alx_connected_state or sth like this |
115 | unset_alx_connected(){ |
116 | local SQL_OPTS |
117 | local CUR_MAC |
118 | |
119 | CUR_MAC=$(/sbin/ifconfig eth0 | grep HWaddr | cut -d ' ' -f11) |
120 | |
121 | echo -e ${COLMAGENTA}"Unregister system from database"${COLDEFAULT} |
122 | |
123 | mysql_command ${SQL_USER} ${SQL_PASS} ${SQL_HOST} ${SQL_DB} \ |
124 | "delete from state_connected where serial='${ALX_SERIAL}' and mac='${CUR_MAC}';" |
125 | evaluate_retval |
126 | } |
127 | |
128 | ########### starts here ################ |
129 | |
130 | #first of all get current system serial |
131 | if [ -f /etc/alxconfig-ng/serial ] |
132 | then |
133 | source /etc/alxconfig-ng/serial |
134 | else |
135 | ALX_SERIAL=0 |
136 | fi |
137 | |
138 | |
139 | case $1 in |
140 | start) |
141 | # check if mysql server is reachable |
142 | # if not abort this script |
143 | reach_mysql_server || exit 1 |
144 | |
145 | set_current_network_state |
146 | evaluate_retval |
147 | ;; |
148 | |
149 | stop) |
150 | # check if mysql server is reachable |
151 | # if not abort this script |
152 | reach_mysql_server || exit 1 |
153 | |
154 | unset_alx_connected |
155 | evaluate_retval |
156 | ;; |
157 | *) |
158 | echo "Usage: $0 {start|stop} ..." |
159 | ;; |
160 | esac |
161 |
Properties
Name | Value |
---|---|
svn:executable | * |