Repaired init script status command.
authorFlorian Pose <fp@igh-essen.com>
Fri, 01 Aug 2008 11:09:39 +0000
changeset 1185 337ce4fc2383
parent 1184 75cd6681eb08
child 1186 ff481f097c97
Repaired init script status command.
TODO
configure.ac
script/init.d/Makefile.am
script/init.d/ethercat
script/init.d/ethercat.in
--- a/TODO	Fri Aug 01 10:10:55 2008 +0000
+++ b/TODO	Fri Aug 01 11:09:39 2008 +0000
@@ -8,8 +8,6 @@
 
 Version 1.4.0:
 
-* Abort code messages in userspace.
-* Repair rcethercat status.
 * Attach Pdo names from SII or Coe dictionary to Pdos read via CoE.
 * Update documentation.
 * Check for possible race condition in jiffy-based frame timeout calculation.
@@ -17,10 +15,10 @@
 Future issues:
 
 * Distributed clocks.
-* Allow master requesting when in ORPHANED phase
+* Implement user space realtime interface via cdev.
 * Move master threads, slave handlers and state machines into a user
   space daemon.
-* Implement user space realtime interface via cdev.
+* Allow master requesting when in ORPHANED phase
 * Mailbox protocol handlers.
 * Mailbox state machine using toggle bits.
 * Mailbox gateway.
--- a/configure.ac	Fri Aug 01 10:10:55 2008 +0000
+++ b/configure.ac	Fri Aug 01 11:09:39 2008 +0000
@@ -503,6 +503,7 @@
         master/Makefile
         script/Makefile
         script/init.d/Makefile
+        script/init.d/ethercat
         script/sysconfig/Makefile
         tool/Makefile
 ])
--- a/script/init.d/Makefile.am	Fri Aug 01 10:10:55 2008 +0000
+++ b/script/init.d/Makefile.am	Fri Aug 01 11:09:39 2008 +0000
@@ -35,6 +35,8 @@
 
 init_SCRIPTS = ethercat
 
-EXTRA_DIST = ethercat
+EXTRA_DIST = ethercat.in
+
+BUILT_SOURCES = ethercat
 
 #------------------------------------------------------------------------------
