Magellan Linux

Diff of /alx-src/trunk/alxconfig-ng/init.d/alxsetstate

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 346 by niro, Sun Aug 28 19:30:25 2005 UTC revision 347 by niro, Sun Oct 9 21:35:27 2005 UTC
# Line 9  Line 9 
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.9 2005-10-09 21:35:27 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
# Line 36  else Line 36  else
36   ALX_STATE=error   ALX_STATE=error
37  fi  fi
38    
39    [[ -z ${ALX_IFACE} ]] && export ALX_IFACE=eth0
40    
41  # need to put this to an extra init script which will be  # need to put this to an extra init script which will be
42  # executed when the real network is up and not the preliminary.  # executed when the real network is up and not the preliminary.
43  # nice name is alx_connected_state or sth like this  # nice name is alx_connected_state or sth like this
44  set_current_network_state(){  set_current_network_state()
45    {
46   local CUR_IP CUR_MAC ID   local CUR_IP CUR_MAC ID
47    
48   echo -e ${COLMAGENTA}"Register system to database"${COLDEFAULT}   echo -e ${COLMAGENTA}"Register system to database"${COLDEFAULT}
49    
50   CUR_IP=$(/sbin/ifconfig eth0 | sed -n '/addr:/s/ [^r]*..//gp')   CUR_IP=$(/sbin/ifconfig ${ALX_IFACE} | sed -n '/addr:/s/ [^r]*..//gp')
51   CUR_MAC=$(/sbin/ifconfig eth0 | grep HWaddr | cut -d ' ' -f11)   CUR_MAC=$(/sbin/ifconfig ${ALX_IFACE} | grep HWaddr | cut -d ' ' -f11)
52   CUR_MTIME=$(date +%s)   CUR_MTIME=$(date +%s)
53    
54   # validate current serial   # validate current serial
# Line 58  set_current_network_state(){ Line 61  set_current_network_state(){
61   exit 1   exit 1
62   fi   fi
63    
64   #first check if an entry exist with my serial   # first check if an entry exist with my serial
65   # if it exist update this entry else insert a new one   # if it exist update this entry else insert a new one
66   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};")  
67    
68   if [ -n "${ID}" ]   if [ -n "${ID}" ]
69   then   then
70   #run an update   # run an update
71    
72   #nice status   # nice status
73   $CURS_UP   $CURS_UP
74   $SET_WCOL   $SET_WCOL
75   echo "[ U, State: ${ALX_STATE} ]"   echo "[ U, State: ${ALX_STATE} ]"
76    
77   mysql_command ${SQL_USER} ${SQL_PASS} ${SQL_HOST} ${SQL_DB} \   mysqldo "update state_connected set
  "update state_connected set  
78   hostname='${HOSTNAME}',   hostname='${HOSTNAME}',
79   ip='${CUR_IP}',   ip='${CUR_IP}',
80   mac='${CUR_MAC}',   mac='${CUR_MAC}',
# Line 81  set_current_network_state(){ Line 82  set_current_network_state(){
82   mtime='${CUR_MTIME}'   mtime='${CUR_MTIME}'
83   where serial=${ALX_SERIAL};"   where serial=${ALX_SERIAL};"
84   else   else
85   #run an insert   # run an insert
86    
87   #nice status   # nice status
88   $CURS_UP   $CURS_UP
89   $SET_WCOL   $SET_WCOL
90   echo "[ N, State: ${ALX_STATE} ]"   echo "[ N, State: ${ALX_STATE} ]"
91    
92   mysql_command ${SQL_USER} ${SQL_PASS} ${SQL_HOST} ${SQL_DB} \   mysqldo "insert into state_connected(
  "insert into state_connected(  
93   serial,   serial,
94   hostname,   hostname,
95   ip,   ip,
# Line 112  set_current_network_state(){ Line 112  set_current_network_state(){
112  # need to put this to an extra init script which will  # need to put this to an extra init script which will
113  # be executed first when the system is going down.  # be executed first when the system is going down.
114  # nice name is alx_connected_state or sth like this  # nice name is alx_connected_state or sth like this
115  unset_alx_connected(){  unset_alx_connected()
116    {
117   local SQL_OPTS   local SQL_OPTS
118   local CUR_MAC   local CUR_MAC
119    
120   CUR_MAC=$(/sbin/ifconfig eth0 | grep HWaddr | cut -d ' ' -f11)   CUR_MAC=$(/sbin/ifconfig ${ALX_IFACE} | grep HWaddr | cut -d ' ' -f11)
121    
122   echo -e ${COLMAGENTA}"Unregister system from database"${COLDEFAULT}   echo -e ${COLMAGENTA}"Unregister system from database"${COLDEFAULT}
123    
124   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}';"  
125   evaluate_retval   evaluate_retval
126  }  }
127    
128    
129  ########### starts here ################  ########### starts here ################
130    
131  #first of all get current system serial  # first of all get current system serial
132  if [ -f /etc/alxconfig-ng/serial ]  if [ -f /etc/alxconfig-ng/serial ]
133  then  then
134   source /etc/alxconfig-ng/serial   source /etc/alxconfig-ng/serial
# Line 135  else Line 136  else
136   ALX_SERIAL=0   ALX_SERIAL=0
137  fi  fi
138    
   
139  case $1 in  case $1 in
140   start)   start)
141   # check if mysql server is reachable   # check if mysql server is reachable

Legend:
Removed from v.346  
changed lines
  Added in v.347