How to change the user running remote agent daemon on macOS
Platform notice: Server and Data Center only. This article only applies to Atlassian products on the Server and Data Center platforms.
Support for Server* products ended on February 15th 2024. If you are running a Server product, you can visit the Atlassian Server end of support announcement to review your migration options.
*Except Fisheye and Crucible
Summary
Due to some requirements, the remote agent's daemon running on macOS may need to run with a specific user.
Diagnosis
During the remote agent startup, we can check in the atlassian-bamboo-agent.log which user is running the process:
INFO | jvm 1 | 2021/03/08 12:26:54 | 2021-03-08 12:26:54,592 INFO [AgentRunnerThread] [lifecycle] *******************************
INFO | jvm 1 | 2021/03/08 12:26:54 | 2021-03-08 12:26:54,593 INFO [AgentRunnerThread] [lifecycle] * System information *
INFO | jvm 1 | 2021/03/08 12:26:54 | 2021-03-08 12:26:54,593 INFO [AgentRunnerThread] [lifecycle] *******************************
INFO | jvm 1 | 2021/03/08 12:26:54 | 2021-03-08 12:26:54,704 INFO [AgentRunnerThread] [lifecycle] com.atlassian.bamboo.configuration.SystemInfoImpl@2e0f7f47[
INFO | jvm 1 | 2021/03/08 12:26:54 | userName=root
INFO | jvm 1 | 2021/03/08 12:26:54 | userTimezone=America/New_York
INFO | jvm 1 | 2021/03/08 12:26:54 | userLocale=English (United States)
INFO | jvm 1 | 2021/03/08 12:26:54 | systemEncoding=UTF-8
Cause
By default, the daemon will be set to run as root.
Solution
- Stop Bamboo agent;
- Remove the service using <Remote agent home>/bin/bamboo-agent.sh remove;
Since the daemon probably ran as root before, we will need to change some permissions, run:
sudo chown -R bamboo <Agent home folder>
- Install the service running <Remote agent home>/bin/bamboo-agent.sh install. Do not run it;
- Edit /Library/LaunchDaemons/org.tanukisoftware.wrapper.bamboo-agent.plist add <key>UserName</key> as in the example below:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN"
"http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>org.tanukisoftware.wrapper.bamboo-agent</string>
<key>ProgramArguments</key>
<array>
<string>/Users/bamboo/agent-home-7.2.2/bin/bamboo-agent.sh</string>
<string>launchdinternal</string>
</array>
<key>KeepAlive</key>
<false/>
<key>RunAtLoad</key>
<true/>
<key>UserName</key>
<string>bamboo</string>
</dict>
</plist>
6. Start the agent by loading the daemon:
sudo launchctl load -w /Library/LaunchDaemons/org.tanukisoftware.wrapper.bamboo-agent.plist
Note: By default macOS daemon doesn't pick up the environment variables from the user, to add it please check the Incorrect environment variables when running remote agent on macOS KB.