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