-- Leo's gemini proxy

-- Connecting to gemini.sh0.xyz:1965...

-- Connected

-- Sending request

-- Meta line: 20 text/gemini

More Running Multiple Servers


Full Setup available here.


To continue my progress of replacing my simple web pages with Gemini proxied capsules I needed to get Kineto[1] to run multiple instances pointing to different pages and served on different ports. Only problem, kineto doesn't support config files and systemd unit files kind of suck with a dynamic layout.


I've never been a big fan of systemd. When possible I've actively worked at not running it. Making a monolith isn't great but that it the design that shows unseasoned developers. A purely configuration based init system is create when you have nothing special going on but that is rarely the case.



Kineto's command line arguments is as follows:


kineto [-b 127.0.0.1:1866] [-s style.css] [-e style.css] gemini://example.com

All the args are optional except for the last. We could grab them from environment variables which systemd supports.


[Unit]
Description=Kineto Gemini to HTTP Proxy
After=network.target

[Service]
Type=simple
Restart=always
User=molly
EnvironmentFile=/etc/kineto-%i.conf
ExecStart=/usr/local/bin/kineto -b $BIND -s $CSS_FILE -s $CSS_PATH $GEMINI_URL

[Install]
WantedBy=multi-user.target

Only problem is that doesn't really make the args optional. Could make it really hacky and include the flags in the environment variables, but that is just crappy design. Kinda like systemd. Now we need a wrapper script that will handle the arguments optionally.


#!/bin/sh
# /usr/local/bin/kineto-wrapper

if [ -z "${GEMINI_URL}" ]; then
  printf "Missing config GEMINI_URL\n" 1>&2
  exit 1
fi

ARGS=""

if [ ! -z "${BIND}" ]; then
  ARGS="${ARGS} -b ${BIND}"
fi

if [ ! -z "${CSS_FILE}" ]; then
  ARGS="${ARGS} -s ${CSS_FILE}"
fi

if [ ! -z "${CSS_URL}" ]; then
  ARGS="${ARGS} -e ${CSS_URL}"
fi

eval "/usr/local/bin/kineto ${ARGS} ${GEMINI_URL}"

Last step is to modify the unit file.


EnvironmentFile=/etc/kineto-%i.conf
ExecStart=/usr/local/bin/kineto-wrapper

Create as many config files as needed, in my case 2. Then start and enable them.


$ sudo systemctl start kineto@ad0qm
$ sudo systemctl enable kineto@ad0qm
$ sudo systemctl start kineto@sh0
$ sudo systemctl enable kineto@sh0

[1] Kineto


$ published: 2023-03-12 16:20 $

$ tags: #gemini $


-- CC-BY-4.0 jecxjo 2023-03-12


back

-- Response ended

-- Page fetched on Tue May 21 14:29:30 2024