Skip to content
Snippets Groups Projects
Commit f7dc868e authored by Florian Pose's avatar Florian Pose
Browse files

Indentication in init script.

parent bfc81260
No related branches found
No related tags found
No related merge requests found
...@@ -38,9 +38,9 @@ ...@@ -38,9 +38,9 @@
### BEGIN INIT INFO ### BEGIN INIT INFO
# Provides: ethercat # Provides: ethercat
# Required-Start: $local_fs $syslog $network # Required-Start: $local_fs $syslog $network
# Should-Start: $time # Should-Start: $time ntp
# Required-Stop: $local_fs $syslog $network # Required-Stop: $local_fs $syslog $network
# Should-Stop: $time # Should-Stop: $time ntp
# Default-Start: 3 5 # Default-Start: 3 5
# Default-Stop: 0 1 2 6 # Default-Stop: 0 1 2 6
# Short-Description: IgH EtherCAT master modules # Short-Description: IgH EtherCAT master modules
...@@ -51,9 +51,14 @@ ...@@ -51,9 +51,14 @@
ETHERCAT_CONFIG=/etc/sysconfig/ethercat ETHERCAT_CONFIG=/etc/sysconfig/ethercat
test -r $ETHERCAT_CONFIG || { echo "$ETHERCAT_CONFIG not existing"; if [ ! -r $ETHERCAT_CONFIG ]; then
if [ "$1" = "stop" ]; then exit 0; echo "$ETHERCAT_CONFIG not existing";
else exit 6; fi; } if [ "$1" = "stop" ]; then
exit 0
else
exit 6
fi
fi
. $ETHERCAT_CONFIG . $ETHERCAT_CONFIG
...@@ -62,15 +67,16 @@ test -r $ETHERCAT_CONFIG || { echo "$ETHERCAT_CONFIG not existing"; ...@@ -62,15 +67,16 @@ test -r $ETHERCAT_CONFIG || { echo "$ETHERCAT_CONFIG not existing";
# #
# Function for setting up the EoE bridge # Function for setting up the EoE bridge
# #
build_eoe_bridge() { build_eoe_bridge()
if [ -z "$EOE_BRIDGE" ]; then return; fi {
if [ -z "$EOE_BRIDGE" ]; then return; fi
EOEIF=`/sbin/ifconfig -a | grep -o -E "^eoe[0-9]+ "` EOEIF=`/sbin/ifconfig -a | grep -o -E "^eoe[0-9]+ "`
# add bridge, if it does not already exist # add bridge, if it does not already exist
if ! /sbin/brctl show | grep -E -q "^$EOE_BRIDGE"; then if ! /sbin/brctl show | grep -E -q "^$EOE_BRIDGE"; then
if ! /sbin/brctl addbr $EOE_BRIDGE; then if ! /sbin/brctl addbr $EOE_BRIDGE; then
/bin/false /bin/false
rc_status -v rc_status -v
rc_exit rc_exit
fi fi
...@@ -78,19 +84,19 @@ build_eoe_bridge() { ...@@ -78,19 +84,19 @@ build_eoe_bridge() {
# check if specified interfaces are bridged # check if specified interfaces are bridged
for interf in $EOEIF $EOE_EXTRA_INTERFACES; do for interf in $EOEIF $EOE_EXTRA_INTERFACES; do
# interface is already part of the bridge # interface is already part of the bridge
if /sbin/brctl show $EOE_BRIDGE | grep -E -q $interf if /sbin/brctl show $EOE_BRIDGE | grep -E -q $interf
then continue then continue
fi fi
# clear IP address and open interface # clear IP address and open interface
if ! /sbin/ifconfig $interf 0.0.0.0 up; then if ! /sbin/ifconfig $interf 0.0.0.0 up; then
/bin/false /bin/false
rc_status -v rc_status -v
rc_exit rc_exit
fi fi
# add interface to the bridge # add interface to the bridge
if ! /sbin/brctl addif $EOE_BRIDGE $interf; then if ! /sbin/brctl addif $EOE_BRIDGE $interf; then
/bin/false /bin/false
rc_status -v rc_status -v
rc_exit rc_exit
fi fi
...@@ -98,9 +104,9 @@ build_eoe_bridge() { ...@@ -98,9 +104,9 @@ build_eoe_bridge() {
# configure IP on bridge # configure IP on bridge
if [ -n "$EOE_IP_ADDRESS" -a -n "$EOE_IP_NETMASK" ]; then if [ -n "$EOE_IP_ADDRESS" -a -n "$EOE_IP_NETMASK" ]; then
if ! /sbin/ifconfig $EOE_BRIDGE $EOE_IP_ADDRESS \ if ! /sbin/ifconfig $EOE_BRIDGE $EOE_IP_ADDRESS \
netmask $EOE_IP_NETMASK; then netmask $EOE_IP_NETMASK; then
/bin/false /bin/false
rc_status -v rc_status -v
rc_exit rc_exit
fi fi
...@@ -108,23 +114,23 @@ build_eoe_bridge() { ...@@ -108,23 +114,23 @@ build_eoe_bridge() {
# open bridge # open bridge
if ! /sbin/ifconfig $EOE_BRIDGE up; then if ! /sbin/ifconfig $EOE_BRIDGE up; then
/bin/false /bin/false
rc_status -v rc_status -v
rc_exit rc_exit
fi fi
# install new default gateway # install new default gateway
if [ -n "$EOE_GATEWAY" ]; then if [ -n "$EOE_GATEWAY" ]; then
while /sbin/route -n | grep -E -q "^0.0.0.0"; do while /sbin/route -n | grep -E -q "^0.0.0.0"; do
if ! /sbin/route del default; then if ! /sbin/route del default; then
echo "Failed to remove route!" 1>&2 echo "Failed to remove route!" 1>&2
/bin/false /bin/false
rc_status -v rc_status -v
rc_exit rc_exit
fi fi
done done
if ! /sbin/route add default gw $EOE_GATEWAY; then if ! /sbin/route add default gw $EOE_GATEWAY; then
/bin/false /bin/false
rc_status -v rc_status -v
rc_exit rc_exit
fi fi
...@@ -137,115 +143,113 @@ build_eoe_bridge() { ...@@ -137,115 +143,113 @@ build_eoe_bridge() {
rc_reset rc_reset
case "$1" in case "$1" in
start)
echo -n "Starting EtherCAT master "
if [ -z "$DEVICE_INDEX" ]; then start)
echo "ERROR: DEVICE_INDEX not set!" echo -n "Starting EtherCAT master "
/bin/false
rc_status -v
rc_exit
fi
if [ -z "$EOE_INTERFACES" ]; then if [ -z "$DEVICE_INDEX" ]; then
if [ -n "$EOE_DEVICES" ]; then # support legacy sysconfig files echo "ERROR: DEVICE_INDEX not set!"
EOE_INTERFACES=$EOE_DEVICES /bin/false
else rc_status -v
EOE_INTERFACES=0 rc_exit
fi fi
fi
# unload conflicting modules at first if [ -z "$EOE_INTERFACES" ]; then
for mod in 8139too 8139cp; do if [ -n "$EOE_DEVICES" ]; then # support legacy sysconfig files
if lsmod | grep "^$mod " > /dev/null; then EOE_INTERFACES=$EOE_DEVICES
if ! rmmod $mod; then else
/bin/false EOE_INTERFACES=0
rc_status -v
rc_exit
fi fi
fi fi
done
# load master module # unload conflicting modules at first
if ! modprobe ec_master ec_eoeif_count=$EOE_INTERFACES; then for mod in 8139too 8139cp; do
/bin/false if lsmod | grep "^$mod " > /dev/null; then
rc_status -v if ! rmmod $mod; then
rc_exit /bin/false
fi rc_status -v
rc_exit
fi
fi
done
# load device module # load master module
if ! modprobe ec_8139too ec_device_index=$DEVICE_INDEX; then if ! modprobe ec_master ec_eoeif_count=$EOE_INTERFACES; then
/bin/false /bin/false
rc_status -v rc_status -v
rc_exit rc_exit
fi fi
# build EoE bridge # load device module
build_eoe_bridge if ! modprobe ec_8139too ec_device_index=$DEVICE_INDEX; then
/bin/false
rc_status -v
rc_exit
fi
rc_status -v # build EoE bridge
;; build_eoe_bridge
stop) rc_status -v
echo -n "Shutting down EtherCAT master " ;;
# unload modules stop)
for mod in ec_8139too ec_master; do echo -n "Shutting down EtherCAT master "
if lsmod | grep "^$mod " > /dev/null; then
if ! rmmod $mod; then # unload modules
/bin/false for mod in ec_8139too ec_master; do
rc_status -v if lsmod | grep "^$mod " > /dev/null; then
rc_exit if ! rmmod $mod; then
/bin/false
rc_status -v
rc_exit
fi;
fi; fi;
fi; done
done
sleep 1 sleep 1
# reload previous modules # reload previous modules
if ! modprobe 8139too; then if ! modprobe 8139too; then
echo "Warning: Failed to restore 8139too module." echo "Warning: Failed to restore 8139too module."
fi fi
rc_status -v rc_status -v
;; ;;
restart) restart)
$0 stop || exit 1 $0 stop || exit 1
sleep 1
sleep 1 $0 start
rc_status
$0 start ;;
rc_status
;;
status) status)
echo -n "Checking for EtherCAT " echo -n "Checking for EtherCAT "
lsmod | grep "^ec_master " > /dev/null lsmod | grep "^ec_master " > /dev/null
master_running=$? master_running=$?
lsmod | grep "^ec_8139too " > /dev/null lsmod | grep "^ec_8139too " > /dev/null
device_running=$? device_running=$?
# master module and device module loaded? # master module and device module loaded?
test $master_running -eq 0 -a $device_running -eq 0 test $master_running -eq 0 -a $device_running -eq 0
rc_status -v rc_status -v
;; ;;
bridge) bridge)
echo -n "Building EoE bridge " echo -n "Building EoE bridge "
build_eoe_bridge
build_eoe_bridge rc_status -v
;;
rc_status -v
;;
*) *)
echo "USAGE: $0 {start|stop|restart|status|bridge}" echo "USAGE: $0 {start|stop|restart|status|bridge}"
;; ;;
esac esac
rc_exit rc_exit
#------------------------------------------------------------------------------ #------------------------------------------------------------------------------
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment