script/ethercatctl.in
author Florian Pose <fp@igh-essen.com>
Wed, 22 Jun 2016 14:08:34 +0200
changeset 2652 973060629fc6
parent 2589 2b9c78543663
permissions -rwxr-xr-x
Minor change.
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
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2190
diff changeset
    36
LSMOD=/sbin/lsmod
2189
002b978df979 Added first systemd support.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    37
MODPROBE=/sbin/modprobe
002b978df979 Added first systemd support.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    38
RMMOD=/sbin/rmmod
002b978df979 Added first systemd support.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    39
MODINFO=/sbin/modinfo
002b978df979 Added first systemd support.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    40
002b978df979 Added first systemd support.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    41
ETHERCAT=@prefix@/bin/ethercat
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
002b978df979 Added first systemd support.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    45
ETHERCAT_CONFIG=/etc/ethercat.conf
002b978df979 Added first systemd support.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    46
002b978df979 Added first systemd support.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    47
if [ ! -r ${ETHERCAT_CONFIG} ]; then
002b978df979 Added first systemd support.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    48
    echo ${ETHERCAT_CONFIG} not existing;
002b978df979 Added first systemd support.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    49
    exit 6
002b978df979 Added first systemd support.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    50
fi
002b978df979 Added first systemd support.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    51
002b978df979 Added first systemd support.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    52
. ${ETHERCAT_CONFIG}
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
002b978df979 Added first systemd support.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    56
parse_mac_address() {
002b978df979 Added first systemd support.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    57
    if [ -z "${1}" ]; then
002b978df979 Added first systemd support.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    58
        MAC=""
002b978df979 Added first systemd support.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    59
    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
    60
        MAC=${1}
002b978df979 Added first systemd support.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    61
    else
002b978df979 Added first systemd support.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    62
        echo Invalid MAC address \"${1}\" in ${ETHERCAT_CONFIG}
002b978df979 Added first systemd support.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    63
        exit 1
002b978df979 Added first systemd support.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    64
    fi
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
002b978df979 Added first systemd support.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    69
case "${1}" in
002b978df979 Added first systemd support.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    70
002b978df979 Added first systemd support.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    71
start)
002b978df979 Added first systemd support.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    72
    # construct DEVICES and BACKUPS from configuration variables
002b978df979 Added first systemd support.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    73
    DEVICES=""
002b978df979 Added first systemd support.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    74
    BACKUPS=""
002b978df979 Added first systemd support.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    75
    MASTER_INDEX=0
002b978df979 Added first systemd support.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    76
002b978df979 Added first systemd support.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    77
    while true; do
002b978df979 Added first systemd support.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    78
        DEVICE=$(eval echo "\${MASTER${MASTER_INDEX}_DEVICE}")
002b978df979 Added first systemd support.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    79
        BACKUP=$(eval echo "\${MASTER${MASTER_INDEX}_BACKUP}")
002b978df979 Added first systemd support.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    80
        if [ -z "${DEVICE}" ]; then break; fi
002b978df979 Added first systemd support.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    81
002b978df979 Added first systemd support.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    82
        if [ ${MASTER_INDEX} -gt 0 ]; then
002b978df979 Added first systemd support.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    83
            DEVICES=${DEVICES},
002b978df979 Added first systemd support.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    84
            BACKUPS=${BACKUPS},
002b978df979 Added first systemd support.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    85
        fi
002b978df979 Added first systemd support.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    86
002b978df979 Added first systemd support.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    87
        parse_mac_address ${DEVICE}
002b978df979 Added first systemd support.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    88
        DEVICES=${DEVICES}${MAC}
002b978df979 Added first systemd support.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    89
002b978df979 Added first systemd support.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    90
        parse_mac_address ${BACKUP}
002b978df979 Added first systemd support.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    91
        BACKUPS=${BACKUPS}${MAC}
002b978df979 Added first systemd support.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    92
002b978df979 Added first systemd support.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    93
        MASTER_INDEX=$(expr ${MASTER_INDEX} + 1)
