Title: Managing a bouncer via OpenRC
Date: 2023-11-24 16:30

I'm an avid [IRC](https://en.wikipedia.org/wiki/Internet_Relay_Chat)
user, and I'm using [XMPP](https://en.wikipedia.org/wiki/XMPP) to idle on
[Tails](https://tails.net/support/index.en.html)' chatrooms. Since protocols
tend to only work when one is connected, they're both running inside a
[tmux](https://github.com/tmux/tmux) session, acting as a
[bouncer](https://en.wikipedia.org/wiki/BNC_(software)).
But now that my hypervisor is automatically rebooting to apply security updates,
and during power cuts via [nut](https://networkupstools.org/),
I needed a way to automatically restart the bouncer. Since
it's running in an [Alpine Linux](https://www.alpinelinux.org/) container,
here is my solution in the form of an [OpenRC](https://github.com/OpenRC/openrc)
service script, because I couldn't find one on the internet:

```bash
#!/sbin/openrc-run

USER=jvoisin

name="chat"
command_user="$USER"
command=/usr/bin/tmux
command_args="new-session -s chat -d '/usr/bin/weechat' \; new-window '/usr/bin/profanity' \; select-window -t -1"
pidfile="/run/$SVCNAME.pid"
                        
depend() {
        need net
        use dns 
}              
 
stop() {
        su "$USER" -c 'tmux kill-session chat'
}
```
