script/ethercatctl.in
author Florian Pose <fp@igh-essen.com>
Mon, 23 Jul 2012 15:32:42 +0200
changeset 2398 a6e2874fb0bd
parent 2190 3fe304fea395
child 2543 0d978e56a635
child 2560 442634814e29
child 2589 2b9c78543663
permissions -rwxr-xr-x
Fixed 8139too driver for 2.6.36.
2189
002b978df979 Added first systemd support.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     1
#!/bin/sh
002b978df979 Added first systemd support.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     2
002b978df979 Added first systemd support.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     3
#------------------------------------------------------------------------------
002b978df979 Added first systemd support.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     4
#
002b978df979 Added first systemd support.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     5
#  Start script for EtherCAT to use with systemd
002b978df979 Added first systemd support.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     6
#
002b978df979 Added first systemd support.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     7
#  $Id$
002b978df979 Added first systemd support.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     8
#
002b978df979 Added first systemd support.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     9
#  Copyright (C) 2006-2012  Florian Pose, Ingenieurgemeinschaft IgH
002b978df979 Added first systemd support.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    10
#
002b978df979 Added first systemd support.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    11
#  This file is part of the IgH EtherCAT Master.
002b978df979 Added first systemd support.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    12
#
002b978df979 Added first systemd support.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    13
#  The IgH EtherCAT Master is free software; you can redistribute it and/or
002b978df979 Added first systemd support.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    14
#  modify it under the terms of the GNU General Public License version 2, as
002b978df979 Added first systemd support.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    15
#  published by the Free Software Foundation.
002b978df979 Added first systemd support.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    16
#
002b978df979 Added first systemd support.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    17
#  The IgH EtherCAT Master is distributed in the hope that it will be useful,
002b978df979 Added first systemd support.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    18
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
002b978df979 Added first systemd support.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    19
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General
002b978df979 Added first systemd support.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    20
#  Public License for more details.
002b978df979 Added first systemd support.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    21
#
002b978df979 Added first systemd support.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    22
#  You should have received a copy of the GNU General Public License along
002b978df979 Added first systemd support.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    23
#  with the IgH EtherCAT Master; if not, write to the Free Software
002b978df979 Added first systemd support.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    24
#  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
002b978df979 Added first systemd support.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    25
#
002b978df979 Added first systemd support.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    26
#  ---
002b978df979 Added first systemd support.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    27
#
002b978df979 Added first systemd support.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    28
#  The license mentioned above concerns the source code only. Using the
002b978df979 Added first systemd support.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    29
#  EtherCAT technology and brand is only permitted in compliance with the
002b978df979 Added first systemd support.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    30
#  industrial property and similar rights of Beckhoff Automation GmbH.
002b978df979 Added first systemd support.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    31
#
002b978df979 Added first systemd support.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    32
#  vim: expandtab sw=4 tw=78
002b978df979 Added first systemd support.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    33
#
002b978df979 Added first systemd support.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    34
#------------------------------------------------------------------------------
002b978df979 Added first systemd support.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    35
002b978df979 Added first systemd support.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    36
MODPROBE=/sbin/modprobe
002b978df979 Added first systemd support.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    37
RMMOD=/sbin/rmmod
002b978df979 Added first systemd support.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    38
MODINFO=/sbin/modinfo
002b978df979 Added first systemd support.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    39
002b978df979 Added first systemd support.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    40
ETHERCAT=@prefix@/bin/ethercat
002b978df979 Added first systemd support.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    41
002b978df979 Added first systemd support.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    42
#------------------------------------------------------------------------------
002b978df979 Added first systemd support.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    43
002b978df979 Added first systemd support.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    44
ETHERCAT_CONFIG=/etc/ethercat.conf
002b978df979 Added first systemd support.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    45
002b978df979 Added first systemd support.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    46
if [ ! -r ${ETHERCAT_CONFIG} ]; then
002b978df979 Added first systemd support.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    47
    echo ${ETHERCAT_CONFIG} not existing;
002b978df979 Added first systemd support.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    48
    exit 6
