5-2: Configure systemd
For production use, using tmux
to run Pocket is not recommended. A better option in production is to setup a Linux service using a service manager such as systemd.
Creating a systemd service in Linux
To setup a systemd service for Pocket, do the following:
Open nano and create a new file called
pocket.service
sudo nano /etc/systemd/system/pocket.service
Add the following lines to the file:
[Unit]
Description=Pocket service
After=network.target
Wants=network-online.target systemd-networkd-wait-online.service
StartLimitIntervalSec=500
StartLimitBurst=5
[Service]
Restart=on-failure
RestartSec=5s
User=pocket
ExecStart=/home/pocket/go/bin/pocket start
ExecStop=/home/pocket/go/bin/pocket stop
[Install]
WantedBy=default.targetMake sure the
User
is set to the user that will run the Pocket service.Make sure the
ExecStart
andExecStop
paths are set to the path for the Pocket binary.Save the file with Ctrl+O and then return.
Exit nano with Ctrl+X.
Reload the service files to include the pocket service.
sudo systemctl daemon-reload
Start the pocket service.
sudo systemctl start pocket.service
Verify the service is running.
sudo systemctl status pocket.service
Stop the pocket service.
sudo systemctl stop pocket.service
Verify the service is stopped.
sudo systemctl status pocket.service
Set the service to start on boot.
sudo systemctl enable pocket.service
Verify the service is set to start on boot.
sudo systemctl list-unit-files --type=service
Start the pocket service.
sudo systemctl start pocket.service
Other systemctl commands
To restart the service:
sudo systemctl restart pocket.service
To prevent the service from starting on boot:
sudo systemctl disable pocket.service
To see mounted volumes:
sudo systemctl list-units --type=mount
Note: If your pocket data is on a separate partition, you can use the following command to in the
pocket.service
file to mount it before the pocket service starts.After=network.target mnt-data.mount
This ensures that the network is up and the volume is mounted before the pocket service starts.
Viewing the logs
To view the logs for the pocket service, do the following:
sudo journalctl -u pocket.service
To view just the last 100 lines of the logs (equiv. tail -f), do the following:
sudo journalctl -u pocket.service -n 100 --no-pager
Finding Errors
There are a few ways to find errors in the logs.
sudo journalctl -u pocket.service | grep -i error