문제

I am new to cloud-init, my final goal is to run an R script each time an EC2 Spot Instance becomes active, but in order to test it I created an on-demand Ubuntu 12.04 instance and created a simple script but nothing happens after reboot. Here are the steps I took:

  • Launched the new Ubunut 12.04 instance
  • Navigate to /var/lib/cloud/scripts/per-boot
  • sudo vi script.sh
  • Added the following code:

#!/bin/sh
echo "test"

  • sudo reboot

At this point I thought I should see a "test" print when the instance reboots, but there is nothing there. I went to take a look at /var/log/cloud-init.log but there is no error or anything out of the ordinary.

I am clearly missing something so any tip in the right direction will be much appreciated!

Thanks!

도움이 되었습니까?

해결책

It won't run unless the scripts user is set to always run. See this answer for more details (and for instructions on how to get scripts to run on reboot, generally).

다른 팁

If we want to debug the user-data in cloud-init, we can try the following steps:

  1. rm -rf /var/lib/cloud/*
  2. cloud-init init
  3. cloud-init modules -m final

With above commands, the cloud-init is re-run. And we can check the cloud-init.log under /var/log/cloud-init.log to check if it is successfully exec.

Looked at the source code, the script must be executable. This'll make it work

sudo chmod 744 script.sh

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top