Running as a service
Set up rChat server to start automatically on boot and restart on failure.
systemd (Linux)
Section titled “systemd (Linux)”Create the service file:
sudo nano /etc/systemd/system/rchat-server.service[Unit]Description=rChat ServerAfter=network-online.targetWants=network-online.target
[Service]Type=simpleUser=rootExecStart=/usr/local/bin/rchat-server --config /etc/rchat/server.tomlRestart=on-failureRestartSec=5LimitNOFILE=65536
# Redirect logs to journalStandardOutput=journalStandardError=journalSyslogIdentifier=rchat-server
[Install]WantedBy=multi-user.targetEnable and start:
sudo systemctl daemon-reloadsudo systemctl enable rchat-serversudo systemctl start rchat-serverCheck status:
sudo systemctl status rchat-serverView logs:
sudo journalctl -u rchat-server -fManaging the service
Section titled “Managing the service”| Action | Command |
|---|---|
| Start | sudo systemctl start rchat-server |
| Stop | sudo systemctl stop rchat-server |
| Restart | sudo systemctl restart rchat-server |
| Reload config | sudo systemctl reload rchat-server |
| View logs | sudo journalctl -u rchat-server -f |
| Disable autostart | sudo systemctl disable rchat-server |
TLS certificate auto-renewal
Section titled “TLS certificate auto-renewal”If using Let’s Encrypt, add a deploy hook to reload rChat when the certificate renews:
sudo nano /etc/letsencrypt/renewal-hooks/deploy/rchat-reload.sh#!/bin/bashsystemctl reload rchat-server 2>/dev/null || systemctl restart rchat-serversudo chmod +x /etc/letsencrypt/renewal-hooks/deploy/rchat-reload.shTest the renewal process:
sudo certbot renew --dry-runFreeBSD rc(8)
Section titled “FreeBSD rc(8)”Create /usr/local/etc/rc.d/rchat_server:
#!/bin/sh# PROVIDE: rchat_server# REQUIRE: NETWORKING# KEYWORD: shutdown
. /etc/rc.subr
name="rchat_server"rcvar="rchat_server_enable"command="/usr/local/bin/rchat-server"command_args="--config /usr/local/etc/rchat/server.toml"pidfile="/var/run/rchat-server.pid"
load_rc_config $namerun_rc_command "$1"chmod +x /usr/local/etc/rc.d/rchat_serverecho 'rchat_server_enable="YES"' >> /etc/rc.confservice rchat_server startmacOS launchd
Section titled “macOS launchd”Create /Library/LaunchDaemons/io.rchat.server.plist:
<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"><plist version="1.0"><dict> <key>Label</key> <string>io.rchat.server</string> <key>ProgramArguments</key> <array> <string>/usr/local/bin/rchat-server</string> <string>--config</string> <string>/usr/local/etc/rchat/server.toml</string> </array> <key>RunAtLoad</key> <true/> <key>KeepAlive</key> <true/> <key>StandardOutPath</key> <string>/var/log/rchat-server.log</string> <key>StandardErrorPath</key> <string>/var/log/rchat-server.log</string></dict></plist>Load and start:
sudo launchctl load /Library/LaunchDaemons/io.rchat.server.plistsudo launchctl start io.rchat.serverView logs:
tail -f /var/log/rchat-server.log