Magellan Linux

Contents of /alx-src/trunk/tinyalxconfig-ng/init.d/alxsetstate

Parent Directory Parent Directory | Revision Log Revision Log


Revision 493 - (show annotations) (download)
Sun Jun 8 11:10:24 2008 UTC (15 years, 10 months ago) by niro
File size: 3363 byte(s)
-removed deprecated checks

1 #!/bin/bash
2
3 #%rlevels: 3:s 0: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/tinyalxconfig-ng/init.d/alxsetstate,v 1.4 2008-06-08 11:10:24 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 # unset vars which may kill us
23 unset ALX_SERIAL ALX_STATE ALX_IFACE
24
25 # get current system state
26 if [ -f /etc/alxconfig-ng/state/state ]
27 then
28 source /etc/alxconfig-ng/state/state
29 else
30 ALX_STATE=error
31 fi
32
33 if [ -f ${SETTINGSPATH}/confd-networking ]
34 then
35 ALX_IFACE="$(< ${SETTINGSPATH}/confd-networking)"
36 fi
37 [[ -z ${ALX_IFACE} ]] && export ALX_IFACE=eth0
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 {
44 local CUR_IP CUR_MAC ID
45
46 echo -e ${COLMAGENTA}"Register system to database"${COLDEFAULT}
47
48 CUR_IP=$(/sbin/ifconfig ${ALX_IFACE} | sed -n '/addr:/s/ [^r]*..//gp')
49 CUR_MAC=$(/sbin/ifconfig ${ALX_IFACE} | grep HWaddr | cut -d ' ' -f11)
50 CUR_MTIME=$(date +%s)
51
52 # validate current serial
53 if ! validate_serial "${ALX_SERIAL}" "${ALX_REG_DATE}" "${CUR_MAC}"
54 then
55 # abort on non valid serial
56 ALX_STATE="invalid serial"
57 echo "ALX_STATE=${ALX_STATE}" > /etc/alxconfig-ng/state/state
58 show_invalid_serial_msg
59 exit 1
60 fi
61
62 # first check if an entry exist with my serial
63 # if it exist update this entry else insert a new one
64 ID=$(mysqldo "select serial from state_connected where serial=${ALX_SERIAL};")
65
66 if [ -n "${ID}" ]
67 then
68 # run an update
69
70 # nice status
71 $CURS_UP
72 $SET_WCOL
73 echo "[ U, State: ${ALX_STATE} ]"
74
75 mysqldo "update state_connected set
76 hostname='${HOSTNAME}',
77 ip='${CUR_IP}',
78 mac='${CUR_MAC}',
79 state='${ALX_STATE}',
80 mtime='${CUR_MTIME}'
81 where serial=${ALX_SERIAL};"
82 else
83 # run an insert
84
85 # nice status
86 $CURS_UP
87 $SET_WCOL
88 echo "[ N, State: ${ALX_STATE} ]"
89
90 mysqldo "insert into state_connected(
91 serial,
92 hostname,
93 ip,
94 mac,
95 state,
96 mtime
97 )
98 values(
99 '${ALX_SERIAL}',
100 '${HOSTNAME}',
101 '${CUR_IP}',
102 '${CUR_MAC}',
103 '${ALX_STATE}',
104 '${CUR_MTIME}'
105 );"
106 fi
107 }
108
109
110 # need to put this to an extra init script which will
111 # be executed first when the system is going down.
112 # nice name is alx_connected_state or sth like this
113 unset_alx_connected()
114 {
115 local SQL_OPTS
116 local CUR_MAC
117
118 CUR_MAC=$(/sbin/ifconfig ${ALX_IFACE} | grep HWaddr | cut -d ' ' -f11)
119
120 echo -e ${COLMAGENTA}"Unregister system from database"${COLDEFAULT}
121
122 mysqldo "delete from state_connected where serial='${ALX_SERIAL}' and mac='${CUR_MAC}';"
123 evaluate_retval
124 }
125
126
127 ########### starts here ################
128
129 # first of all get current system serial
130 if [ -f /etc/alxconfig-ng/serial ]
131 then
132 source /etc/alxconfig-ng/serial
133 else
134 ALX_SERIAL=0
135 fi
136
137 case $1 in
138 start)
139 # check if mysql server is reachable
140 # if not abort this script
141 reach_mysql_server || exit 1
142
143 set_current_network_state
144 evaluate_retval
145 ;;
146
147 stop)
148 # check if mysql server is reachable
149 # if not abort this script
150 reach_mysql_server || exit 1
151
152 unset_alx_connected
153 evaluate_retval
154 ;;
155 *)
156 echo "Usage: $0 {start|stop} ..."
157 ;;
158 esac
159

Properties

Name Value
svn:executable *