VMware Communities
EEdev
Contributor
Contributor

Running vm as a service, always on in background

Hello all, I've got a few extra cores on my i7 here, so I'm hosting a Linux vm that I want to basically always be running and online.  Host is Windows 10 x64 running the latest VMware 12.5.  Guest is various flavors of Linux.  Basically here is what I'm trying to do:

1) VM needs to start with windows start, not user login

2) Verify that the vm is running (Remote management?)

3) Orderly suspend or shutdown when windows shuts down or restarts

After some scouring on the internet, I was able to get past everybody talking about login scripts, and that's when I discovered the 'vmrun' command and the event for Task Scheduler to run that as soon as windows boots, not waiting for a user to login.  This has the interesting affect of me losing all control over the VM with VMware; Basically that vm is running as a system process, and when I logged in and opened VMware its running on a user process.  Anyway that's my best guess as to why VMware can't see that it's running or interact with it, but it's definitely running because SSH and web server are working.  But that's the only way I'm going to use this machine anyway so I'd consider 1) solved.

If I'm having trouble with the SSH or web server, and want to check if the vm is actually running... ?  I have no clue here, except maybe looking for lock files and logs... btw anyone know which logs are useful in this case?  I'm just trying to basically see the status of the VM, maybe send a command to Start/Restart it.

And finally, I'm pretty sure VMware isn't waiting for my guest to shutdown when i shutdown windows.  Maybe I could use the 'Before Shutdown" event or something like it in Task Scheduler, and run a script that initiates guest shutdown and waits for that to complete?  Maybe with a time limit?

I'm way out of my league with these scripts and task scheduler, can anyone offer any advice on how to accomplish 2) and 3)?

0 Kudos
6 Replies
RDPetruska
Leadership
Leadership

Just make this VM a shared VM - it will then do exactly what you want!

0 Kudos
EEdev
Contributor
Contributor

Thanks for your advice, but "shared VMs" are not going to work in my situation. You lose all the best features of VMware (See below). It's bad enough that I can't do an online snapshot if there are independent disks in the guest. Also, all examples I've seen show a shared vm being able to start up with any user logging in; what I need is the VM running as long as the computer is on, regardless of any users being logged into the host

I think what I need is some scripting-fu in this situation; I can get it to start okay using the vmrun command, but on shutdown of the host is There a way to send a shutdown signal before windows shuts down? Or even better suspend the vm? There should also be a way for my script to time out if the guest shutdown hangs for too long, and just let the host shutdown

Heres a bit more of why I'm not doing shared VMs:

Quote from http://kb.vmware.com/kb/2005585

When you share a virtual machine, you lose these features:

  Unity

  Shared Folders

  AutoProtect

  drag and drop

  copy and paste

  Thin Print

  Ability to connect/redirect USB devices from the host to the virtual machine not available

  3D Acceleration

0 Kudos
wila
Immortal
Immortal

Hi,

The way to do that is probably by running a batch script that suspends your VM on logoff.

See here for details:

http://stackoverflow.com/questions/101647/how-to-schedule-a-task-to-run-when-shutting-down-windows

--

Wil

| Author of Vimalin. The virtual machine Backup app for VMware Fusion, VMware Workstation and Player |
| More info at vimalin.com | Twitter @wilva
0 Kudos
EEdev
Contributor
Contributor

‌For getting the VM to start when windows starts (even when a user hasn't logged in), I've used the vmrun.exe command like so:

"C:\Program Files (x86)\VMware\VMware Workstation\vmrun.exe" -T ws start C:\VMs\<vmName>\<vmName>.vmx nogui

What command can I use to shut down a vm?

wila
Immortal
Immortal

Hi,

If you run vmrun without any commands it will show you the options.

Or alternative look on this page:

http://www.vi-toolkit.com/wiki/index.php/Vmrun

So in result, you should replace "start" with either "stop" or "suspend" in your line of code depending on what you want to do and make sure to remove the nogui option.

--

Wil

| Author of Vimalin. The virtual machine Backup app for VMware Fusion, VMware Workstation and Player |
| More info at vimalin.com | Twitter @wilva
0 Kudos
admin
Immortal
Immortal

It's bad enough that I can't do an online snapshot if there are independent disks in the guest.

You think it's bad, but it is the only sensible choice.  An independent disk is a disk that is not affected by snapshots.  If we allowed a snapshot to be taken of a running virtual machine with independent disks, what would happen if you made changes to the independent disk and then restored that snapshot?  From the perspective of the guest OS, the contents of one of its local disks would have suddenly changed from under it.  Contents of the disk that the guest OS cached in memory would no longer valid, and the guest OS could potentially corrupt the contents of the disk when writing to it.  This is really not what you want.

Also, all examples I've seen show a shared vm being able to start up with any user logging in; what I need is the VM running as long as the computer is on, regardless of any users being logged into the host

That is not correct.  Shared VMs configured to autostart do not require users to log in because shared VMs are run via a system service.  You also can edit the %ProgramData%\VMware\hostd\vmAutoStart.xml file and configure autostart VMs to automatically suspend (or shut down) when the host shuts down.

0 Kudos