Init-Skript xendomains.local

Aus Neobikers Wiki
Version vom 13. Januar 2021, 00:28 Uhr von Neobiker (Diskussion | Beiträge) (Die Seite wurde neu angelegt: „Init-Skript '''/etc/init.d/xendomains.local''' (Debian) <pre> #!/bin/bash ### BEGIN INIT INFO # Provides: xendomains.local # Required-Start: xendom…“)
(Unterschied) ← Nächstältere Version | Aktuelle Version (Unterschied) | Nächstjüngere Version → (Unterschied)
Zur Navigation springen Zur Suche springen

Init-Skript /etc/init.d/xendomains.local (Debian)

#!/bin/bash
### BEGIN INIT INFO
# Provides:          xendomains.local
# Required-Start:    xendomains
# Required-Stop:     xendomains
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: Start/stop local xen domains
# Description:       Start / stop domains automatically when domain 0
#                    boots / shuts down.
### END INIT INFO

. /lib/init/vars.sh
. /lib/lsb/init-functions

xen list &> /dev/null
if test $? -ne 0
then
        exit 0;
fi

if ! [ -e /proc/xen/privcmd ]; then
        exit 0
fi

[ -r /etc/default/xendomains ] && . /etc/default/xendomains

shopt -s nullglob

check_config_name()
{
  /usr/lib/xen-common/bin/xen-init-name "$1" 2>/dev/null
}

check_running()
{
  xen domid "$1" > /dev/null 2>&1
  return $?
}

timeout_domain()
{
  name="$1"
  TIMEOUT="$2"
  for no in $(seq 0 $TIMEOUT); do
    if ! check_running "$name"; then return 0; fi
    sleep 1
    log_action_cont_msg
  done
  return 1
}

do_stop_shutdown()
{
  # which is our actual file-server?
  srv=$(ping -qc 1 srv|head -1|cut -d\  -f2|cut -d. -f1)
  [ -z "$srv" ] && srv=none

  # skip shutdown of some vm's: Domain-N, firewall and file server
  while read id name rest; do
    case $name in
        Domain-N)
                ;;
        opnsense)
                ;;
        $srv)
                ;;
        *)
            log_action_begin_msg "Shutting down local Xen domain $name ($id)"
            xen shutdown $id 2>&1 1>/dev/null
            log_action_end_msg $?
            sleep 5
            ;;
    esac
  done < <(/usr/lib/xen-common/bin/xen-init-list 2>/dev/null)

  sleep 5

  # shutdown of some vm's: file-server
  while read id name rest; do
    case $name in
        $srv)
            log_action_begin_msg "Shutting down local Xen domain $name ($id)"
            xen shutdown $id 2>&1 1>/dev/null
            log_action_end_msg $?
            sleep 5
            ;;
        *)
            ;;
    esac
  done < <(/usr/lib/xen-common/bin/xen-init-list 2>/dev/null)

  sleep 5

  # shutdown remaining vm's with specific flags: opnsense
  while read id name rest; do
    case $name in
        opnsense*)   FLAG=""
            log_action_begin_msg "Shutting down local Xen domain $name ($id)"
            xen shutdown $FLAG $id 2>&1 1>/dev/null
            log_action_end_msg $?
            sleep 5
                ;;
        *)         FLAG=
            log_action_begin_msg "Shutting down local Xen domain $name ($id)"
            xen shutdown $FLAG $id 2>&1 1>/dev/null
            log_action_end_msg $?
            sleep 5
                ;;
    esac
  done < <(/usr/lib/xen-common/bin/xen-init-list 2>/dev/null)
}

do_stop()
{
  do_stop_shutdown
}

case "$1" in
  start)
    ;;

  stop)
    do_stop
    ;;

  restart)
    ;;

  reload|force-reload)
    ;;

  *)
    echo "Usage: $0 {start|stop|restart|reload|force-reload}"
    exit 3
    ;;
esac
exit 0