Changeset 2941 in /cluster/svnroot


Ignore:
Timestamp:
Jan 23, 2011 7:17:56 PM (10 years ago)
Author:
skylar
Message:

better error handling (#584)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • bccd-ng/branches/skylar-devel/trees/bin/bccd-reset-network

    r2751 r2941  
    11#!/bin/bash
     2
     3set -x
    24
    35# $Id$
     
    2325# along with this program.  If not, see <http://www.gnu.org/licenses/>.
    2426
    25 /bin/rm -f /etc/network/configured && \
    26         /usr/sbin/invoke-rc.d dhcp3-server stop && \
    27         /usr/sbin/invoke-rc.d networking stop && \
    28         /bin/bccd-nic-setup && \
    29         /usr/sbin/invoke-rc.d networking start && \
    30         /bin/bccd-nat && \
    31         /usr/sbin/invoke-rc.d networking start && \
    32         /usr/sbin/invoke-rc.d dhcp3-server start
     27# Print an optional message and die
     28function fatal() {
     29    RC=2
     30    while getopts "m:r:" OPTION; do
     31        case ${OPTION} in
     32            m )
     33                MSG=${OPTARG}
     34                ;;
     35            r )
     36                RC=${OPTARG}
     37                ;;
     38            esac
     39    done
     40    if [ -n "${MSG}" ]; then
     41        echo $(basename $0): ${MSG} >&2
     42    fi
     43    echo $(basename $0): failed! >&2
     44    exit ${RC}
     45}
     46
     47/bin/rm -f /etc/network/configured
     48RC=$?
     49if [ ${RC} -ne 0 ]; then
     50        fatal -m "Unconfiguring network failed" -r ${RC}
     51fi
     52
     53/usr/sbin/invoke-rc.d dhcp3-server stop
     54RC=$?
     55if [ ${RC} -ne 0 ]; then
     56        fatal -m "DHCP server stop failed" -r ${RC}
     57fi
     58
     59/usr/sbin/invoke-rc.d networking stop
     60RC=$?
     61if [ ${RC} -ne 0 ]; then
     62        fatal -m "Networking stop failed" -r ${RC}
     63fi
     64
     65/bin/bccd-nic-setup
     66RC=$?
     67if [ ${RC} -ne 0 ]; then
     68        fatal -m "bccd-nic-setup failed" -r ${RC}
     69fi
     70
     71/usr/sbin/invoke-rc.d networking start
     72RC=$?
     73if [ ${RC} -ne 0 ]; then
     74        fatal -m "Networking start failed" -r ${RC}
     75fi
     76
     77/bin/bccd-nat
     78RC=$?
     79if [ ${RC} -ne 0 ]; then
     80        fatal -m "bccd-nat failed" -r ${RC}
     81fi
     82
     83/usr/sbin/invoke-rc.d networking start
     84RC=$?
     85if [ ${RC} -ne 0 ]; then
     86        fatal -m "Networking start failed" -r ${RC}
     87fi
     88
     89/usr/sbin/invoke-rc.d dhcp3-server start
     90RC=$?
     91if [ ${RC} -ne 0 ]; then
     92        fatal -m "DHCP server start failed" -r ${RC}
     93fi
Note: See TracChangeset for help on using the changeset viewer.