Attempting to run a bash script via user-data on creation isn't working and no logs

March 3, 2015 2k views
Control Panels Logging CentOS

On Google/EC2 I run a bash script to setup a server and after reading https://www.digitalocean.com/community/tutorials/an-introduction-to-droplet-metadata it seems like I can do that on DigitalOcean too.

I'm running into an issue though where the script isn't running however and I can't find where the logs are. On Google/EC2 they're in /var/log/messages on CentOS but I couldn't find anything in there on DO and the install.log files in /root/ don't have anything about the script either.

The user-data I'm trying to run is:

#!/bin/bash

curl {script url} | sh

If I log into the box and run that curl/pipe it works fine. I'm using the Control Panel to create the droplet. Is there something I'm missing? Thanks!

6 Answers

Thanks for brining this to Q&A. Much easier than going over it 140 chars at a time =)

I would recommend using the following in your user-data when creating the droplet in order to accomplish this:

#cloud-config

runcmd:
  - curl {script url} | sh

Since it is a single line, a full bash script shouldn't be necessary.

  • That didn't run it either :( I also looked in /var/log/messages and still didn't see anything there referencing that it ever ran this script. I also looked through other logs in /var/log/ and didn't see anything about it either. Is there another spot where the output goes when this is run?

  • Which OS are you using when deploying the new droplet?

  • I'm using CentOS 6.x 64-bit.

    (Apparently I cannot hit "Reply" on your comment until after I post a new comment... Screenshot: http://cl.ly/image/3E382h3e1F2K)

That didn't run it either :( I also looked in /var/log/messages and still didn't see anything there referencing that it ever ran this script. I also looked through other logs in /var/log/ and didn't see anything about it either. Is there another spot where the output goes when this is run?

  • I realized I posted this in the wrong place. I can't find how to delete this either :(

Did you ever solve this problem? I have the same problem with my newly created droplets (ams3, Debian 7 x64). The user data is available from the meta-data service: "curl http://169.254.169.254/metadata/v1/user-data" but it's not getting executed.

Script (bash) works fine when run manually on the droplet.

Unfortunately, it looks as though "User Data" scripts do not run automatically on CentOS 6.x (versions < 7).

Sorry to bring an old post up, but I'm having the same issue with a new Centos 7 droplet. This user script - https://github.com/digitalocean/do_user_scripts/blob/master/CentOS-7/web-servers/lamp.yml - won't get excecuted on droplet creation.

have to say via api I made the mistake of using the field user-data rather than the correct one which is user_data . Once I realised this it worked!!! might help somebody....

Have another answer? Share your knowledge.