0
votes

There is a VM scale set running with Centos 7 custom image. Required to run below script as cloud-init script while scaling the VM Scale set. But VM scaled, the script not executed. From the server also not able to locate the execution history. This is the command I used,

#cloud-config
runcmd:
– cd /srv/compose/composeforsvaret/
– docker-compose stop
- docker-compose up -d
final_message: "Your Docker server is now ready."
1
Where do you have this script? Is it in a pipeline, or a cronjob on your VM, or...? - Casper Dijkstra
@CasperDijkstra I added that script to the cloud init script box on th Azure portal. Operating System > Script box - vish

1 Answers

1
votes

The commands are not executed, because the syntax is not recognized.
I read in the cloud init documentation about runcmd

the list has to be proper yaml, so you have to quote any characters yaml would eat (':' can be problematic)

This should do the trick:

runcmd:
– [ cd, /srv/compose/composeforsvaret, / ] // or - [ sh, -c , "cd /srv/compose/composeforsvaret" ]
– [ sh, -c, "docker-compose stop" ]
- [ sh, -c, "docker-compose up -d" ]
final_message: "Your Docker server is now ready."

Also keep in mind that runcmd only runs during the first boot, so depending on your purpose you should consider bootcmd!