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