002b978df979 Added first systemd support.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    49
fi
002b978df979 Added first systemd support.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    50
002b978df979 Added first systemd support.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    51
. ${ETHERCAT_CONFIG}
002b978df979 Added first systemd support.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    52
002b978df979 Added first systemd support.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    53
#------------------------------------------------------------------------------
002b978df979 Added first systemd support.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    54
002b978df979 Added first systemd support.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    55
parse_mac_address() {
002b978df979 Added first systemd support.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    56
    if [ -z "${1}" ]; then
002b978df979 Added first systemd support.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    57
        MAC=""
002b978df979 Added first systemd support.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    58
    elif echo ${1} | grep -qE '^([0-9a-fA-F]{2}:){5}[0-9a-fA-F]{2}$'; then
002b978df979 Added first systemd support.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    59
        MAC=${1}
002b978df979 Added first systemd support.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    60
    else
002b978df979 Added first systemd support.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    61
        echo Invalid MAC address \"${1}\" in ${ETHERCAT_CONFIG}
002b978df979 Added first systemd support.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    62
        exit 1
002b978df979 Added first systemd support.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    63
    fi
002b978df979 Added first systemd support.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    64
}
002b978df979 Added first systemd support.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    65
002b978df979 Added first systemd support.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    66
#------------------------------------------------------------------------------
002b978df979 Added first systemd support.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    67
002b978df979 Added first systemd support.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    68
case "${1}" in
002b978df979 Added first systemd support.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    69
002b978df979 Added first systemd support.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    70
start)
002b978df979 Added first systemd support.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    71
    # construct DEVICES and BACKUPS from configuration variables
002b978df979 Added first systemd support.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    72
    DEVICES=""
002b978df979 Added first systemd support.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    73
    BACKUPS=""
002b978df979 Added first systemd support.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    74
    MASTER_INDEX=0
002b978df979 Added first systemd support.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    75
002b978df979 Added first systemd support.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    76
    while true; do
002b978df979 Added first systemd support.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    77
        DEVICE=$(eval echo "\${MASTER${MASTER_INDEX}_DEVICE}")
002b978df979 Added first systemd support.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    78
        BACKUP=$(eval echo "\${MASTER${MASTER_INDEX}_BACKUP}")
002b978df979 Added first systemd support.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    79
        if [ -z "${DEVICE}" ]; then break; fi
002b978df979 Added first systemd support.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    80
002b978df979 Added first systemd support.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    81
        if [ ${MASTER_INDEX} -gt 0 ]; then
002b978df979 Added first systemd support.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    82
            DEVICES=${DEVICES},
002b978df979 Added first systemd support.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    83
            BACKUPS=${BACKUPS},
002b978df979 Added first systemd support.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    84
        fi
002b978df979 Added first systemd support.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    85
002b978df979 Added first systemd support.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    86
        parse_mac_address ${DEVICE}
002b978df979 Added first systemd support.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    87
        DEVICES=${DEVICES}${MAC}
002b978df979 Added first systemd support.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    88
002b978df979 Added first systemd support.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    89
        parse_mac_address ${BACKUP}
002b978df979 Added first systemd support.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    90
        BACKUPS=${BACKUPS}${MAC}
002b978df979 Added first systemd support.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    91
002b978df979 Added first systemd support.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    92
        MASTER_INDEX=$(expr ${MASTER_INDEX} + 1)
002b978df979 Added first systemd support.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    93
    done
002b978df979 Added first systemd support.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    94
002b978df979 Added first systemd support.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    95
    # load master module
002b978df979 Added first systemd support.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    96
    if ! ${MODPROBE} ${MODPROBE_FLAGS} ec_master \
002b978df979 Added first systemd support.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    97
            main_devices=${DEVICES} backup_devices=${BACKUPS}; then
002b978df979 Added first systemd support.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    98
        exit 1
002b978df979 Added first systemd support.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    99
    fi
002b978df979 Added first systemd support.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   100
002b978df979 Added first systemd support.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   101
    LOADED_MODULES=ec_master
