Contents of /alx-src/tags/alxconf-0_6_0-rc5/init.d/alxsetstate
Parent Directory | Revision Log
Revision 347 -
(show annotations)
(download)
Sun Oct 9 21:35:27 2005 UTC (18 years, 11 months ago) by niro
Original Path: alx-src/trunk/alxconfig-ng/init.d/alxsetstate
File size: 3381 byte(s)
Sun Oct 9 21:35:27 2005 UTC (18 years, 11 months ago) by niro
Original Path: alx-src/trunk/alxconfig-ng/init.d/alxsetstate
File size: 3381 byte(s)
- fixed whitespaces - using now mysqldo from mysqlfunctions - added support mutiple ifaces support
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.9 2005-10-09 21:35:27 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 | [[ -z ${ALX_IFACE} ]] && export ALX_IFACE=eth0 |
40 | |
41 | # need to put this to an extra init script which will be |
42 | # executed when the real network is up and not the preliminary. |
43 | # nice name is alx_connected_state or sth like this |
44 | set_current_network_state() |
45 | { |
46 | local CUR_IP CUR_MAC ID |
47 | |
48 | echo -e ${COLMAGENTA}"Register system to database"${COLDEFAULT} |
49 | |
50 | CUR_IP=$(/sbin/ifconfig ${ALX_IFACE} | sed -n '/addr:/s/ [^r]*..//gp') |
51 | CUR_MAC=$(/sbin/ifconfig ${ALX_IFACE} | grep HWaddr | cut -d ' ' -f11) |
52 | CUR_MTIME=$(date +%s) |
53 | |
54 | # validate current serial |
55 | if ! validate_serial "${ALX_SERIAL}" "${ALX_REG_DATE}" "${CUR_MAC}" |
56 | then |
57 | # abort on non valid serial |
58 | ALX_STATE="invalid serial" |
59 | echo "ALX_STATE=${ALX_STATE}" > /etc/alxconfig-ng/state/state |
60 | show_invalid_serial_msg |
61 | exit 1 |
62 | fi |
63 | |
64 | # first check if an entry exist with my serial |
65 | # if it exist update this entry else insert a new one |
66 | ID=$(mysqldo "select serial from state_connected where serial=${ALX_SERIAL};") |
67 | |
68 | if [ -n "${ID}" ] |
69 | then |
70 | # run an update |
71 | |
72 | # nice status |
73 | $CURS_UP |
74 | $SET_WCOL |
75 | echo "[ U, State: ${ALX_STATE} ]" |
76 | |
77 | mysqldo "update state_connected set |
78 | hostname='${HOSTNAME}', |
79 | ip='${CUR_IP}', |
80 | mac='${CUR_MAC}', |
81 | state='${ALX_STATE}', |
82 | mtime='${CUR_MTIME}' |
83 | where serial=${ALX_SERIAL};" |
84 | else |
85 | # run an insert |
86 | |
87 | # nice status |
88 | $CURS_UP |
89 | $SET_WCOL |
90 | echo "[ N, State: ${ALX_STATE} ]" |
91 | |
92 | mysqldo "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 | { |
117 | local SQL_OPTS |
118 | local CUR_MAC |
119 | |
120 | CUR_MAC=$(/sbin/ifconfig ${ALX_IFACE} | grep HWaddr | cut -d ' ' -f11) |
121 | |
122 | echo -e ${COLMAGENTA}"Unregister system from database"${COLDEFAULT} |
123 | |
124 | mysqldo "delete from state_connected where serial='${ALX_SERIAL}' and mac='${CUR_MAC}';" |
125 | evaluate_retval |
126 | } |
127 | |
128 | |
129 | ########### starts here ################ |
130 | |
131 | # first of all get current system serial |
132 | if [ -f /etc/alxconfig-ng/serial ] |
133 | then |
134 | source /etc/alxconfig-ng/serial |
135 | else |
136 | ALX_SERIAL=0 |
137 | fi |
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 | * |