# Runs the Bamboo agent.
description bamboo

# Auto start on reboot
start on (local-filesystems and (net-device-up IFACE=eth2 or net-device-up IFACE=wall))
stop on runlevel [016]

# Restart the service anytime it crashes.
respawn

chdir /home/{{bamboo_user}}

setuid {{bamboo_user}}
# Without using setgid explicitly upstarts seems to leave the root (0) group in
# in the supplementary groups of the user. This doesn't interact well
# with Python/Ansible resulting in calls to os.getgroups() to not return the
# user's primary group in the list of groups.
setgid {{bamboo_group}}

# These environment variables are used by various things (setup script, Ansible)
# and aren't set by default.
env HOME='/home/{{bamboo_user}}'
export HOME
env USER='{{bamboo_user}}'
export USER

{% if set_unlimited_rtprio is defined %}
{#
  For agents which run cammux online, this needs to be set so that cammux spawned
  from the agent can properly set realtime priority for its threads.
#}
limit rtprio unlimited unlimited
{% endif %}
limit memlock unlimited unlimited
limit nofile 50000 50000

exec /usr/bin/java -jar /home/{{bamboo_user}}/{{bamboo_agent_jar}} {{bamboo_server_url}} -t {{bamboo_server_token}}
