How to run .exe file on startup on gcp windows instance - google-cloud-platform

I am having a VM, windows instance (GCE) on google cloud platform. I want to run a program(.exe) every time at the start of the instance.
I am able to run the file by putting it in the startup folder. but I want to run it using startup script as suggested by google here: running startup scripts on a google compute engine

To run .exe on GCP when Windows VM instance start/restart.
Click edit on VM instance
Expand Management, security, disks, networking, sole tenancy section
In the Metadata section, provide windows-startup-script-cmd as the metadata key.
In the Value box, provide /path/to/exe-file

Related

How to use existing Compute Engine for Google Cloud Build?

How would you use an existing Compute Engine VM instance for a Google Cloud Build pipeline?
I know there's been a similar question in the past, however, the suggested answer is not really what I want - creating and then destroying a Compute Engine with every build.
In settings, Cloud Build allows you to enable "service account permissions" for Compute Engine (Compute Instance Admin (v1)), but I've found no information how to use that permission and service for running the build process with one of your predefined VM instances.
Or maybe I misunderstand the answer in the linked thread above and
COMMAND=sudo supervisorctl restart
actually restarts the existing VM supervisorctl? Any help would be appreciated.
You can't run a Cloud Build build on a GCE instance. The most customizable option you would have is to run the build on a private pool. But even in those cases it's always managed, you never have access to the underlying VM.
Another option would be to start a powerful GCE instance with Cloud Build via the GCE API, run your operations there and then stop the GCE instance.

Why "activate cloud shell" opens a shell that is not what is under my newly created "Instance-1" virtual machine?

I just set up everything on google cloud shell (terminal that activates when you press "activate cloud shell" on top right). However, i just now realised it is not the same thing as the Instance-1 i created as connecting to it by pressing "SSH" leaves me with none of the software i installed in google cloud shell.
Why is it so? Is it possible to add google cloud shell to the Instance-1 virtual machine i just created? (it would greatly easy software setup)
As #John hanley expressed in the comments, cloud shell are transient and it isn't suggested to utilize it to store or introduce lasting data and applications.
In your case, you'd like to have an instance where you've got a default setup with the fundamental software preinstalled. There are 3 alternatives you'll utilize for this situation.
Using Snapshot, Image or Instance template.
A snapshot reflects the contents of a persistent disk in a concrete
instant in time. An image is the same thing, but includes an
operating system and boot loader and can be used to boot an instance.
But snapshot is cheaper in terms of cost.
Images are primarily meant for boot disk creation. They optimized for
multiple downloads of the same data over and over. If the same image
is downloaded many times, subsequent to the first download the following
downloads are going to be very fast (even for large images).
Instance templates define the machine type, boot disk image or
container image, labels, and other instance properties. An instance
template is a global resource that is not bound to a zone or a region.
All these options can create an instance using the cloud shell and you can get the command line version by clicking the Equivalent command line button when creating the resource.
After the setup, you will just initiate the command on cloud shell based on the option you chose then connect to your instance via SSH from cloud shell as also suggested by #dany L.

Can we run the jar in the GCP VM from the cloud function

Can we run the jar in the GCP VM from the cloud function-
We thaught of deploying the jar in cloud function directly and running from there but we encountered the execution time out issues, so Is there any way that we can just to trigger the jar file in GCP VM from cloud function
Thanks in advance
If the only purpose of the VM is to run this process I would:
Cloud Scheduler calls a Cloud Function.
The Cloud Function starts a VM with a startup script that runs the jar process, and shuts down.
If you need to pass arguments to the script, you can do it using instance metadata when you create the instance (or while it is already running).
You can also have a look at this article (which is not supported by google). There you will find how you can start and stop instances using cloud functions.

accessing a new vm's terminal without using the console in UI

I'm new to vmware and i'm trying to do some automation when creating a vm from an OVA file. Essentially, I have an OVA that I need to get into the console and run a script so I can get to it via the internet...the script is this (runs a netplan config and some iptable commands), I just don't know how to execute or run the commands manually without having to get into the UI via the console.
I'm just trying to figure out how I can run this without having to access the console via the vmware esxi UI.
I'm using packet.com's environment to provision a server with vmware esxi on it via terraform, and then use ansible to deploy a few ova's on it.
The problem then is though that I can't access the newly deployed vm's unless I go into the console of the vm via the UI. I'm trying to see how I can do that either via an api or some other fashion so I can do some further automation after the VM's come up.
Assuming the VM has VMware Tools running, that would give you access to run a process/command/script in the Guest OS using the GuestProcessManager object in the vSphere Web Services API. More specifically, using the StartProgramInGuest method: http://pubs.vmware.com/vsphere-6-5/topic/com.vmware.wssdk.apiref.doc/vim.vm.guest.ProcessManager.html#startProgram

Google startup script on custom image not working

I have launched a VM in GCP using a custom image from GCP console.
I have added a start-up script while launching the VM.
When I login into the VM, I have observed that my start-up script is not executed.
I have gone through the log file and observed the " No start-up script found" message in /var/log/syslog.
Note : Start-up scripts execute successfully for VM's launched using GCP default images.
Can any one help me on how to execute start-up scripts for VM's launched using custom images.