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