36 #------------------------------------------------------------------------------ |
36 #------------------------------------------------------------------------------ |
37 |
37 |
38 ### BEGIN INIT INFO |
38 ### BEGIN INIT INFO |
39 # Provides: ethercat |
39 # Provides: ethercat |
40 # Required-Start: $local_fs $syslog $network |
40 # Required-Start: $local_fs $syslog $network |
41 # Should-Start: $time |
41 # Should-Start: $time ntp |
42 # Required-Stop: $local_fs $syslog $network |
42 # Required-Stop: $local_fs $syslog $network |
43 # Should-Stop: $time |
43 # Should-Stop: $time ntp |
44 # Default-Start: 3 5 |
44 # Default-Start: 3 5 |
45 # Default-Stop: 0 1 2 6 |
45 # Default-Stop: 0 1 2 6 |
46 # Short-Description: IgH EtherCAT master modules |
46 # Short-Description: IgH EtherCAT master modules |
47 # Description: |
47 # Description: |
48 ### END INIT INFO |
48 ### END INIT INFO |
49 |
49 |
50 #------------------------------------------------------------------------------ |
50 #------------------------------------------------------------------------------ |
51 |
51 |
52 ETHERCAT_CONFIG=/etc/sysconfig/ethercat |
52 ETHERCAT_CONFIG=/etc/sysconfig/ethercat |
53 |
53 |
54 test -r $ETHERCAT_CONFIG || { echo "$ETHERCAT_CONFIG not existing"; |
54 if [ ! -r $ETHERCAT_CONFIG ]; then |
55 if [ "$1" = "stop" ]; then exit 0; |
55 echo "$ETHERCAT_CONFIG not existing"; |
56 else exit 6; fi; } |
56 if [ "$1" = "stop" ]; then |
|
57 exit 0 |
|
58 else |
|
59 exit 6 |
|
60 fi |
|
61 fi |
57 |
62 |
58 . $ETHERCAT_CONFIG |
63 . $ETHERCAT_CONFIG |
59 |
64 |
60 #------------------------------------------------------------------------------ |
65 #------------------------------------------------------------------------------ |
61 |
66 |
62 # |
67 # |
63 # Function for setting up the EoE bridge |
68 # Function for setting up the EoE bridge |
64 # |
69 # |
65 build_eoe_bridge() { |
70 build_eoe_bridge() |
66 if [ -z "$EOE_BRIDGE" ]; then return; fi |
71 { |
|
72 if [ -z "$EOE_BRIDGE" ]; then return; fi |
67 |
73 |
68 EOEIF=`/sbin/ifconfig -a | grep -o -E "^eoe[0-9]+ "` |
74 EOEIF=`/sbin/ifconfig -a | grep -o -E "^eoe[0-9]+ "` |
69 |
75 |
70 # add bridge, if it does not already exist |
76 # add bridge, if it does not already exist |
71 if ! /sbin/brctl show | grep -E -q "^$EOE_BRIDGE"; then |
77 if ! /sbin/brctl show | grep -E -q "^$EOE_BRIDGE"; then |
72 if ! /sbin/brctl addbr $EOE_BRIDGE; then |
78 if ! /sbin/brctl addbr $EOE_BRIDGE; then |
73 /bin/false |
79 /bin/false |
74 rc_status -v |
80 rc_status -v |
75 rc_exit |
81 rc_exit |
76 fi |
82 fi |
77 fi |
83 fi |
78 |
84 |
79 # check if specified interfaces are bridged |
85 # check if specified interfaces are bridged |
80 for interf in $EOEIF $EOE_EXTRA_INTERFACES; do |
86 for interf in $EOEIF $EOE_EXTRA_INTERFACES; do |
81 # interface is already part of the bridge |
87 # interface is already part of the bridge |
82 if /sbin/brctl show $EOE_BRIDGE | grep -E -q $interf |
88 if /sbin/brctl show $EOE_BRIDGE | grep -E -q $interf |
83 then continue |
89 then continue |
84 fi |
90 fi |
85 # clear IP address and open interface |
91 # clear IP address and open interface |
86 if ! /sbin/ifconfig $interf 0.0.0.0 up; then |
92 if ! /sbin/ifconfig $interf 0.0.0.0 up; then |
87 /bin/false |
93 /bin/false |
88 rc_status -v |
94 rc_status -v |
89 rc_exit |
95 rc_exit |
90 fi |
96 fi |
91 # add interface to the bridge |
97 # add interface to the bridge |
92 if ! /sbin/brctl addif $EOE_BRIDGE $interf; then |
98 if ! /sbin/brctl addif $EOE_BRIDGE $interf; then |
93 /bin/false |
99 /bin/false |
94 rc_status -v |
100 rc_status -v |
95 rc_exit |
101 rc_exit |
96 fi |
102 fi |
97 done |
103 done |
98 |
104 |
99 # configure IP on bridge |
105 # configure IP on bridge |
100 if [ -n "$EOE_IP_ADDRESS" -a -n "$EOE_IP_NETMASK" ]; then |
106 if [ -n "$EOE_IP_ADDRESS" -a -n "$EOE_IP_NETMASK" ]; then |
101 if ! /sbin/ifconfig $EOE_BRIDGE $EOE_IP_ADDRESS \ |
107 if ! /sbin/ifconfig $EOE_BRIDGE $EOE_IP_ADDRESS \ |
102 netmask $EOE_IP_NETMASK; then |
108 netmask $EOE_IP_NETMASK; then |
103 /bin/false |
109 /bin/false |
104 rc_status -v |
110 rc_status -v |
105 rc_exit |
111 rc_exit |
106 fi |
112 fi |
107 fi |
113 fi |
108 |
114 |
109 # open bridge |
115 # open bridge |
110 if ! /sbin/ifconfig $EOE_BRIDGE up; then |
116 if ! /sbin/ifconfig $EOE_BRIDGE up; then |
111 /bin/false |
117 /bin/false |
112 rc_status -v |
118 rc_status -v |
113 rc_exit |
119 rc_exit |
114 fi |
120 fi |
115 |
121 |
116 # install new default gateway |
122 # install new default gateway |
117 if [ -n "$EOE_GATEWAY" ]; then |
123 if [ -n "$EOE_GATEWAY" ]; then |
118 while /sbin/route -n | grep -E -q "^0.0.0.0"; do |
124 while /sbin/route -n | grep -E -q "^0.0.0.0"; do |
119 if ! /sbin/route del default; then |
125 if ! /sbin/route del default; then |
120 echo "Failed to remove route!" 1>&2 |
126 echo "Failed to remove route!" 1>&2 |
121 /bin/false |
127 /bin/false |
122 rc_status -v |
128 rc_status -v |
123 rc_exit |
129 rc_exit |
124 fi |
130 fi |
125 done |
131 done |
126 if ! /sbin/route add default gw $EOE_GATEWAY; then |
132 if ! /sbin/route add default gw $EOE_GATEWAY; then |
127 /bin/false |
133 /bin/false |
128 rc_status -v |
134 rc_status -v |
129 rc_exit |
135 rc_exit |
130 fi |
136 fi |
131 fi |
137 fi |
132 } |
138 } |
135 |
141 |
136 . /etc/rc.status |
142 . /etc/rc.status |
137 rc_reset |
143 rc_reset |
138 |
144 |
139 case "$1" in |
145 case "$1" in |
|
146 |
140 start) |
147 start) |
141 echo -n "Starting EtherCAT master " |
148 echo -n "Starting EtherCAT master " |
142 |
149 |
143 if [ -z "$DEVICE_INDEX" ]; then |
150 if [ -z "$DEVICE_INDEX" ]; then |
144 echo "ERROR: DEVICE_INDEX not set!" |
151 echo "ERROR: DEVICE_INDEX not set!" |
145 /bin/false |
152 /bin/false |
146 rc_status -v |
153 rc_status -v |
147 rc_exit |
154 rc_exit |
148 fi |
155 fi |
149 |
156 |
150 if [ -z "$EOE_INTERFACES" ]; then |
157 if [ -z "$EOE_INTERFACES" ]; then |
151 if [ -n "$EOE_DEVICES" ]; then # support legacy sysconfig files |
158 if [ -n "$EOE_DEVICES" ]; then # support legacy sysconfig files |
152 EOE_INTERFACES=$EOE_DEVICES |
159 EOE_INTERFACES=$EOE_DEVICES |
153 else |
160 else |
154 EOE_INTERFACES=0 |
161 EOE_INTERFACES=0 |
155 fi |
|
156 fi |
|
157 |
|
158 # unload conflicting modules at first |
|
159 for mod in 8139too 8139cp; do |
|
160 if lsmod | grep "^$mod " > /dev/null; then |
|
161 if ! rmmod $mod; then |
|
162 /bin/false |
|
163 rc_status -v |
|
164 rc_exit |
|
165 fi |
162 fi |
166 fi |
163 fi |
167 done |
164 |
168 |
165 # unload conflicting modules at first |
169 # load master module |
166 for mod in 8139too 8139cp; do |
170 if ! modprobe ec_master ec_eoeif_count=$EOE_INTERFACES; then |
167 if lsmod | grep "^$mod " > /dev/null; then |
171 /bin/false |
168 if ! rmmod $mod; then |
172 rc_status -v |
169 /bin/false |
173 rc_exit |
170 rc_status -v |
174 fi |
171 rc_exit |
175 |
172 fi |
176 # load device module |
173 fi |
177 if ! modprobe ec_8139too ec_device_index=$DEVICE_INDEX; then |
174 done |
178 /bin/false |
175 |
179 rc_status -v |
176 # load master module |
180 rc_exit |
177 if ! modprobe ec_master ec_eoeif_count=$EOE_INTERFACES; then |
181 fi |
178 /bin/false |
182 |
179 rc_status -v |
183 # build EoE bridge |
180 rc_exit |
184 build_eoe_bridge |
181 fi |
185 |
182 |
186 rc_status -v |
183 # load device module |
187 ;; |
184 if ! modprobe ec_8139too ec_device_index=$DEVICE_INDEX; then |
|
185 /bin/false |
|
186 rc_status -v |
|
187 rc_exit |
|
188 fi |
|
189 |
|
190 # build EoE bridge |
|
191 build_eoe_bridge |
|
192 |
|
193 rc_status -v |
|
194 ;; |
188 |
195 |
189 stop) |
196 stop) |
190 echo -n "Shutting down EtherCAT master " |
197 echo -n "Shutting down EtherCAT master " |
191 |
198 |
192 # unload modules |
199 # unload modules |
193 for mod in ec_8139too ec_master; do |
200 for mod in ec_8139too ec_master; do |
194 if lsmod | grep "^$mod " > /dev/null; then |
201 if lsmod | grep "^$mod " > /dev/null; then |
195 if ! rmmod $mod; then |
202 if ! rmmod $mod; then |
196 /bin/false |
203 /bin/false |
197 rc_status -v |
204 rc_status -v |
198 rc_exit |
205 rc_exit |
|
206 fi; |
199 fi; |
207 fi; |
200 fi; |
208 done |
201 done |
209 |
202 |
210 sleep 1 |
203 sleep 1 |
211 |
204 |
212 # reload previous modules |
205 # reload previous modules |
213 if ! modprobe 8139too; then |
206 if ! modprobe 8139too; then |
214 echo "Warning: Failed to restore 8139too module." |
207 echo "Warning: Failed to restore 8139too module." |
215 fi |
208 fi |
216 |
209 |
217 rc_status -v |
210 rc_status -v |
218 ;; |
211 ;; |
|
212 |
219 |
213 restart) |
220 restart) |
214 $0 stop || exit 1 |
221 $0 stop || exit 1 |
215 |
222 sleep 1 |
216 sleep 1 |
223 $0 start |
217 |
224 rc_status |
218 $0 start |
225 ;; |
219 |
|
220 rc_status |
|
221 ;; |
|
222 |
226 |
223 status) |
227 status) |
224 echo -n "Checking for EtherCAT " |
228 echo -n "Checking for EtherCAT " |
225 |
229 |
226 lsmod | grep "^ec_master " > /dev/null |
230 lsmod | grep "^ec_master " > /dev/null |
227 master_running=$? |
231 master_running=$? |
228 lsmod | grep "^ec_8139too " > /dev/null |
232 lsmod | grep "^ec_8139too " > /dev/null |
229 device_running=$? |
233 device_running=$? |
230 |
234 |
231 # master module and device module loaded? |
235 # master module and device module loaded? |
232 test $master_running -eq 0 -a $device_running -eq 0 |
236 test $master_running -eq 0 -a $device_running -eq 0 |
233 |
237 |
234 rc_status -v |
238 rc_status -v |
235 ;; |
239 ;; |
236 |
240 |
237 bridge) |
241 bridge) |
238 echo -n "Building EoE bridge " |
242 echo -n "Building EoE bridge " |
239 |
243 build_eoe_bridge |
240 build_eoe_bridge |
244 rc_status -v |
241 |
245 ;; |
242 rc_status -v |
|
243 ;; |
|
244 |
246 |
245 *) |
247 *) |
246 echo "USAGE: $0 {start|stop|restart|status|bridge}" |
248 echo "USAGE: $0 {start|stop|restart|status|bridge}" |
247 ;; |
249 ;; |
|
250 |
248 esac |
251 esac |
|
252 |
249 rc_exit |
253 rc_exit |
250 |
254 |
251 #------------------------------------------------------------------------------ |
255 #------------------------------------------------------------------------------ |