\nI read in the cloud init documentation about runcmd
\n\nthe list has to be proper yaml, so you have to quote any characters yaml would eat (':' can be problematic)
\n
This should do the trick:
\nruncmd:\n– [ cd, /srv/compose/composeforsvaret, / ] // or - [ sh, -c , "cd /srv/compose/composeforsvaret" ]\n– [ sh, -c, "docker-compose stop" ]\n- [ sh, -c, "docker-compose up -d" ]\nfinal_message: "Your Docker server is now ready."\n
\nAlso keep in mind that runcmd
only runs during the first boot, so depending on your purpose you should consider bootcmd
!
Reputation: 791
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."
Upvotes: 0
Views: 394
Reputation: 1895
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
!
Upvotes: 2