9 |
#%before: |
#%before: |
10 |
#%after: |
#%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 $ |
# $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 |
source /etc/sysconfig/rc |
15 |
source $rc_functions |
source $rc_functions |
16 |
|
|
17 |
#mysql settings |
# mysql settings |
18 |
source /etc/alxconfig-ng/config.rc |
source /etc/alxconfig-ng/config.rc |
19 |
source /usr/lib/alxconfig-ng/functions/mysqlfunctions |
source /usr/lib/alxconfig-ng/functions/mysqlfunctions |
20 |
source /usr/lib/alxconfig-ng/functions/serial_functions |
source /usr/lib/alxconfig-ng/functions/serial_functions |
21 |
|
|
22 |
#check if mysql is available |
# check if mysql is available |
23 |
[ -x /usr/bin/mysql ] && MYSQL_ALX=true |
[ -x /usr/bin/mysql ] && MYSQL_ALX=true |
24 |
|
|
25 |
#other needed vars |
# other needed vars |
26 |
ALX_HW_DETECT=false |
ALX_HW_DETECT=false |
27 |
|
|
28 |
#unset vars which may kill us |
# unset vars which may kill us |
29 |
unset ALX_SERIAL ALX_STATE |
unset ALX_SERIAL ALX_STATE ALX_IFACE |
30 |
|
|
31 |
#get current system state |
# get current system state |
32 |
if [ -f /etc/alxconfig-ng/state/state ] |
if [ -f /etc/alxconfig-ng/state/state ] |
33 |
then |
then |
34 |
source /etc/alxconfig-ng/state/state |
source /etc/alxconfig-ng/state/state |
36 |
ALX_STATE=error |
ALX_STATE=error |
37 |
fi |
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 |
# need to put this to an extra init script which will be |
46 |
# executed when the real network is up and not the preliminary. |
# executed when the real network is up and not the preliminary. |
47 |
# nice name is alx_connected_state or sth like this |
# nice name is alx_connected_state or sth like this |
48 |
set_current_network_state(){ |
set_current_network_state() |
49 |
|
{ |
50 |
local CUR_IP CUR_MAC ID |
local CUR_IP CUR_MAC ID |
51 |
|
|
52 |
echo -e ${COLMAGENTA}"Register system to database"${COLDEFAULT} |
echo -e ${COLMAGENTA}"Register system to database"${COLDEFAULT} |
53 |
|
|
54 |
CUR_IP=$(/sbin/ifconfig eth0 | sed -n '/addr:/s/ [^r]*..//gp') |
CUR_IP=$(/sbin/ifconfig ${ALX_IFACE} | sed -n '/addr:/s/ [^r]*..//gp') |
55 |
CUR_MAC=$(/sbin/ifconfig eth0 | grep HWaddr | cut -d ' ' -f11) |
CUR_MAC=$(/sbin/ifconfig ${ALX_IFACE} | grep HWaddr | cut -d ' ' -f11) |
56 |
CUR_MTIME=$(date +%s) |
CUR_MTIME=$(date +%s) |
57 |
|
|
58 |
# validate current serial |
# validate current serial |
65 |
exit 1 |
exit 1 |
66 |
fi |
fi |
67 |
|
|
68 |
#first check if an entry exist with my serial |
# first check if an entry exist with my serial |
69 |
# if it exist update this entry else insert a new one |
# if it exist update this entry else insert a new one |
70 |
ID=$(mysql_command ${SQL_USER} ${SQL_PASS} ${SQL_HOST} ${SQL_DB} \ |
ID=$(mysqldo "select serial from state_connected where serial=${ALX_SERIAL};") |
|
"select serial from state_connected where serial=${ALX_SERIAL};") |
|
71 |
|
|
72 |
if [ -n "${ID}" ] |
if [ -n "${ID}" ] |
73 |
then |
then |
74 |
#run an update |
# run an update |
75 |
|
|
76 |
#nice status |
# nice status |
77 |
$CURS_UP |
$CURS_UP |
78 |
$SET_WCOL |
$SET_WCOL |
79 |
echo "[ U, State: ${ALX_STATE} ]" |
echo "[ U, State: ${ALX_STATE} ]" |
80 |
|
|
81 |
mysql_command ${SQL_USER} ${SQL_PASS} ${SQL_HOST} ${SQL_DB} \ |
mysqldo "update state_connected set |
|
"update state_connected set |
|
82 |
hostname='${HOSTNAME}', |
hostname='${HOSTNAME}', |
83 |
ip='${CUR_IP}', |
ip='${CUR_IP}', |
84 |
mac='${CUR_MAC}', |
mac='${CUR_MAC}', |
86 |
mtime='${CUR_MTIME}' |
mtime='${CUR_MTIME}' |
87 |
where serial=${ALX_SERIAL};" |
where serial=${ALX_SERIAL};" |
88 |
else |
else |
89 |
#run an insert |
# run an insert |
90 |
|
|
91 |
#nice status |
# nice status |
92 |
$CURS_UP |
$CURS_UP |
93 |
$SET_WCOL |
$SET_WCOL |
94 |
echo "[ N, State: ${ALX_STATE} ]" |
echo "[ N, State: ${ALX_STATE} ]" |
95 |
|
|
96 |
mysql_command ${SQL_USER} ${SQL_PASS} ${SQL_HOST} ${SQL_DB} \ |
mysqldo "insert into state_connected( |
|
"insert into state_connected( |
|
97 |
serial, |
serial, |
98 |
hostname, |
hostname, |
99 |
ip, |
ip, |
116 |
# need to put this to an extra init script which will |
# need to put this to an extra init script which will |
117 |
# be executed first when the system is going down. |
# be executed first when the system is going down. |
118 |
# nice name is alx_connected_state or sth like this |
# nice name is alx_connected_state or sth like this |
119 |
unset_alx_connected(){ |
unset_alx_connected() |
120 |
|
{ |
121 |
local SQL_OPTS |
local SQL_OPTS |
122 |
local CUR_MAC |
local CUR_MAC |
123 |
|
|
124 |
CUR_MAC=$(/sbin/ifconfig eth0 | grep HWaddr | cut -d ' ' -f11) |
CUR_MAC=$(/sbin/ifconfig ${ALX_IFACE} | grep HWaddr | cut -d ' ' -f11) |
125 |
|
|
126 |
echo -e ${COLMAGENTA}"Unregister system from database"${COLDEFAULT} |
echo -e ${COLMAGENTA}"Unregister system from database"${COLDEFAULT} |
127 |
|
|
128 |
mysql_command ${SQL_USER} ${SQL_PASS} ${SQL_HOST} ${SQL_DB} \ |
mysqldo "delete from state_connected where serial='${ALX_SERIAL}' and mac='${CUR_MAC}';" |
|
"delete from state_connected where serial='${ALX_SERIAL}' and mac='${CUR_MAC}';" |
|
129 |
evaluate_retval |
evaluate_retval |
130 |
} |
} |
131 |
|
|
132 |
|
|
133 |
########### starts here ################ |
########### starts here ################ |
134 |
|
|
135 |
#first of all get current system serial |
# first of all get current system serial |
136 |
if [ -f /etc/alxconfig-ng/serial ] |
if [ -f /etc/alxconfig-ng/serial ] |
137 |
then |
then |
138 |
source /etc/alxconfig-ng/serial |
source /etc/alxconfig-ng/serial |
140 |
ALX_SERIAL=0 |
ALX_SERIAL=0 |
141 |
fi |
fi |
142 |
|
|
|
|
|
143 |
case $1 in |
case $1 in |
144 |
start) |
start) |
145 |
# check if mysql server is reachable |
# check if mysql server is reachable |