bamboo instance setup script
Asked by Chason Choate:

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](https://confluence.atlassian.com/display/BAMBOO/Creating+a+custom+elastic+image) "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?


Answers:
author: Marcin Oles
body: 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# ...# ...whoamiexec sudo -u centos /bin/sh - &lt;&lt; EOF  # code as centos here  # ...  # ...  whoamiEOF
```

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/shsudo -u centos -H sh -c 'echo $HOME'    # out: /home/centossudo -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.shif [ $? -eq 0 ]; then    echo "Starting Elastic Bamboo Agent..."    ...else    echo "Elastic Bamboo Agent not started."fi...
```

comments: author: Chason Choate
body: 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?


author: Marcin Oles
body: Hey, I've updated my answer after your clarification, hope it helps.


author: Chason Choate
body: 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!


Tags: bamboo-administration