002b978df979 Added first systemd support.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   102
002b978df979 Added first systemd support.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   103
    # check for modules to replace
002b978df979 Added first systemd support.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   104
    for MODULE in ${DEVICE_MODULES}; do
002b978df979 Added first systemd support.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   105
        ECMODULE=ec_${MODULE}
002b978df979 Added first systemd support.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   106
        if ! ${MODINFO} ${ECMODULE} > /dev/null; then
002b978df979 Added first systemd support.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   107
            continue # ec_* module not found
002b978df979 Added first systemd support.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   108
        fi
002b978df979 Added first systemd support.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   109
002b978df979 Added first systemd support.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   110
        if [ ${MODULE} != "generic" ]; then
002b978df979 Added first systemd support.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   111
            # try to unload standard module
002b978df979 Added first systemd support.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   112
            if lsmod | grep "^${MODULE} " > /dev/null; then
002b978df979 Added first systemd support.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   113
                if ! ${RMMOD} ${MODULE}; then
002b978df979 Added first systemd support.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   114
                    ${RMMOD} ${LOADED_MODULES}
002b978df979 Added first systemd support.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   115
                    exit 1
002b978df979 Added first systemd support.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   116
                fi
002b978df979 Added first systemd support.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   117
            fi
002b978df979 Added first systemd support.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   118
        fi
002b978df979 Added first systemd support.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   119
002b978df979 Added first systemd support.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   120
        if ! ${MODPROBE} ${MODPROBE_FLAGS} ${ECMODULE}; then
002b978df979 Added first systemd support.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   121
            if [ ${MODULE} != "generic" ]; then
002b978df979 Added first systemd support.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   122
                ${MODPROBE} ${MODPROBE_FLAGS} ${MODULE} # try to restore
002b978df979 Added first systemd support.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   123
            fi
002b978df979 Added first systemd support.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   124
            ${RMMOD} ${LOADED_MODULES}
002b978df979 Added first systemd support.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   125
            exit 1
002b978df979 Added first systemd support.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   126
        fi
002b978df979 Added first systemd support.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   127
2190
3fe304fea395 Fixed appending to LOADED_MODULES variable.
Florian Pose <fp@igh-essen.com>
parents: 2189
diff changeset
   128
        LOADED_MODULES="${ECMODULE} ${LOADED_MODULES}"
2189
002b978df979 Added first systemd support.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   129
    done
002b978df979 Added first systemd support.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   130
002b978df979 Added first systemd support.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   131
    exit 0
002b978df979 Added first systemd support.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   132
    ;;
002b978df979 Added first systemd support.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   133
002b978df979 Added first systemd support.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   134
#------------------------------------------------------------------------------
002b978df979 Added first systemd support.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   135
002b978df979 Added first systemd support.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   136
stop)
002b978df979 Added first systemd support.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   137
    # unload EtherCAT device modules
002b978df979 Added first systemd support.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   138
    for MODULE in ${DEVICE_MODULES} master; do
002b978df979 Added first systemd support.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   139
        ECMODULE=ec_${MODULE}
002b978df979 Added first systemd support.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   140
        if ! lsmod | grep -q "^${ECMODULE} "; then
002b978df979 Added first systemd support.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   141
            continue # ec_* module not loaded
002b978df979 Added first systemd support.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   142
        fi
002b978df979 Added first systemd support.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   143
        if ! ${RMMOD} ${ECMODULE}; then
002b978df979 Added first systemd support.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   144
            exit 1
002b978df979 Added first systemd support.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   145
        fi;
002b978df979 Added first systemd support.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   146
    done
002b978df979 Added first systemd support.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   147
002b978df979 Added first systemd support.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   148
    sleep 1
002b978df979 Added first systemd support.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   149
002b978df979 Added first systemd support.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   150
    # load standard modules again
002b978df979 Added first systemd support.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   151
    for MODULE in ${DEVICE_MODULES}; do
002b978df979 Added first systemd support.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   152
        if [ ${MODULE} == "generic" ]; then
002b978df979 Added first systemd support.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   153
            continue