--- a/script/init.d/ethercat	Fri Aug 01 10:10:55 2008 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,263 +0,0 @@
-#!/bin/sh
-
-#------------------------------------------------------------------------------
-#
-#  Init script for EtherCAT
-#
-#  $Id$
-#
-#  Copyright (C) 2006  Florian Pose, Ingenieurgemeinschaft IgH
-#
-#  This file is part of the IgH EtherCAT Master.
-#
-#  The IgH EtherCAT Master is free software; you can redistribute it
-#  and/or modify it under the terms of the GNU General Public License
-#  as published by the Free Software Foundation; either version 2 of the
-#  License, or (at your option) any later version.
-#
-#  The IgH EtherCAT Master is distributed in the hope that it will be
-#  useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
-#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-#  GNU General Public License for more details.
-#
-#  You should have received a copy of the GNU General Public License
-#  along with the IgH EtherCAT Master; if not, write to the Free Software
-#  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
-#
-#  The right to use EtherCAT Technology is granted and comes free of
-#  charge under condition of compatibility of product made by
-#  Licensee. People intending to distribute/sell products based on the
-#  code, have to sign an agreement to guarantee that products using
-#  software based on IgH EtherCAT master stay compatible with the actual
-#  EtherCAT specification (which are released themselves as an open
-#  standard) as the (only) precondition to have the right to use EtherCAT
-#  Technology, IP and trade marks.
-#
-#------------------------------------------------------------------------------
-
-### BEGIN INIT INFO
-# Provides:          ethercat
-# Required-Start:    $local_fs $syslog $network
-# Should-Start:      $time ntp
-# Required-Stop:     $local_fs $syslog $network
-# Should-Stop:       $time ntp
-# Default-Start:     3 5
-# Default-Stop:      0 1 2 6
-# Short-Description: EtherCAT Master
-# Description:
-### END INIT INFO
-
-#------------------------------------------------------------------------------
-
-MODPROBE=/sbin/modprobe
-RMMOD=/sbin/rmmod
-MODINFO=/sbin/modinfo
-
-#------------------------------------------------------------------------------
-
-ETHERCAT_CONFIG=/etc/sysconfig/ethercat
-
-if [ ! -r ${ETHERCAT_CONFIG} ]; then
-    echo ${ETHERCAT_CONFIG} not existing;
-    if [ "${1}" = "stop" ]; then
-	exit 0
-    else
-	exit 6
-    fi
-fi
-
-. ${ETHERCAT_CONFIG}
-
-#------------------------------------------------------------------------------
-
-function exit_success()
-{
-    if [ -r /etc/rc.status ]; then
-        rc_reset
-        rc_status -v
-        rc_exit
-    else
-        echo " done"
-        exit 0
-    fi
-}
-
-#------------------------------------------------------------------------------
-
-function exit_running()
-{
-    if [ -r /etc/rc.status ]; then
-        rc_reset
-        rc_status -v
-        rc_exit
-    else
-        echo " running"
-        exit 0
-    fi
-}
-
-#------------------------------------------------------------------------------
-
-function exit_fail()
-{
-    if [ -r /etc/rc.status ]; then
-        rc_failed
-        rc_status -v
-        rc_exit
-    else
-        echo " failed"
-        exit 1
-    fi
-}
-
-#------------------------------------------------------------------------------
-
-function exit_dead()
-{
-    if [ -r /etc/rc.status ]; then
-        rc_failed
-        rc_status -v
-        rc_exit
-    else
-        echo " dead"
-        exit 1
-    fi
-}
-
-#------------------------------------------------------------------------------
-
-function parse_mac_address()
-{
-    if [ -z "${1}" ]; then
-        MAC=""
-    elif echo ${1} | grep -qE '^([0-9a-fA-F]{2}:){5}[0-9a-fA-F]{2}$'; then
-        MAC=${1}
-    else
-        echo Invalid MAC address \"${1}\" in ${ETHERCAT_CONFIG}
-        exit_fail
-    fi 
-}
-
-#------------------------------------------------------------------------------
-
-if [ -r /etc/rc.status ]; then
-    . /etc/rc.status
-    rc_reset
-fi
-
-case "${1}" in
-
-start)
-    echo -n "Starting EtherCAT master "
-
-    # construct DEVICES and BACKUPS from configuration variables
-    DEVICES=""
-    BACKUPS=""
-    MASTER_INDEX=0
-    while true; do
-        DEVICE=$(eval echo "\${MASTER${MASTER_INDEX}_DEVICE}")
-        BACKUP=$(eval echo "\${MASTER${MASTER_INDEX}_BACKUP}")
-        if [ -z "${DEVICE}" ]; then break; fi
-
-        if [ ${MASTER_INDEX} -gt 0 ]; then
-            DEVICES=${DEVICES},
-            BACKUPS=${BACKUPS},
-        fi
-
-        parse_mac_address ${DEVICE}
-        DEVICES=${DEVICES}${MAC}
-        
-        parse_mac_address ${BACKUP}
-        BACKUPS=${BACKUPS}${MAC}
-
-        MASTER_INDEX=$(expr ${MASTER_INDEX} + 1)
-    done
-
-    # load master module
-    if ! ${MODPROBE} ${MODPROBE_FLAGS} ec_master \
-            main_devices=${DEVICES} backup_devices=${BACKUPS}; then
-        exit_fail
-    fi
-
-    # check for modules to replace
-    for MODULE in ${DEVICE_MODULES}; do
-        ECMODULE=ec_${MODULE}
-        if ! ${MODINFO} ${ECMODULE} > /dev/null; then
-            continue # ec_* module not found
-        fi
-        if lsmod | grep "^${MODULE} " > /dev/null; then
-            if ! ${RMMOD} ${MODULE}; then
-                exit_fail
-            fi
-        fi
-        if ! ${MODPROBE} ${MODPROBE_FLAGS} ${ECMODULE}; then
-            ${MODPROBE} ${MODPROBE_FLAGS} ${MODULE} # try to restore module
-            exit_fail
-        fi
-    done
-
-    exit_success
-    ;;
-
-stop)
-    echo -n "Shutting down EtherCAT master "
-
-    # unload EtherCAT device modules
-    for MODULE in ${DEVICE_MODULES} master; do
-        ECMODULE=ec_${MODULE}
-        if ! lsmod | grep -q "^${ECMODULE} "; then
-            continue # ec_* module not loaded
-        fi
-        if ! ${RMMOD} ${ECMODULE}; then
-            exit_fail
-        fi;
-    done
-
-    sleep 1
-
-    # reload previous modules
-    for MODULE in ${DEVICE_MODULES}; do
-        if ! ${MODPROBE} ${MODPROBE_FLAGS} ${MODULE}; then
-            echo Warning: Failed to restore ${MODULE}.
-        fi
-    done
-
-    exit_success
-    ;;
-
-restart)
-    $0 stop || exit 1
-    sleep 1
-    $0 start
-    ;;
-
-status)
-    echo -n "Checking for EtherCAT "
-
-    lsmod | grep -q "^ec_master "
-    MASTERS_RUNNING=$?
-
-    ! grep -q "(WAITING)" /sys/ethercat/master*/info
-    MASTERS_IDLE=$?
-
-    # master module loaded and masters not waiting for devices?
-    if [ ${MASTERS_RUNNING} -eq 0 -a ${MASTERS_IDLE} -eq 0 ]; then
-        exit_running
-    else
-        exit_dead
-    fi
-    ;;
-
-*)
-    echo "USAGE: $0 {start|stop|restart|status}"
-    ;;
-
-esac
-
-if [ -r /etc/rc.status ]; then
-    rc_exit
-else
-    exit 1
-fi
-
-#------------------------------------------------------------------------------
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/script/init.d/ethercat.in	Fri Aug 01 11:09:39 2008 +0000
@@ -0,0 +1,275 @@
+#!/bin/sh
+
+#------------------------------------------------------------------------------
+#
+#  Init script for EtherCAT
+#
+#  $Id$
+#
+#  Copyright (C) 2006  Florian Pose, Ingenieurgemeinschaft IgH
+#
+#  This file is part of the IgH EtherCAT Master.
+#
+#  The IgH EtherCAT Master is free software; you can redistribute it
+#  and/or modify it under the terms of the GNU General Public License
+#  as published by the Free Software Foundation; either version 2 of the
+#  License, or (at your option) any later version.
+#
+#  The IgH EtherCAT Master is distributed in the hope that it will be
+#  useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
+#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+#  GNU General Public License for more details.
+#
+#  You should have received a copy of the GNU General Public License
+#  along with the IgH EtherCAT Master; if not, write to the Free Software
+#  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+#
+#  The right to use EtherCAT Technology is granted and comes free of
+#  charge under condition of compatibility of product made by
+#  Licensee. People intending to distribute/sell products based on the
+#  code, have to sign an agreement to guarantee that products using
+#  software based on IgH EtherCAT master stay compatible with the actual
+#  EtherCAT specification (which are released themselves as an open
+#  standard) as the (only) precondition to have the right to use EtherCAT
+#  Technology, IP and trade marks.
+#
+#------------------------------------------------------------------------------
+
+### BEGIN INIT INFO
+# Provides:          ethercat
+# Required-Start:    $local_fs $syslog $network
+# Should-Start:      $time ntp
+# Required-Stop:     $local_fs $syslog $network
+# Should-Stop:       $time ntp
+# Default-Start:     3 5
+# Default-Stop:      0 1 2 6
+# Short-Description: EtherCAT master
+# Description:       EtherCAT master @VERSION@
+### END INIT INFO
+
+#------------------------------------------------------------------------------
+
+MODPROBE=/sbin/modprobe
+RMMOD=/sbin/rmmod
+MODINFO=/sbin/modinfo
+ETHERCAT=@prefix@/bin/ethercat
+
+#------------------------------------------------------------------------------
+
+ETHERCAT_CONFIG=/etc/sysconfig/ethercat
+
+if [ ! -r ${ETHERCAT_CONFIG} ]; then
+    echo ${ETHERCAT_CONFIG} not existing;
+    if [ "${1}" = "stop" ]; then
+	exit 0
+    else
+	exit 6
+    fi
+fi
+
+. ${ETHERCAT_CONFIG}
+
+#------------------------------------------------------------------------------
+
+function exit_success()
+{
+    if [ -r /etc/rc.status ]; then
+        rc_reset
+        rc_status -v
+        rc_exit
+    else
+        echo " done"
+        exit 0
+    fi
+}
+
+#------------------------------------------------------------------------------
+
+function exit_fail()
+{
+    if [ -r /etc/rc.status ]; then
+        rc_failed
+        rc_status -v
+        rc_exit
+    else
+        echo " failed"
+        exit 1
+    fi
+}
+
+#------------------------------------------------------------------------------
+
+function print_running()
+{
+    if [ -r /etc/rc.status ]; then
+        rc_reset
+        rc_status -v
+    else
+        echo " running"
+    fi
+}
+
+#------------------------------------------------------------------------------
+
+function print_dead()
+{
+    if [ -r /etc/rc.status ]; then
+        rc_failed
+        rc_status -v
+    else
+        echo " dead"
+    fi
+}
+
+#------------------------------------------------------------------------------
+
+function parse_mac_address()
+{
+    if [ -z "${1}" ]; then
+        MAC=""
+    elif echo ${1} | grep -qE '^([0-9a-fA-F]{2}:){5}[0-9a-fA-F]{2}$'; then
+        MAC=${1}
+    else
+        echo Invalid MAC address \"${1}\" in ${ETHERCAT_CONFIG}
+        exit_fail
+    fi 
+}
+
+#------------------------------------------------------------------------------
+
+if [ -r /etc/rc.status ]; then
+    . /etc/rc.status
+    rc_reset
+fi
+
+case "${1}" in
+
+start)
+    echo -n "Starting EtherCAT master @VERSION@"
+
+    # construct DEVICES and BACKUPS from configuration variables
+    DEVICES=""
+    BACKUPS=""
+    MASTER_INDEX=0
+    while true; do
+        DEVICE=$(eval echo "\${MASTER${MASTER_INDEX}_DEVICE}")
+        BACKUP=$(eval echo "\${MASTER${MASTER_INDEX}_BACKUP}")
+        if [ -z "${DEVICE}" ]; then break; fi
+
+        if [ ${MASTER_INDEX} -gt 0 ]; then
+            DEVICES=${DEVICES},
+            BACKUPS=${BACKUPS},
+        fi
+
+        parse_mac_address ${DEVICE}
+        DEVICES=${DEVICES}${MAC}
+        
+        parse_mac_address ${BACKUP}
+        BACKUPS=${BACKUPS}${MAC}
+
+        MASTER_INDEX=$(expr ${MASTER_INDEX} + 1)
+    done
+
+    # load master module
+    if ! ${MODPROBE} ${MODPROBE_FLAGS} ec_master \
+            main_devices=${DEVICES} backup_devices=${BACKUPS}; then
+        exit_fail
+    fi
+
+    # check for modules to replace
+    for MODULE in ${DEVICE_MODULES}; do
+        ECMODULE=ec_${MODULE}
+        if ! ${MODINFO} ${ECMODULE} > /dev/null; then
+            continue # ec_* module not found
+        fi
+        if lsmod | grep "^${MODULE} " > /dev/null; then
+            if ! ${RMMOD} ${MODULE}; then
+                exit_fail
+            fi
+        fi
+        if ! ${MODPROBE} ${MODPROBE_FLAGS} ${ECMODULE}; then
+            ${MODPROBE} ${MODPROBE_FLAGS} ${MODULE} # try to restore module
+            exit_fail
+        fi
+    done
+
+    exit_success
+    ;;
+
+stop)
+    echo -n "Shutting down EtherCAT master @VERSION@"
+
+    # unload EtherCAT device modules
+    for MODULE in ${DEVICE_MODULES} master; do
+        ECMODULE=ec_${MODULE}
+        if ! lsmod | grep -q "^${ECMODULE} "; then
+            continue # ec_* module not loaded
+        fi
+        if ! ${RMMOD} ${ECMODULE}; then
+            exit_fail
+        fi;
+    done
+
+    sleep 1
+
+    # reload previous modules
+    for MODULE in ${DEVICE_MODULES}; do
+        if ! ${MODPROBE} ${MODPROBE_FLAGS} ${MODULE}; then
+            echo Warning: Failed to restore ${MODULE}.
+        fi
+    done
+
+    exit_success
+    ;;
+
+restart)
+    $0 stop || exit 1
+    sleep 1
+    $0 start
+    ;;
+
+status)
+    echo "Checking for EtherCAT master @VERSION@"
+
+    # count masters in configuration file
+    MASTER_COUNT=0
+    while true; do
+        DEVICE=$(eval echo "\${MASTER${MASTER_COUNT}_DEVICE}")
+        if [ -z "${DEVICE}" ]; then break; fi
+        MASTER_COUNT=$(expr ${MASTER_COUNT} + 1)
+    done
+
+    RESULT=0
+
+    for i in `seq 0 $(expr ${MASTER_COUNT} - 1)`; do
+        echo -n "Master${i}"
+        
+        # Check if the master is in idle or operation phase
+        ${ETHERCAT} master --master ${i} 2>/dev/null | \
+            grep -qE 'Phase:[[:space:]]*Idle|Phase:[[:space:]]*Operation'
+        EXITCODE=$?
+
+        if [ ${EXITCODE} -eq 0 ]; then
+            print_running
+        else
+            print_dead
+            RESULT=1
+        fi
+    done
+
+    exit ${RESULT}
+    ;;
+
+*)
+    echo "USAGE: $0 {start|stop|restart|status}"
+    ;;
+
+esac
+
+if [ -r /etc/rc.status ]; then
+    rc_exit
+else
+    exit 1
+fi
+
+#------------------------------------------------------------------------------