Skip to main content

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:

  1. Open nano and create a new file called pocket.service

    sudo nano /etc/systemd/system/pocket.service
  2. 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.target
  3. Make sure the User is set to the user that will run the Pocket service.

  4. Make sure the ExecStart and ExecStop paths are set to the path for the Pocket binary.

  5. Save the file with Ctrl+O and then return.

  6. Exit nano with Ctrl+X.

  7. Reload the service files to include the pocket service.

    sudo systemctl daemon-reload
  8. Start the pocket service.

    sudo systemctl start pocket.service
  9. Verify the service is running.

    sudo systemctl status pocket.service
  10. Stop the pocket service.

    sudo systemctl stop pocket.service
  11. Verify the service is stopped.

    sudo systemctl status pocket.service
  12. Set the service to start on boot.

    sudo systemctl enable pocket.service
  13. Verify the service is set to start on boot.

    sudo systemctl list-unit-files --type=service
  14. 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