Deployment¶
A bot is one long-running process holding one connection. Run it as exactly one instance: a container, a systemd service, or pinhook run.
Run one copy¶
Two copies of a bot fight over its nick and answer every command twice. Every example here runs one copy, and replaces it by stopping the old one first: strategy: Recreate on Kubernetes, never a rolling update. Restarts are safe: the bot reconnects, and its state is on disk.
Keep state on a volume¶
data_dir holds plugin stores, grants and denies, bans, !enable and !disable, and STS policies. recipes/ holds recipes added from chat. Put both on a persistent volume with one writer. A backup is a copy of the two folders.
The config is read only. Check it in CI before it's deployed:
pinhook check --strict config.yaml
Pass secrets¶
Write ${NAME} for an environment variable and ${file:PATH} for a file, which is how Docker and Kubernetes secrets arrive:
sasl_password: '${file:/run/secrets/sasl_password}'
secrets.env beside the config is for a plain install. A variable already in the environment wins. Secrets show as *** in the log.
Logs¶
log_file: '-'
log_format: json
log_file: '-' writes to stdout. log_format: json writes one JSON object per line, with time, level, bot and message, and error with the traceback:
{"time": "2026-11-02T10:15:00.123+00:00", "level": "info", "bot": "gamebot", "message": "mal (account mal) ran !ban troll: banned troll (account trollacct)", "audit": true}
Changes to who can do what are audit lines, logged with who made them and carrying "audit": true: !op, !deop, !ban, !unban, !allow, !deny, !revoke, !enable, !disable and !recipe.
Health checks¶
health_port: 8080
/healthz answers 200 while the process runs. /readyz answers 200 once the bot is connected and in every channel in its config, and 503 with the reason before then, like not in #games. It listens on health_host, 127.0.0.1 by default.
Shut down cleanly¶
SIGTERM lets running commands finish and sends what's waiting, for up to 5 seconds, then quits. Give the bot longer than that to stop: the examples give it 30 seconds.
Network¶
A bot makes outbound connections only: IRC on 6697, or Twitch's chat servers. It needs no inbound ports apart from the health endpoint.
The image¶
ghcr.io/archangelic/pinhook is pinhook on Python 3.15's slim image, for amd64 and arm64, tagged with each version and its minor and major, like 2.0.0, 2.0 and 2. It runs as user 10001, with /bot as its folder:
| Path | Holds |
|---|---|
/bot/config.yaml |
the config, mounted read only |
/bot/plugins |
plugins, mounted or built in |
/bot/recipes |
recipes, writable for !recipe add |
/bot/data |
the volume |
It runs pinhook run /bot/config.yaml, logs to stdout, and serves the health endpoint on 8080. A bot with plugin dependencies builds its own image on it:
FROM ghcr.io/archangelic/pinhook:2
COPY plugins /bot/plugins
RUN pip install --no-cache-dir requests
Each image is signed with cosign. Check one:
cosign verify ghcr.io/archangelic/pinhook:2 \
--certificate-identity-regexp '^https://github.com/archangelic/pinhook/' \
--certificate-oidc-issuer https://token.actions.githubusercontent.com
Docker Compose¶
Save these beside config.yaml, plugins/ and recipes/, with the bot account's password in sasl_password.txt, then run docker compose up -d.
compose.yaml:
# One pinhook bot. Beside this file: config.yaml, plugins/, recipes/ and
# sasl_password.txt holding the bot account's password. The bot runs as uid 10001,
# so give it recipes/ for the recipes ops add from chat: sudo chown 10001 recipes
#
# docker compose up -d
# docker compose logs -f
services:
bot:
image: ghcr.io/archangelic/pinhook:2
# one copy only, since two would fight over the nick
restart: unless-stopped
configs:
- source: config
target: /bot/config.yaml
secrets:
- sasl_password
volumes:
- ./plugins:/bot/plugins:ro
- ./recipes:/bot/recipes
- data:/bot/data
# longer than the bot's shutdown_wait, so it quits cleanly
stop_grace_period: 30s
configs:
config:
file: ./config.yaml
secrets:
sasl_password:
file: ./sasl_password.txt
volumes:
data:
config.yaml:
nickname: 'gamebot'
server: 'irc.libera.chat'
port: 6697
ssl_required: true
channels:
- '#gamebot-test'
ops:
- '$a:youraccount'
# compose mounts the secret here
sasl_password: '${file:/run/secrets/sasl_password}'
systemd¶
For a plain pip install on a server. Save this as /etc/systemd/system/pinhook.service, after the steps at its top:
# A pinhook bot from a plain pip install, as the pinhook user:
#
# sudo useradd --system --home-dir /srv/pinhook --shell /usr/sbin/nologin pinhook
# sudo python3 -m venv /srv/pinhook/venv
# sudo /srv/pinhook/venv/bin/pip install pinhook
#
# Put config.yaml, plugins/ and recipes/ in /srv/pinhook, and secrets in
# /srv/pinhook/secrets.env, owned by pinhook with mode 600. Then:
#
# sudo mkdir -p /srv/pinhook/data /srv/pinhook/recipes
# sudo chown -R pinhook: /srv/pinhook
# sudo cp pinhook.service /etc/systemd/system/
# sudo systemctl enable --now pinhook
# journalctl -u pinhook -f
[Unit]
Description=pinhook bot
Wants=network-online.target
After=network-online.target
[Service]
Type=exec
User=pinhook
WorkingDirectory=/srv/pinhook
ExecStart=/srv/pinhook/venv/bin/pinhook run /srv/pinhook/config.yaml
# logs to the journal, and the health endpoint for a monitor to check
Environment=PINHOOK_BOT_DIR=/srv/pinhook PINHOOK_LOG_FILE=- PINHOOK_HEALTH_PORT=8080
Restart=on-failure
RestartSec=10
# longer than the bot's shutdown_wait, so it quits cleanly
TimeoutStopSec=30
NoNewPrivileges=yes
ProtectSystem=strict
ProtectHome=yes
PrivateTmp=yes
PrivateDevices=yes
ReadWritePaths=/srv/pinhook/data /srv/pinhook/recipes
[Install]
WantedBy=multi-user.target
/srv/pinhook/config.yaml:
nickname: 'gamebot'
server: 'irc.libera.chat'
port: 6697
ssl_required: true
channels:
- '#gamebot-test'
ops:
- '$a:youraccount'
# from secrets.env beside this file: SASL_PASSWORD=...
sasl_password: '${SASL_PASSWORD}'
Kubernetes¶
A ConfigMap for the config, a PersistentVolumeClaim for data/ and recipes/, and a Deployment with one replica, strategy: Recreate and probes on the health endpoint:
# One pinhook bot on Kubernetes: its config, its secret, a volume for data/ and
# recipes/, and the bot itself. Plugins go in an image built on pinhook's:
#
# FROM ghcr.io/archangelic/pinhook:2
# COPY plugins /bot/plugins
#
# kubectl create secret generic gamebot-secrets --from-literal=sasl_password=...
# kubectl apply -f pinhook.yaml
# kubectl logs -f deployment/gamebot
apiVersion: v1
kind: ConfigMap
metadata:
name: gamebot-config
data:
config.yaml: |
nickname: 'gamebot'
server: 'irc.libera.chat'
port: 6697
ssl_required: true
channels:
- '#gamebot-test'
ops:
- '$a:youraccount'
# the Secret is mounted here
sasl_password: '${file:/run/secrets/pinhook/sasl_password}'
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: gamebot-data
spec:
accessModes: [ReadWriteOnce]
resources:
requests:
storage: 1Gi
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: gamebot
labels:
app: gamebot
spec:
# one copy only, since two would fight over the nick. Recreate stops the old pod
# before starting the new one
replicas: 1
strategy:
type: Recreate
selector:
matchLabels:
app: gamebot
template:
metadata:
labels:
app: gamebot
spec:
# longer than the bot's shutdown_wait, so it quits cleanly
terminationGracePeriodSeconds: 30
securityContext:
runAsNonRoot: true
runAsUser: 10001
fsGroup: 10001
seccompProfile:
type: RuntimeDefault
containers:
- name: bot
image: ghcr.io/archangelic/pinhook:2
ports:
- name: health
containerPort: 8080
livenessProbe:
httpGet:
path: /healthz
port: health
readinessProbe:
httpGet:
path: /readyz
port: health
securityContext:
allowPrivilegeEscalation: false
readOnlyRootFilesystem: true
capabilities:
drop: [ALL]
volumeMounts:
- name: config
mountPath: /bot/config.yaml
subPath: config.yaml
readOnly: true
- name: secrets
mountPath: /run/secrets/pinhook
readOnly: true
- name: data
mountPath: /bot/data
subPath: data
- name: data
mountPath: /bot/recipes
subPath: recipes
volumes:
- name: config
configMap:
name: gamebot-config
- name: secrets
secret:
secretName: gamebot-secrets
- name: data
persistentVolumeClaim:
claimName: gamebot-data
Each example is started against a real IRC server in pinhook's CI, so these files work as shown.