CENTRODIGRAVITA.it
Vmware ESXi 6 AVVIO AUTOMATICO VM da CRONTAB
|
|
Questi sono i passaggi per poter eseguire uno script programmato su di un server Vmware ESXi 6.
Nel caso specifico eseguo uno script dove viene avviata una Virtual Machine.
Prima di eseguire i comandi linux sul server ESXi è necessario attivare la connessione SSH al server agendo dal software ESX CLient for Vmware.
Creazione dello SCRIPT SH per l'avvio di una Virtual Machines
(ESXi 4.x, 5.x and 6.0)
- List the inventory ID of the virtual machine with the command:
vim-cmd vmsvc/getallvms |grep <vm name>
Note: The first column of the output shows the vmid.
- Check the power state of the virtual machine with the command:
vim-cmd vmsvc/power.getstate <vmid>
- Power-on the virtual machine with the command:
vim-cmd vmsvc/power.on <vmid>
ATTIVAZIONE dello SCRIPT SH sul server ESX
- Edit "vi /var/spool/cron/crontabs/root" (to wrtire press i, delete line <esc> :d <enter>, to save <esc> :wq! <enter>)
- Add the line (all on one line)
20 17 * * * /vmfs/volumes/datastore1/start-vm.sh >> /vmfs/volumes/datastore1/start-vm.log 2>&1
chmod 777 /start-vm.sh
- Run the command "cat /var/run/crond.pid"
- Run the command "kill 12345" where "12345" should be replaced with the number output by the previous command
- Restart cron "/usr/lib/vmware/busybox/bin/busybox crond"
- Issue command "auto-backup.sh"
Now cron will start working but all it's setting will be lost after the reboot. To inject commands into crontab do the following:
- Edit /etc/rc.local.d/local.sh
At the end of the file right before the "exit 0" statement write this:
/bin/kill $(cat /var/run/crond.pid) # Gets the cron service pid and simply kills it.
/bin/echo '20 17 * * * /vmfs/volumes/datastore1/start-vm.sh >> /vmfs/volumes/datastore1/start-vm.log 2>&1' >> /var/spool/cron/crontabs/root
/usr/lib/vmware/busybox/bin/busybox crond
save the file (<esc> :wq <enter>)
- Run the command "auto-backup.sh" so that the change to/etc/rc.local survives a reboot.
- OPTIONAL: reboot the server to see if everything works.
*IMPORTANT: ESXi inside runs on UTC time even on Vsphere client it shows othertime. When giving time commands on crontab please use UTC time. You can check ESXi time with command "date".
Tutto il materiale (testo, grafica e immagini) presente in questo sito è di proprietà di CENTRODIGRAVITA.it, pubblicato su concessione degli autori. Ne è vietata la riproduzione, anche parziale, senza il consenso scritto da parte dello staff CENTRODIGRAVITA.it. Eventuale materiale erroneamente pubblicato e soggetto a copyright verrà immediatamente rimosso su segnalazione del titolare dei diritti. CENTRODIGRAVITA.it non si assume nessuna responsabilità per danni che derivino dall'utilizzo delle informazioni, consigli e file scaricati dal sito. Per info o problemi cliccate qui per contattarci. o qui per accedere all'informativa sui cookie