Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

bamboo instance setup script

Chason Choate August 17, 2015

I've got an AMI that can only be logged in with a user named "centos". This user has "sudo" access as well. How can I configure Bamboo to use the "centos" user to run the "Instance setup script"? It seems the "Instance setup script" will only work if the AMI is configured to login as the "root" user. Can someone shed some light on this for me, i've looked at the documentation and only see comments here or there about the matter.

 

Clarification:

My AMI has the root login disabled. Therefore it seems as if the "instance setup scripts" don't run at all. Which would make sense if it's trying to login as root. (Although I don't see any failed logs about this) Per the documentation "It's a script that gets run as root user before the agent is started." Therefore is it possible to configure Bamboo to run the "instance setup script" as another user other than root?

1 answer

1 accepted

0 votes
Answer accepted
Marcin Oles
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
August 18, 2015

Hello,

yes, the startup scripts on Linux images are executed as root user. I'm not sure if root user can be disabled completely to such extent that it'll cause the script to stop working, but it usually isn't.

If you really need to use other user than root, then you may try switching the user using e.g. sudo. Didn't test it, but something like this might work:

#!/bin/sh

# code as root here
# ...
# ...
whoami

exec sudo -u centos /bin/sh - << EOF

  # code as centos here
  # ...
  # ...
  whoami

EOF

Although be careful with some variables, they might not be set correctly (e.g. $HOME, $USER). Maybe adding -H to sudo command will help.

Or, you could try doing it command by command. Just be careful with single and double quotes. E.g.

#!/bin/sh

sudo -u centos -H sh -c 'echo $HOME'    # out: /home/centos
sudo -u centos -H sh -c "echo $HOME"    # out: /root

 

=== EDIT ===

The user 'root' is not logging in via SSH. It's just the user that launches the startup scripts. I think it's impossible to disable this user. You can disable logging in as root, but it wouldn't disable startup scripts.

So in your case I'd rather look for another source of error, not in the user calling the scripts. There may be some errors in the scripts in the first place. Or, even more probable, if it's not an AMI build based on an existing Bamboo stock image, the startup script might not be registered to run at startup.

Make sure that your /etc/rc.local executes startup scripts from agent installation directory. This is how it looks like for Bamboo stock images:

File: /etc/rc.local
 
#!/bin/sh
 
...
 
/opt/bamboo-elastic-agent/bin/runStartupScripts.sh
if [ $? -eq 0 ]; then
    echo "Starting Elastic Bamboo Agent..."
    ...
else
    echo "Elastic Bamboo Agent not started."
fi

...
Chason Choate August 18, 2015

Thanks for the response. I added a clarification to my question stating that the root account is disabled via SSH completely. (I can still run "sudo" and "sudo su -" but wouldn't be able to SSH into the root account) Therefore how can I configure Bamboo to run the "instance setup script" as a user other than root?

Marcin Oles
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
August 19, 2015

Hey, I've updated my answer after your clarification, hope it helps.

Chason Choate August 19, 2015

You're my hero! I indeed was building from scratch with packer and never knew to run /opt/elastic-bamboo-agent/bin/runStartupScripts.sh! This has solved my problem, thank you so much for the help!

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events