002b978df979 Added first systemd support.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   154
        fi
002b978df979 Added first systemd support.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   155
        ${MODPROBE} ${MODPROBE_FLAGS} ${MODULE}
002b978df979 Added first systemd support.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   156
    done
002b978df979 Added first systemd support.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   157
002b978df979 Added first systemd support.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   158
    exit 0
002b978df979 Added first systemd support.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   159
    ;;
002b978df979 Added first systemd support.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   160
002b978df979 Added first systemd support.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   161
#------------------------------------------------------------------------------
002b978df979 Added first systemd support.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   162
002b978df979 Added first systemd support.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   163
restart)
002b978df979 Added first systemd support.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   164
    $0 stop || exit 1
002b978df979 Added first systemd support.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   165
    sleep 1
002b978df979 Added first systemd support.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   166
    $0 start
002b978df979 Added first systemd support.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   167
    ;;
002b978df979 Added first systemd support.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   168
002b978df979 Added first systemd support.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   169
#------------------------------------------------------------------------------
002b978df979 Added first systemd support.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   170
002b978df979 Added first systemd support.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   171
status)
002b978df979 Added first systemd support.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   172
    echo "Checking for EtherCAT master @VERSION@ "
002b978df979 Added first systemd support.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   173
002b978df979 Added first systemd support.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   174
    # count masters in configuration file
002b978df979 Added first systemd support.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   175
    MASTER_COUNT=0
002b978df979 Added first systemd support.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   176
    while true; do
002b978df979 Added first systemd support.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   177
        DEVICE=$(eval echo "\${MASTER${MASTER_COUNT}_DEVICE}")
002b978df979 Added first systemd support.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   178
        if [ -z "${DEVICE}" ]; then break; fi
002b978df979 Added first systemd support.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   179
        MASTER_COUNT=$(expr ${MASTER_COUNT} + 1)
002b978df979 Added first systemd support.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   180
    done
002b978df979 Added first systemd support.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   181
002b978df979 Added first systemd support.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   182
    RESULT=0
002b978df979 Added first systemd support.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   183
002b978df979 Added first systemd support.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   184
    for i in `seq 0 $(expr ${MASTER_COUNT} - 1)`; do
002b978df979 Added first systemd support.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   185
        echo -n "Master${i} "
002b978df979 Added first systemd support.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   186
002b978df979 Added first systemd support.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   187
        # Check if the master is in idle or operation phase
002b978df979 Added first systemd support.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   188
        ${ETHERCAT} master --master ${i} 2>/dev/null | \
002b978df979 Added first systemd support.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   189
            grep -qE 'Phase:[[:space:]]*Idle|Phase:[[:space:]]*Operation'
002b978df979 Added first systemd support.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   190
        EXITCODE=$?
002b978df979 Added first systemd support.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   191
002b978df979 Added first systemd support.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   192
        if [ ${EXITCODE} -eq 0 ]; then
002b978df979 Added first systemd support.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   193
            echo " running"
002b978df979 Added first systemd support.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   194
        else
002b978df979 Added first systemd support.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   195
            echo " dead"
002b978df979 Added first systemd support.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   196
            RESULT=1
002b978df979 Added first systemd support.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   197
        fi
002b978df979 Added first systemd support.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   198
    done
002b978df979 Added first systemd support.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   199
002b978df979 Added first systemd support.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   200
    exit ${RESULT}
002b978df979 Added first systemd support.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   201
    ;;
002b978df979 Added first systemd support.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   202
002b978df979 Added first systemd support.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   203
#------------------------------------------------------------------------------
002b978df979 Added first systemd support.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   204
002b978df979 Added first systemd support.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   205
*)
002b978df979 Added first systemd support.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   206
    echo "USAGE: $0 {start|stop|restart|status}"
002b978df979 Added first systemd support.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   207
    exit 1
002b978df979 Added first systemd support.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   208
    ;;
002b978df979 Added first systemd support.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   209
esac
002b978df979 Added first systemd support.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   210
002b978df979 Added first systemd support.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   211
#------------------------------------------------------------------------------