Created
June 10, 2022 15:45
-
-
Save mikehearn/5299a3ae41bdd2c59ad7711688ee1d2a to your computer and use it in GitHub Desktop.
An example systemd service for TeamCity
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[Unit] | |
After=postgresql.service | |
Description=JetBrains TeamCity | |
Requires=postgresql.service | |
Wants=network-online.target | |
# Can be included to allow a server to write to its own files. | |
[Service] | |
CacheDirectory=jetbrains/teamcity | |
ConfigurationDirectory=jetbrains/teamcity | |
# Lightly sandbox the service in the classical UNIX way, but without needing to clean up the user/group afterwards. | |
# See: http://0pointer.net/blog/dynamic-users-with-systemd.html | |
DynamicUser=yes | |
# Some servers want to write to $HOME even though conventionally UNIX services don't have one. | |
# https://www.jetbrains.com/help/teamcity/installing-and-configuring-the-teamcity-server.html#Setting+Up+Memory+settings+for+TeamCity+Server | |
Environment=HOME=/var/lib/jetbrains/teamcity | |
# Some servers want to write to $HOME even though conventionally UNIX services don't have one. | |
# https://www.jetbrains.com/help/teamcity/installing-and-configuring-the-teamcity-server.html#Setting+Up+Memory+settings+for+TeamCity+Server | |
Environment=TEAMCITY_SERVER_MEM_OPTS=-Xmx2048m | |
ExecStart=/usr/lib/jetbrains/teamcity/bin/teamcity-server.sh run | |
# The ! mark here makes the script run as root but after uid/gid allocation is done. | |
ExecStartPre=!/bin/sh -c "chown -R --preserve-root -h jetbrains-teamcity:jetbrains-teamcity /usr/lib/jetbrains/teamcity" | |
ExecStop=/usr/lib/jetbrains/teamcity/bin/teamcity-server.sh stop | |
Group=jetbrains-teamcity | |
LogsDirectory=jetbrains/teamcity | |
ReadWritePaths=+/usr/lib/jetbrains/teamcity | |
# Restart the service if it crashes, is OOM killed etc, but not if it quits with a non-zero exit code | |
# (which probably implies a bad configuration file or similar). | |
Restart=on-abnormal | |
StateDirectory=jetbrains/teamcity | |
# Type=exec has more much sensible behaviour than Type=simple. Also the systemd maintainer stated in a talk in 2018 that | |
# 'exec' is the right way to go, and opt-in only for compatibility reasons. | |
# https://media.ccc.de/v/ASG2018-230-systemd_in_2018#t=491 | |
Type=exec | |
User=jetbrains-teamcity | |
WorkingDirectory=/usr/lib/jetbrains/teamcity | |
[Install] | |
WantedBy=default.target |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment