Question

User data not executing node script when droplet is created over the api

I am creating a droplet from a snapshot. The droplet contains a folder called youtube-uploader in the root directory. My cloud config looks like this:

#cloud-config
runcmd:
  - touch test.txt
  - node /root/youtuber-uploader/index.js ID-1234
  - touch hello.txt

The droplet is created successfully but the node command is never executed. Both test.txt and hello.txt is created at /. If I ssh into the droplet and run the node command, everything works as expected.

I am making the call to the DO api through a node script and the axios package. The request looks like the following

axios('https://api.digitalocean.com/v2/droplets', {
    method: 'POST', 
    headers: {
       Authorization: 'xxxxxx'
    },
    'Content-Type': 'application/json',
    data: {
      "name": 'testing'
      "region": "nyc3",
      "size": "s-6vcpu-16gb",
      "image": "45281496",
      "ssh_keys": [
        24240690
      ],
      "backups": false,
      "ipv6": false,
      "user_data": `#cloud-config
runcmd:
  - touch test.txt
  - node /root/youtuber-uploader/index.js ${snap.id}
  - touch hello.txt`,
      "private_networking": null,
      "volumes": null,
      "tags": [
        "web"
      ]
    }
  }

Is there any obvious mistake here? It might be that the script is being called but the id is not being passed so the script is not doing the work its supposed to. Is there anyway I can check for this?


Submit an answer


This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

jarland
DigitalOcean Employee
DigitalOcean Employee badge
March 29, 2019
Accepted Answer

Greetings!

Most likely the script is running, but not doing what you expect it to. You may be able to find helpful information in one of these log files:

/var/log/cloud-init.log /var/log/cloud-init-output.log

Jarland

Try DigitalOcean for free

Click below to sign up and get $200 of credit to try our products over 60 days!

Sign up

Get our biweekly newsletter

Sign up for Infrastructure as a Newsletter.

Hollie's Hub for Good

Working on improving health and education, reducing inequality, and spurring economic growth? We'd like to help.

Become a contributor

Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.

Welcome to the developer cloud

DigitalOcean makes it simple to launch in the cloud and scale up as you grow — whether you're running one virtual machine or ten thousand.

Learn more
DigitalOcean Cloud Control Panel