1# Running Soft Serve as a Systemd Service23Most Linux OSes use Systemd as an init system and service management. You can4use Systemd to manage Soft Serve as a service on your host machine.56Our Soft Serve deb/rpm packages come with Systemd service files pre-packaged.7You can install `soft-serve` from our Apt/Yum repositories. Follow the8[installation instructions](https://github.com/charmbracelet/soft-serve#installation) for9more information.1011## Writing a Systemd Service File1213> **Note** you can skip this section if you are using our deb/rpm packages or14> installed Soft Serve from our Apt/Yum repositories.1516Start by writing a Systemd service file to define how your Soft Serve server17should start.1819First, we need to specify where the data should live for our server. Here I20will be choosing `/var/local/lib/soft-serve` to store the server's data. Soft21Serve will look for this path in the `SOFT_SERVE_DATA_PATH` environment22variable.2324Make sure this directory exists before proceeding.2526```sh27sudo mkdir -p /var/local/lib/soft-serve28```2930We will also create a `/etc/soft-serve.conf` file for any extra server settings that we want to override.3132```conf33# Config defined here will override the config in /var/local/lib/soft-serve/config.yaml34# Keys defined in `SOFT_SERVE_INITIAL_ADMIN_KEYS` will be merged with35# the `initial_admin_keys` from /var/local/lib/soft-serve/config.yaml.36#37#SOFT_SERVE_GIT_LISTEN_ADDR=:941838#SOFT_SERVE_HTTP_LISTEN_ADDR=:2323239#SOFT_SERVE_SSH_LISTEN_ADDR=:2323140#SOFT_SERVE_SSH_KEY_PATH=ssh/soft_serve_host_ed2551941#SOFT_SERVE_INITIAL_ADMIN_KEYS='ssh-ed25519 AAAAC3NzaC1lZDI1...'42```4344> **Note** Soft Serve stores its server configuration and settings in45> `config.yaml` under its _data path_ directory specified using46> `SOFT_SERVE_DATA_PATH` environment variable.4748Now, let's write a new `/etc/systemd/system/soft-serve.service` Systemd service file:4950```conf51[Unit]52Description=Soft Serve git server 🍦53Documentation=https://github.com/charmbracelet/soft-serve54Requires=network-online.target55After=network-online.target5657[Service]58Type=simple59Restart=always60RestartSec=161ExecStart=/usr/bin/soft serve62Environment=SOFT_SERVE_DATA_PATH=/var/local/lib/soft-serve63EnvironmentFile=-/etc/soft-serve.conf64WorkingDirectory=/var/local/lib/soft-serve6566[Install]67WantedBy=multi-user.target68```6970Great, we now have a Systemd service file for Soft Serve. The settings defined71here may vary depending on your specific setup. This assumes that you want to72run Soft Serve as `root`. For more information on Systemd service files, refer73to74[systemd.service](https://www.freedesktop.org/software/systemd/man/systemd.service.html)7576## Start Soft Serve on boot7778Now that we have our Soft Serve Systemd service file in-place, let's go ahead79and enable and start Soft Serve to run on-boot.8081```sh82# Reload systemd daemon83sudo systemctl daemon-reload84# Enable Soft Serve to start on-boot85sudo systemctl enable soft-serve.service86# Start Soft Serve now!!87sudo systemctl start soft-serve.service88```8990You can monitor the server logs using `journalctl -u soft-serve.service`. Use91`-f` to _tail_ and follow the logs as they get written.9293***9495Part of [Charm](https://charm.sh).9697<a href="https://charm.sh/"><img alt="The Charm logo" src="https://stuff.charm.sh/charm-badge-unrounded.jpg" width="400"></a>9899Charm热爱开源 • Charm loves open source