Magellan Linux

Contents of /alx-src/branches/alxconf-060/init.d/alxsetstate

Parent Directory Parent Directory | Revision Log Revision Log


Revision 283 - (show annotations) (download)
Wed Aug 17 21:20:12 2005 UTC (18 years, 8 months ago) by niro
Original Path: alx-src/trunk/alxconfig-ng/init.d/alxsetstate
File size: 3383 byte(s)
added to major functions: do not change any settings if mysql server is not reachable

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.7 2005-08-17 21:20:12 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 ALX_STATE="invalid serial"
55 fi
56
57 #first check if an entry exist with my serial
58 # if it exist update this entry else insert a new one
59 ID=$(mysql_command ${SQL_USER} ${SQL_PASS} ${SQL_HOST} ${SQL_DB} \
60 "select serial from state_connected where serial=${ALX_SERIAL};")
61
62 if [ -n "${ID}" ]
63 then
64 #run an update
65
66 #nice status
67 $CURS_UP
68 $SET_WCOL
69 echo "[ U, State: ${ALX_STATE} ]"
70
71 mysql_command ${SQL_USER} ${SQL_PASS} ${SQL_HOST} ${SQL_DB} \
72 "update state_connected set
73 hostname='${HOSTNAME}',
74 ip='${CUR_IP}',
75 mac='${CUR_MAC}',
76 state='${ALX_STATE}',
77 mtime='${CUR_MTIME}'
78 where serial=${ALX_SERIAL};"
79 else
80 #run an insert
81
82 #nice status
83 $CURS_UP
84 $SET_WCOL
85 echo "[ N, State: ${ALX_STATE} ]"
86
87 mysql_command ${SQL_USER} ${SQL_PASS} ${SQL_HOST} ${SQL_DB} \
88 "insert into state_connected(
89 serial,
90 hostname,
91 ip,
92 mac,
93 state,
94 mtime
95 )
96 values(
97 '${ALX_SERIAL}',
98 '${HOSTNAME}',
99 '${CUR_IP}',
100 '${CUR_MAC}',
101 '${ALX_STATE}',
102 '${CUR_MTIME}'
103 );"
104 fi
105 }
106
107
108 # need to put this to an extra init script which will
109 # be executed first when the system is going down.
110 # nice name is alx_connected_state or sth like this
111 unset_alx_connected(){
112 local SQL_OPTS
113 local CUR_MAC
114
115 CUR_MAC=$(/sbin/ifconfig eth0 | grep HWaddr | cut -d ' ' -f11)
116
117 echo -e ${COLMAGENTA}"Unregister system from database"${COLDEFAULT}
118
119 mysql_command ${SQL_USER} ${SQL_PASS} ${SQL_HOST} ${SQL_DB} \
120 "delete from state_connected where serial='${ALX_SERIAL}' and mac='${CUR_MAC}';"
121 evaluate_retval
122 }
123
124 ########### starts here ################
125
126 #first of all get current system serial
127 if [ -f /etc/alxconfig-ng/serial ]
128 then
129 source /etc/alxconfig-ng/serial
130 else
131 ALX_SERIAL=0
132 fi
133
134
135 case $1 in
136 start)
137 # check if mysql server is reachable
138 # if not abort this script
139 reach_mysql_server || exit 1
140
141 set_current_network_state
142 evaluate_retval
143 ;;
144
145 stop)
146 # check if mysql server is reachable
147 # if not abort this script
148 reach_mysql_server || exit 1
149
150 unset_alx_connected
151 evaluate_retval
152 ;;
153 *)
154 echo "Usage: $0 {start|stop} ..."
155 ;;
156 esac
157

Properties

Name Value
svn:executable *