Como executar alguns comandos antes dos scripts do usuário no cloud-init

1

Estou tentando executar alguns scripts e configurações usando uma configuração multiparte.

Content-Type: multipart/mixed; boundary="MIMEBOUNDARY"
MIME-Version: 1.0
--MIMEBOUNDARY
Content-Disposition: attachment; filename="cloud-config.cfg"
Content-Transfer-Encoding: 7bit
Content-Type: text/cloud-config
Mime-Version: 1.0

package_upgrade: true
packages:
  - jq
  - docker

runcmd:
  - service docker start

--MIMEBOUNDARY
Content-Disposition: attachment; filename="00-rancher_server_install"
Content-Transfer-Encoding: 7bit
Content-Type: text/x-shellscript
Mime-Version: 1.0

#!/bin/bash

# Pull required images
docker pull rancher/server:v1.0.2

--MIMEBOUNDARY--

O problema é a ordem em que os scripts são executados ... - Primeiro yum instalar scripts - Então os scripts do bash - Então os scripts runcmd

então o serviço docker não foi iniciado quando os comandos de scripts do usuário são executados

Estou usando um Amazon Linux AMI no EC2, que é o CentOS ...

Este é o log de inicialização da nuvem

Cloud-init v. 0.7.6 running 'modules:config' at Tue, 21 Jun 2016 01:30:44 +0000. Up 25.32 seconds.
Loaded plugins: priorities, update-motd, upgrade-helper
Metadata Cache Created
Loaded plugins: priorities, update-motd, upgrade-helper
No packages needed for security; 26 packages available
Resolving Dependencies
Loaded plugins: priorities, update-motd, upgrade-helper
Resolving Dependencies
--> Running transaction check
---> Package docker.x86_64 0:1.11.1-1.2.amzn1 will be installed
--> Processing Dependency: xfsprogs for package: docker-1.11.1-1.2.amzn1.x86_64
---> Package jq.x86_64 0:1.5-1.2.amzn1 will be installed
--> Processing Dependency: jq-libs(x86-64) = 1.5-1.2.amzn1 for package: jq-1.5-1.2.amzn1.x86_64
--> Processing Dependency: oniguruma for package: jq-1.5-1.2.amzn1.x86_64
--> Processing Dependency: libjq.so.1()(64bit) for package: jq-1.5-1.2.amzn1.x86_64
--> Processing Dependency: libonig.so.2()(64bit) for package: jq-1.5-1.2.amzn1.x86_64
--> Running transaction check
---> Package jq-libs.x86_64 0:1.5-1.2.amzn1 will be installed
---> Package oniguruma.x86_64 0:5.9.1-3.1.2.amzn1 will be installed
---> Package xfsprogs.x86_64 0:3.2.2-2.20.amzn1 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

================================================================================
 Package         Arch         Version                  Repository          Size
================================================================================
Installing:
 docker          x86_64       1.11.1-1.2.amzn1         amzn-updates        17 M
 jq              x86_64       1.5-1.2.amzn1            amzn-updates        44 k
Installing for dependencies:
 jq-libs         x86_64       1.5-1.2.amzn1            amzn-updates       121 k
 oniguruma       x86_64       5.9.1-3.1.2.amzn1        amzn-main          149 k
 xfsprogs        x86_64       3.2.2-2.20.amzn1         amzn-main          1.7 M

Transaction Summary
================================================================================
Install  2 Packages (+3 Dependent packages)

Total download size: 19 M
Installed size: 60 M
Downloading packages:
--------------------------------------------------------------------------------
Total                                               11 MB/s |  19 MB  00:01
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : oniguruma-5.9.1-3.1.2.amzn1.x86_64                           1/5
  Installing : jq-libs-1.5-1.2.amzn1.x86_64                                 2/5
  Installing : xfsprogs-3.2.2-2.20.amzn1.x86_64                             3/5
  Installing : docker-1.11.1-1.2.amzn1.x86_64                               4/5
  Installing : jq-1.5-1.2.amzn1.x86_64                                      5/5
  Verifying  : docker-1.11.1-1.2.amzn1.x86_64                               1/5
  Verifying  : oniguruma-5.9.1-3.1.2.amzn1.x86_64                           2/5
  Verifying  : jq-1.5-1.2.amzn1.x86_64                                      3/5
  Verifying  : jq-libs-1.5-1.2.amzn1.x86_64                                 4/5
  Verifying  : xfsprogs-3.2.2-2.20.amzn1.x86_64                             5/5

Installed:
  docker.x86_64 0:1.11.1-1.2.amzn1           jq.x86_64 0:1.5-1.2.amzn1

Dependency Installed:
  jq-libs.x86_64 0:1.5-1.2.amzn1        oniguruma.x86_64 0:5.9.1-3.1.2.amzn1
  xfsprogs.x86_64 0:3.2.2-2.20.amzn1

Complete!
Cloud-init v. 0.7.6 running 'modules:final' at Tue, 21 Jun 2016 01:31:55 +0000. Up 96.28 seconds.
Warning: failed to get default registry endpoint from daemon (Cannot connect to the Docker daemon. Is the docker daemon running on this host?). Using system default: https://index.docker.io/v1/
Cannot connect to the Docker daemon. Is the docker daemon running on this host?
Jun 21 01:31:55 cloud-init[2485]: util.py[WARNING]: Failed running /var/lib/cloud/instance/scripts/00-rancher_server_install [1]
Starting cgconfig service: [  OK  ]
Starting docker:    .[  OK  ]
Jun 21 01:31:56 cloud-init[2485]: cc_scripts_user.py[WARNING]: Failed to run module scripts-user (scripts in /var/lib/cloud/instance/scripts)
Jun 21 01:31:56 cloud-init[2485]: util.py[WARNING]: Running module scripts-user (<module 'cloudinit.config.cc_scripts_user' from '/usr/lib/python2.7/dist-packages/cloudinit/config/cc_scripts_user.pyc'>) failed
Cloud-init v. 0.7.6 finished at Tue, 21 Jun 2016 01:31:56 +0000. Datasource DataSourceEc2.  Up 97.56 seconds
    
por blackjid 21.06.2016 / 17:31

1 resposta

3

@smoser do irc # cloud-init me ajudou

procure em /var/lib/cloud/instance/scripts/ você verá um arquivo chamado runcmd e os outros arquivos que estão em seu multiparte são nomeados pelo nome do arquivo.

Os scripts nesse diretório são executados na ordem classificada de código de idioma C (como se fosse por runparts)

Então, se você alterar o nome do script do qual adicionou %código% para %código% então você vai ser bom.

    
por 21.06.2016 / 19:06