002b978df979 Added first systemd support.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    94
    done
002b978df979 Added first systemd support.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    95
002b978df979 Added first systemd support.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    96
    # load master module
002b978df979 Added first systemd support.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    97
    if ! ${MODPROBE} ${MODPROBE_FLAGS} ec_master \
002b978df979 Added first systemd support.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    98
            main_devices=${DEVICES} backup_devices=${BACKUPS}; then
002b978df979 Added first systemd support.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    99
        exit 1
002b978df979 Added first systemd support.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   100
    fi
002b978df979 Added first systemd support.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   101
002b978df979 Added first systemd support.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   102
    LOADED_MODULES=ec_master
002b978df979 Added first systemd support.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   103
002b978df979 Added first systemd support.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   104
    # check for modules to replace
002b978df979 Added first systemd support.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   105
    for MODULE in ${DEVICE_MODULES}; do
002b978df979 Added first systemd support.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   106
        ECMODULE=ec_${MODULE}
002b978df979 Added first systemd support.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   107
        if ! ${MODINFO} ${ECMODULE} > /dev/null; then
002b978df979 Added first systemd support.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   108
            continue # ec_* module not found
002b978df979 Added first systemd support.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   109
        fi
002b978df979 Added first systemd support.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   110
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2190
diff changeset
   111
        if [ ${MODULE} != "generic" -a ${MODULE} != "ccat" ]; then
2189
002b978df979 Added first systemd support.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   112
            # try to unload standard module
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2190
diff changeset
   113
            if ${LSMOD} | grep "^${MODULE} " > /dev/null; then
2189
002b978df979 Added first systemd support.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   114
                if ! ${RMMOD} ${MODULE}; then
002b978df979 Added first systemd support.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   115
                    ${RMMOD} ${LOADED_MODULES}
002b978df979 Added first systemd support.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   116
                    exit 1
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
        fi
002b978df979 Added first systemd support.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   120
002b978df979 Added first systemd support.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   121
        if ! ${MODPROBE} ${MODPROBE_FLAGS} ${ECMODULE}; then
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2190
diff changeset
   122
            if [ ${MODULE} != "generic" -a ${MODULE} != "ccat" ]; then
2189
002b978df979 Added first systemd support.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   123
                ${MODPROBE} ${MODPROBE_FLAGS} ${MODULE} # try to restore
002b978df979 Added first systemd support.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   124
            fi
002b978df979 Added first systemd support.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   125
            ${RMMOD} ${LOADED_MODULES}
002b978df979 Added first systemd support.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   126
            exit 1
002b978df979 Added first systemd support.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   127
        fi
002b978df979 Added first systemd support.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   128
2190
3fe304fea395 Fixed appending to LOADED_MODULES variable.
Florian Pose <fp@igh-essen.com>
parents: 2189
diff changeset
   129
        LOADED_MODULES="${ECMODULE} ${LOADED_MODULES}"
2189
002b978df979 Added first systemd support.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   130
    done
002b978df979 Added first systemd support.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   131
002b978df979 Added first systemd support.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   132
    exit 0
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
002b978df979 Added first systemd support.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   137
stop)
002b978df979 Added first systemd support.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   138
    # unload EtherCAT device modules
002b978df979 Added first systemd support.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   139
    for MODULE in ${DEVICE_MODULES} master; do
002b978df979 Added first systemd support.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   140
        ECMODULE=ec_${MODULE}
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2190
diff changeset
   141
        if ! ${LSMOD} | grep -q "^${ECMODULE} "; then
2189
002b978df979 Added first systemd support.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   142
            continue # ec_* module not loaded
002b978df979 Added first systemd support.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   143
        fi
002b978df979 Added first systemd support.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   144
        if ! ${RMMOD} ${ECMODULE}; then
002b978df979 Added first systemd support.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   145
            exit 1
