Running a TeamCity agent as a system service ensures it continues working after logout and automatically starts on boot. This is the recommended production setup.
📁 Prerequisites
Make sure your TeamCity agent is installed in:
/opt/teamcity/bin/agent.sh
👉 The agent.sh script must exist inside the bin directory:
/opt/teamcity/bin/agent.sh
Also ensure it is executable:
chmod +x /opt/teamcity/bin/agent.sh
⚙️ Create systemd service
Create the file:
sudo nano /etc/systemd/system/teamcity-agent.service
Paste the following configuration:
[Unit]
Description=TeamCity Build Agent
After=network.target
[Service]
Type=oneshot
User=root
Group=root
WorkingDirectory=/opt/teamcity
ExecStart=/opt/teamcity/bin/agent.sh start
ExecStop=/opt/teamcity/bin/agent.sh stop
RemainAfterExit=yes
SuccessExitStatus=0 143
[Install]
WantedBy=multi-user.target
🚀 Enable and start the service
Reload systemd and start the agent:
sudo systemctl daemon-reload
sudo systemctl enable teamcity-agent
sudo systemctl start teamcity-agent
🔍 Verify status
systemctl status teamcity-agent
Expected result:
Active: active (exited)
This is normal for TeamCity agents when using Type=oneshot.
⚠️ Notes
- The agent must be located in
/opt/teamcity/bin/agent.sh -
RemainAfterExit=yesis required so systemd considers the service active -
SuccessExitStatus=143prevents false failure detection - Using
rootworks, but for production it's safer to use a dedicated user
Top comments (0)