# Notes:
#
# The template parameter is the instance number. Use `%I` in Description or
# similar and `%i` everywhere else (`%I` is rewritten by Build OS monitor to
# include the toolchain name).
#
[Unit]
Description=bbot agent %I
After=multi-user.target

[Service]
Type=simple

Environment=VERBOSE=3

Environment=CPU=1
Environment=RAM_BUILD=4194304
Environment=RAM_AUXIL=0
Environment=BRIDGE=br1

Environment=AUTH_KEY=

Environment=INTERACTIVE=false

Environment=BOOTSTRAP_TIMEOUT=3600
Environment=BOOTSTRAP_AUXILIARY=900
Environment=BOOTSTRAP_RETRIES=2

Environment=BUILD_TIMEOUT=5400
Environment=BUILD_RETRIES=2

Environment=INTERACTIVE_TIMEOUT=10800

Environment=CONNECT_TIMEOUT=60
Environment=REQUEST_TIMEOUT=300
Environment=REQUEST_RETRIES=4

Environment=TOOLCHAIN_NAME=default
Environment=TOOLCHAIN_NUM=1
Environment=TOOLCHAIN_VER=
Environment=TOOLCHAIN_ID=

Environment=INSTANCE_MAX=0

Environment="CONTROLLER_URL="
Environment="CONTROLLER_TRUST="

# Note that we cannot use ${TOOLCHAIN_NAME} in the first word of ExecStart.
#
ExecStart=/build/bots/default/bin/bbot-agent \
  --systemd-daemon \
  --verbose ${VERBOSE} \
  --cpu ${CPU} \
  --build-ram ${RAM_BUILD} \
  --auxiliary-ram ${RAM_AUXIL} \
  --bridge ${BRIDGE} \
  --auth-key ${AUTH_KEY} \
  --interactive ${INTERACTIVE} \
  --bootstrap-timeout ${BOOTSTRAP_TIMEOUT} \
  --bootstrap-auxiliary ${BOOTSTRAP_AUXILIARY} \
  --bootstrap-retries ${BOOTSTRAP_RETRIES} \
  --build-timeout ${BUILD_TIMEOUT} \
  --build-retries ${BUILD_RETRIES} \
  --intactive-timeout ${INTERACTIVE_TIMEOUT} \
  --connect-timeout ${CONNECT_TIMEOUT} \
  --request-timeout ${REQUEST_TIMEOUT} \
  --request-retries ${REQUEST_RETRIES} \
  --toolchain-name ${TOOLCHAIN_NAME} \
  --toolchain-num ${TOOLCHAIN_NUM} \
  --toolchain-ver ${TOOLCHAIN_VER} \
  --toolchain-id ${TOOLCHAIN_ID} \
  --instance-max ${INSTANCE_MAX} \
  --instance %i \
  $CONTROLLER_TRUST \
  $CONTROLLER_URL

Nice=0
CPUAffinity=
User=build
Group=build
WorkingDirectory=~

[Install]
WantedBy=multi-user.target