002b978df979 Added first systemd support.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   146
        fi;
002b978df979 Added first systemd support.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   147
    done
002b978df979 Added first systemd support.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   148
002b978df979 Added first systemd support.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   149
    sleep 1
002b978df979 Added first systemd support.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   150
002b978df979 Added first systemd support.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   151
    # load standard modules again
002b978df979 Added first systemd support.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   152
    for MODULE in ${DEVICE_MODULES}; do
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2190
diff changeset
   153
        if [ ${MODULE} == "generic" -o ${MODULE} == "ccat" ]; then
2189
002b978df979 Added first systemd support.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   154
            continue
002b978df979 Added first systemd support.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   155
        fi
002b978df979 Added first systemd support.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   156
        ${MODPROBE} ${MODPROBE_FLAGS} ${MODULE}
002b978df979 Added first systemd support.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   157
    done
002b978df979 Added first systemd support.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   158
002b978df979 Added first systemd support.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   159
    exit 0
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
002b978df979 Added first systemd support.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   164
restart)
002b978df979 Added first systemd support.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   165
    $0 stop || exit 1
002b978df979 Added first systemd support.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   166
    sleep 1
002b978df979 Added first systemd support.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   167
    $0 start
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
002b978df979 Added first systemd support.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   172
status)
002b978df979 Added first systemd support.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   173
    echo "Checking for EtherCAT master @VERSION@ "
002b978df979 Added first systemd support.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   174
002b978df979 Added first systemd support.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   175
    # count masters in configuration file
002b978df979 Added first systemd support.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   176
    MASTER_COUNT=0
002b978df979 Added first systemd support.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   177
    while true; do
002b978df979 Added first systemd support.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   178
        DEVICE=$(eval echo "\${MASTER${MASTER_COUNT}_DEVICE}")
002b978df979 Added first systemd support.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   179
        if [ -z "${DEVICE}" ]; then break; fi
002b978df979 Added first systemd support.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   180
        MASTER_COUNT=$(expr ${MASTER_COUNT} + 1)
002b978df979 Added first systemd support.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   181
    done
002b978df979 Added first systemd support.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   182
002b978df979 Added first systemd support.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   183
    RESULT=0
002b978df979 Added first systemd support.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   184
002b978df979 Added first systemd support.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   185
    for i in `seq 0 $(expr ${MASTER_COUNT} - 1)`; do
002b978df979 Added first systemd support.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   186
        echo -n "Master${i} "
002b978df979 Added first systemd support.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   187
002b978df979 Added first systemd support.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   188
        # Check if the master is in idle or operation phase
002b978df979 Added first systemd support.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   189
        ${ETHERCAT} master --master ${i} 2>/dev/null | \
002b978df979 Added first systemd support.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   190
            grep -qE 'Phase:[[:space:]]*Idle|Phase:[[:space:]]*Operation'
002b978df979 Added first systemd support.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   191
        EXITCODE=$?
002b978df979 Added first systemd support.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   192
002b978df979 Added first systemd support.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   193
        if [ ${EXITCODE} -eq 0 ]; then
002b978df979 Added first systemd support.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   194
            echo " running"
002b978df979 Added first systemd support.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   195
        else
002b978df979 Added first systemd support.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   196
            echo " dead"
002b978df979 Added first systemd support.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   197
            RESULT=1
002b978df979 Added first systemd support.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   198
        fi
002b978df979 Added first systemd support.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   199
    done
002b978df979 Added first systemd support.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   200
002b978df979 Added first systemd support.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   201
    exit ${RESULT}
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
*)
002b978df979 Added first systemd support.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   207
    echo "USAGE: $0 {start|stop|restart|status}"
002b978df979 Added first systemd support.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   208
    exit 1
002b978df979 Added first systemd support.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   209
    ;;
002b978df979 Added first systemd support.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   210
esac
002b978df979 Added first systemd support.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   211
002b978df979 Added first systemd support.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   212
#------------------------------------------------------------------------------