Contents of /alx-src/tags/alxconf-0_6_0-rc4/init.d/alxsetstate
Parent Directory | Revision Log
Revision 2413 -
(show annotations)
(download)
Wed Jun 15 13:02:44 2011 UTC (13 years, 3 months ago) by niro
File size: 3374 byte(s)
Wed Jun 15 13:02:44 2011 UTC (13 years, 3 months ago) by niro
File size: 3374 byte(s)
tagged 'alxconf-0_6_0-rc4'
1 | #!/bin/bash |
2 | # $Id$ |
3 | |
4 | #%rlevels: 3:s 0:k |
5 | #%start: 99 |
6 | #%stop: 01 |
7 | |
8 | #deps |
9 | #%needs: |
10 | #%before: |
11 | #%after: |
12 | |
13 | source /etc/conf.d/rc |
14 | source $rc_functions |
15 | |
16 | # mysql settings |
17 | source /etc/alxconfig-ng/config.rc |
18 | # helper functions |
19 | source /usr/lib/alxconfig-ng/functions/mysqlfunctions |
20 | source /usr/lib/alxconfig-ng/functions/serial_functions |
21 | source /usr/lib/alxconfig-ng/functions/common |
22 | |
23 | # unset vars which may kill us |
24 | unset ALX_SERIAL ALX_STATE ALX_IFACE |
25 | |
26 | # get current system state |
27 | if [ -f /etc/alxconfig-ng/state/state ] |
28 | then |
29 | source /etc/alxconfig-ng/state/state |
30 | else |
31 | ALX_STATE=error |
32 | fi |
33 | |
34 | if [ -f ${SETTINGSPATH}/confd-networking ] |
35 | then |
36 | ALX_IFACE="$(< ${SETTINGSPATH}/confd-networking)" |
37 | fi |
38 | [[ -z ${ALX_IFACE} ]] && export ALX_IFACE=eth0 |
39 | |
40 | # need to put this to an extra init script which will be |
41 | # executed when the real network is up and not the preliminary. |
42 | # nice name is alx_connected_state or sth like this |
43 | set_current_network_state() |
44 | { |
45 | local CUR_IP CUR_MAC ID |
46 | |
47 | rc_mecho "Register system to database" |
48 | |
49 | CUR_IP=$(/sbin/ifconfig ${ALX_IFACE} | sed -n '/addr:/s/ [^r]*..//gp') |
50 | CUR_MAC=$(/sbin/ifconfig ${ALX_IFACE} | grep HWaddr | cut -d ' ' -f11) |
51 | CUR_MTIME=$(date +%s) |
52 | |
53 | # validate current serial |
54 | if ! validate_serial "${ALX_SERIAL}" "${ALX_REG_DATE}" "${CUR_MAC}" |
55 | then |
56 | # abort on non valid serial |
57 | ALX_STATE="invalid serial" |
58 | echo "ALX_STATE=\"${ALX_STATE}\"" > /etc/alxconfig-ng/state/state |
59 | show_invalid_serial_msg |
60 | exit 1 |
61 | fi |
62 | |
63 | # first check if an entry exist with my serial |
64 | # if it exist update this entry else insert a new one |
65 | ID=$(mysqldo "select serial from state_connected where serial=${ALX_SERIAL};") |
66 | |
67 | if [ -n "${ID}" ] |
68 | then |
69 | # run an update |
70 | |
71 | # nice status |
72 | $CURS_UP |
73 | $SET_WCOL |
74 | rc_echo "[ SN: ${ALX_SERIAL}, U, ${ALX_STATE} ]" |
75 | |
76 | mysqldo "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 | rc_echo "[ SN: ${ALX_SERIAL}, N, ${ALX_STATE} ]" |
90 | |
91 | mysqldo "insert into state_connected( |
92 | serial, |
93 | hostname, |
94 | ip, |
95 | mac, |
96 | state, |
97 | mtime |
98 | ) |
99 | values( |
100 | '${ALX_SERIAL}', |
101 | '${HOSTNAME}', |
102 | '${CUR_IP}', |
103 | '${CUR_MAC}', |
104 | '${ALX_STATE}', |
105 | '${CUR_MTIME}' |
106 | );" |
107 | fi |
108 | } |
109 | |
110 | |
111 | # need to put this to an extra init script which will |
112 | # be executed first when the system is going down. |
113 | # nice name is alx_connected_state or sth like this |
114 | unset_alx_connected() |
115 | { |
116 | local SQL_OPTS |
117 | local CUR_MAC |
118 | |
119 | CUR_MAC=$(/sbin/ifconfig ${ALX_IFACE} | grep HWaddr | cut -d ' ' -f11) |
120 | |
121 | rc_mecho "Unregister system from database" |
122 | |
123 | # nice status |
124 | $CURS_UP |
125 | $SET_WCOL |
126 | rc_echo "[ SN: ${ALX_SERIAL} ]" |
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 | * |