Buscar

VMWare: ESXi reiniciar servicios con services.sh

En un host VMWare ESXi encontraremos el siguiente shell script: services.sh en el directorio /bin.

Los ficheros dentro del directorio /bin están situados en el path del sistema, así que podrán ser llamados desde cualquier ruta.

Este shell script (services.sh) permite reiniciar todos los servicios del host ESXi sin reiniciar el host.

El script acepta como parámetros: start, stop y restart.

Es importante tener en cuenta que si ejecutamos services.sh stop, perderemos toda conectividad con el host y no quedará recuperada de forma automática, ya que todos los servicios quedarán detenidos.

Podemos ejecutar este script desde la shell del sistema.

Funcionamiento interno del script:

El script lista los servicios configurados como activos con el comando: chkconfig -io.

Con el comando service start y service stop, se reinician los servicios.

Con el comando localcli network firewall ruleset, se actualizan las reglas en el firewall.

Contenido del script:

~ # cat /bin/services.sh
#!/bin/sh

export PATH=/sbin:/bin

log() {
   echo "$*"
   logger init "$*"
   esxcfg-init --set-boot-status-text "$*"
   esxcfg-init --set-boot-progress step
}

# Try esxcli to set firewall first. If return value is not 0,
# that demonstrates hostd is not up, yet. Then try localcli,
# which always succeeds. Setting firewall in this way,
# guarantees new settings sync to hostd cache.
update_ruleset_status() {
   /sbin/esxcli network firewall ruleset set -r $1 -e $2
   if [ $? -ne 0 ]; then
      /sbin/localcli network firewall ruleset set -r $1 -e $2
   fi
}

update_firewall() {
   if [ $1 = "ntpd" ]; then
      update_ruleset_status "ntpClient" $2
   elif [ $1 = "SSH" ]; then
      update_ruleset_status "sshServer" $2
   elif [ $1 = "vpxa" ]; then
      update_ruleset_status "vpxHeartbeats" $2
   elif [ $1 = "sfcbd-watchdog" ]; then
      update_ruleset_status "CIMHttpServer" $2
      update_ruleset_status "CIMHttpsServer" $2
   fi
}

start() {
   esxcfg-init --set-boot-progress-text "Starting up services"
   ulimit -s 512
   startdir=`pwd`
   svclst=`/sbin/chkconfig -io`
   for service in $svclst; do
      if [ -x "$service" ]; then
         dir=`dirname $service`
         svc=`basename $service`
         log "Running $svc $action"
         cd $dir
         update_firewall $svc true
         $service start
      fi
   done
   cd $startdir
}

stop() {
   startdir=`pwd`
   svclst=`/sbin/chkconfig -o | sed -n -e '1!G' -e 'h' -e '$p'`
   for service in $svclst; do
      if [ -x "$service" ]; then
         dir=`dirname $service`
         svc=`basename $service`
         log "Running $svc stop"
         cd $dir
         $service stop
         update_firewall $svc false
      fi
   done
   cd $startdir
}

action=$1
case "$1" in
   start)
      start
      ;;
   stop)
      stop
      ;;
   restart)
      stop
      start
      ;;
   *)
      echo "Usage: `basename "$0"` {start|stop|restart}"
      exit 1
esac


Ejecución del script (reinicio de servicios):

