Running Liwan as a Service
Liwan can run as a service so it starts automatically when your server boots. This page shows examples for systemd and OpenRC.
-
Creating the service
To run Liwan as a service usingsystemd, create a new service file in/etc/systemd/system/liwan.servicewith the following content:/etc/systemd/system/liwan.service [Unit]Description=Liwan Web AnalyticsAfter=network.target[Service]# Replace `yourusername` with your usernameExecStart=/home/yourusername/.local/bin/liwanRestart=on-failureUser=yourusername[Install]WantedBy=multi-user.targetReplace
yourusernameand adjust the paths to match your setup. To generate a configuration file, you can runliwan generate-config -o ~/.config/liwan/liwan.config.toml. -
Starting the service
After creating the service file, reload the systemd daemon and start the service:Terminal window # Reload the systemd daemonsudo systemctl daemon-reload# Enable the service to start automatically on bootsudo systemctl enable liwan# Start the servicesudo systemctl start liwan -
Checking the status
You can now check the status of the service usingsystemctl status liwanand view the logs usingjournalctl -u liwan. If this is the first time you are running Liwan, you can find a link to set up your account in the logs.
-
Creating the service
To run Liwan as a service usingOpenRC, create a new service script in/etc/init.d/liwanwith the following content:/etc/init.d/liwan #!/sbin/openrc-runname="Liwan"description="Liwan Web Analytics"command_user="yourusername"command="/home/${command_user}/.local/bin/liwan"command_background=truepidfile="/run/${RC_SVCNAME}.pid"capabilities="^cap_net_bind_service"output_log="/var/log/liwan/liwan.log"error_log="/var/log/liwan/liwan.err"depend() {need netafter firewall}start_pre() {checkpath --directory --owner $command_user:$command_user --mode 0775 \/run/$RC_SVCNAME /var/log/$RC_SVCNAME}Replace
yourusernameand adjust the paths to match your setup. Make sure the script is executable:Terminal window chmod +x /etc/init.d/liwanTo generate an example configuration file, you can run
liwan generate-config -o ~/.config/liwan/liwan.config.toml. -
Starting the service
After creating the service script, add it to the default runlevel and start it:Terminal window # Add the service to the default runlevelrc-update add liwan default# Start the servicerc-service liwan start -
Checking the status
You can now check the status of the service usingrc-service liwan statusand view the logs usingtail -f /var/log/liwan/liwan.log. If this is the first time you are running Liwan, you can find a link to set up your account in the logs.