What would a systemd service file look like for an agate server?

A systemd service file for an Agate Gemini server defines how the Agate service should start, stop, and manage the Gemini server.

A systemd service file for an Agate Gemini server defines how the Agate service should start, stop, and manage the Gemini server. Below is a sample service file for Agate:

Example Agate Systemd Service File

  1. Create the service file:
    You will typically place this file at /etc/systemd/system/agate.service.

Service File Contents:

[Unit]
Description=Agate Gemini Server
After=network.target

[Service]
ExecStart=/usr/local/bin/agate --content /path/to/content --hostname example.com --key /path/to/key.pem --cert /path/to/cert.pem
Restart=on-failure
User=agate
Group=agate
WorkingDirectory=/path/to/content
Environment=AGATE_PORT=1965
LimitNOFILE=4096

[Install]
WantedBy=multi-user.target

Explanation of Each Section:

[Unit]

  • Description: A short explanation of what the service is for.
  • After: Specifies that the service should start after the network is available.

[Service]

  • ExecStart: The command to start the Agate server. Replace the path /usr/local/bin/agate with the actual path to your Agate binary, and replace /path/to/content, /path/to/key.pem, and /path/to/cert.pem with the appropriate paths for your setup.
  • Restart: Ensures that the service restarts if it fails.
  • User: Runs the service as the user agate. You may need to create this user if it doesn't exist.
  • Group: Runs the service under the group agate.
  • WorkingDirectory: The working directory for Agate, where your Gemini capsule content is stored.
  • Environment: Sets environment variables like the port for Agate (AGATE_PORT=1965), which is the default port for Gemini.
  • LimitNOFILE: Increases the file descriptor limit, which may be needed for serving multiple connections.

[Install]

  • WantedBy: This tells systemd to start the service in the multi-user run level (which is the common run level for most server environments).

Commands to Enable and Start the Service:

Check the service status:

sudo systemctl status agate

Start the service:

sudo systemctl start agate

Enable the service to start on boot:

sudo systemctl enable agate

Reload systemd to recognize the new service:

sudo systemctl daemon-reload

This service file will manage the Agate server, ensuring it runs at system startup and restarts if it encounters failures. Adjust paths, user names, and other variables to match your environment.