Supervising services with tmux

Properly configuring your service manager is good and all, but sometimes I just want to start a few services on startup and be able to tinker with them as I go.

My solution is just to run my stuff in a tmux.

I mean, this is a shell script. You can specify things and wait for readiness in whatever way you wish.

#!/bin/sh

set -ux

session="services"

tmux has-session -t "$session" 2>/dev/null && { tmux attach -t "$session"; exit 0; }

tmux new-session -d -s "$session" -n misc

tmux new-window -t "$session" -n arahli
tmux send-keys -t "$session:arahli" 'arahli -config /etc/lindenii/arahli/443.conf' c-m

tmux new-window -t "$session" -n villosad
tmux send-keys -t "$session:villosad" 'su -ls /bin/sh -c "villosad" villosa' c-m

tmux select-window -t "$session:misc"
tmux attach -t "$session"

Note that this does not give you restarts. I personally don’t want them; if something crashes, I prefer for it to stay down until I get to look at them. You could just add a loop though.

And of course this needs to be started via OpenRC or such.

#!/sbin/openrc-run
 
description="tmux-based service manager thingy"

depend() {
	need net
	after bootmisc
}

start() {
	ebegin "Starting the tmux-based service manager thingy"
	/root/startsvc
	eend $?
}

There are, obviously, better setups than this. Sometime I might work on making my service manager and process supervisor support tty detach/attach. But this works for me, for now.