~ # /bin/services.sh restart
Running xorg stop
Running sfcbd stop
This operation is not supported.
Please use /etc/init.d/sfcbd-watchdog stop
Running wsman stop
Stopping openwsmand
Running snmpd stop
root: snmpd is not running.
Running sfcbd-watchdog stop
Running vpxa stop
watchdog-vpxa: Terminating watchdog process with PID 33717
vpxa stopped.
Running vobd stop
watchdog-vobd: Terminating watchdog process with PID 33277
vobd stopped
Running lacp stop
watchdog-net-lacp: Terminating watchdog process with PID 33468
Running memscrubd stop
memscrubd is not running
Running smartd stop
watchdog-smartd: Terminating watchdog process with PID 34628
smartd stopped
Running dcbd stop
watchdog-dcbd: Terminating watchdog process with PID 34588
Running cdp stop
watchdog-cdp: Terminating watchdog process with PID 34542
Running nscd stop
watchdog-nscd: Terminating watchdog process with PID 34488
Running slpd stop
Stopping slpd
Running storageRM stop
watchdog-storageRM: Terminating watchdog process with PID 34366
storageRM stopped
Running hostd stop
watchdog-hostd: Terminating watchdog process with PID 34325
hostd stopped.
Running vmfstraced stop
watchdog-vmfstracegd: PID file /var/run/vmware/watchdog-vmfstracegd.PID does not exist
watchdog-vmfstracegd: Unable to terminate watchdog: No running watchdog process for vmfstracegd
vmfstracegd is not running
Failed to clear vmfstracegd memory reservation
Running lbtd stop
watchdog-net-lbt: Terminating watchdog process with PID 34264
net-lbt stopped
Running sdrsInjector stop
watchdog-sdrsInjector: Terminating watchdog process with PID 34191
sdrsInjector stopped
Running rhttpproxy stop
watchdog-rhttpproxy: Terminating watchdog process with PID 34150
rhttpproxy stopped.
Running sensord stop
watchdog-sensord: Terminating watchdog process with PID 34126
sensord stopped
Running usbarbitrator stop
watchdog-usbarbitrator: Terminating watchdog process with PID 34089
usbarbitrator stopped
Running DCUI stop
Disabling DCUI logins
VobUserLib_Init failed with -1
Running SSH stop
SSH login disabled
VobUserLib_Init failed with -1
Connect to localhost failed: Connection failure
Errors:
Invalid operation requested: This ruleset is required and connot be disabled
Running ESXShell stop
ESXi shell login disabled
VobUserLib_Init failed with -1
Running ntpd stop
Stopping ntpd
watchdog-ntpd: Terminating watchdog process with PID 33993
Connect to localhost failed: Connection failure
Running vsantraced stop
watchdog-vsantraced: Terminating watchdog process with PID 33924
vsantraced stopped
watchdog-vsantracedUrgen: Terminating watchdog process with PID 33953
vsantracedUrgen stopped
Running vsantraced restart
Storing traces to /scratch/vsantraces
vsantraced started
vsantracedUrgen started
Running ntpd restart
Connect to localhost failed: Connection failure
Starting ntpd
Running ESXShell restart
ESXi shell login enabled
VobUserLib_Init failed with -1
Running SSH restart
Connect to localhost failed: Connection failure
SSH login enabled
VobUserLib_Init failed with -1
Running DCUI restart
Enabling DCUI login: runlevel =
VobUserLib_Init failed with -1
Running usbarbitrator restart
usbarbitrator started
Running sensord restart
sensord started
Running rhttpproxy restart
rhttpproxy started.
Running sdrsInjector restart
sdrsInjector started
Running lbtd restart
net-lbt started
Running vmfstraced restart
VMFS Global Tracing is not enabled.
Running hostd restart
Ramdisk 'hostd' with estimated size of 413MB already exists
hostd started.
Running storageRM restart
storageRM started
Running slpd restart
Starting slpd
Running nscd restart
nscd started
Running cdp restart
cdp started
Running dcbd restart
dcbd started
Running smartd restart
smartd started
Running memscrubd restart
The checkPages boot option is FALSE, hence memscrubd could not be started.
Running lacp restart
LACP daemon started
Running vobd restart
vobd started
Running vpxa restart
Connect to localhost failed: Connection failure
Running sfcbd-watchdog restart
Running snmpd restart
root: snmpd has not been enabled.
Running wsman restart
Starting openwsmand
Running sfcbd restart
This operation is not supported.
Please use /etc/init.d/sfcbd-watchdog start
Running xorg restart




No hay comentarios:

Publicar un comentario