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.
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?
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 ...
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?
I'm John Allspaw, co-founder of Adaptive Capacity Labs, where we help teams use their incidents to learn and improve. We bring research-driven methods and approaches to drive effective inciden...
Connect with like-minded Atlassian users at free events near you!Find a group
Connect with like-minded Atlassian users at free events near you!
Unfortunately there are no AUG chapters near you at the moment.Start an AUG
You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs