In production environments, server processes should be managed by a process supervisor that can start, stop, and automatically restart the service if it exits unexpectedly. Several options are available on Unix-like systems, including perpd, systemd, runit, and s6. This section covers perpd and systemd as representative examples.
perpd is a lightweight
process supervisor that monitors a set of services defined as directories under
a base path (typically /etc/perp). Each service directory
contains a rc.main script that starts and stops the
service. The supervisor will automatically restart the service if it
terminates.
To set up a VRTQL server as a perpd service, create a service directory and its control script:
# mkdir -p /etc/perp/vrtql-ws
Then create the /etc/perp/vrtql-ws/rc.main script:
#!/bin/sh
exec 2>&1
TARGET=${1}
start()
{
exec /usr/local/bin/vrtql-ws-server
}
reset()
{
exit 0
}
eval ${TARGET} "$@"
Make the script executable and activate the service:
#chmod +x /etc/perp/vrtql-ws/rc.main#perpctl A vrtql-ws
The service can be controlled using perpctl:
#perpctl d vrtql-ws # stop (down)#perpctl u vrtql-ws # start (up)#perpstat vrtql-ws # check status
On systems using systemd, you can create a unit file
to manage the VRTQL server. Create
/etc/systemd/system/vrtql-ws.service:
[Unit] Description=VRTQL WebSocket Server After=network.target [Service] Type=simple ExecStart=/usr/local/bin/vrtql-ws-server Restart=always RestartSec=5 Environment=VWS_HOST=127.0.0.1 Environment=VWS_PORT=8181 Environment=VWS_THREADS=10 [Install] WantedBy=multi-user.target
Enable and start the service:
#systemctl daemon-reload#systemctl enable vrtql-ws#systemctl start vrtql-ws#systemctl status vrtql-ws
The Restart=always directive ensures that
systemd will automatically restart the server if it exits for
any reason. The RestartSec=5 directive adds a five-second
delay before restarting, which prevents rapid restart loops in the event of a
persistent failure.