Hi everyone,
I am trying to use packer for creating managed images on azure. I want a script to be executed after the VM is launched. Just as in case of AWS instances, a linux instance has /var/lib/cloud/scripts/per-instance
to run scripts once the instance is launched and per-boot
for executing scripts whenever the instance is booted. Similarly, what can be done in case of Ubuntu VM on azure?
If the command should be executed at every reboot, you could add an entry to /etc/crontab
with @reboot
as time to execute.
@reboot /usr/bin/your-command
Or you could use systemd
with an onshot
like:
# /etc/systemd/system/rc-local.service
[Unit]
After = network-online.target
Wants = network-online.target
[Service]
Type = oneshot
RemainAfterExit = yes
ExecStart = <your-command>
ExecStart = <your-second-command>
# ...
[Install]
WantedBy = multi-user.target
Would specifying the path of a script instead of a command work?
For ex: @reboot /tmp/setup.sh
Similarly can we do the same with systemd
? Or is it even possible to write all the commands for ExecStart
?
Can we do something like in AWS linux AMI such as adding the file to per-instance
and its executed after the instance is launched. The logs are seen in cloud-init-output.log
Should both be possible.
Hi @Wolfsrudel
Could you possibly provide an insight on this approach for a VM (ubuntu)?