Skip to main content

Systemd Services

For production use, running pocket in a tmux session isn't recommended. A better option to use a service manager like systemd to run and manage the pocket service.

In this section, we'll create a systemd service for pocket.

Creating a systemd service

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 Network Service
    After=network.target
    StartLimitIntervalSec=500
    StartLimitBurst=5

    [Service]
    Restart=on-failure
    RestartSec=5s
    User=pocket
    ExecStart=/usr/local/go/bin/pocket start
    ExecStop=/usr/local/go/bin/pocket stop

    [Install]
    WantedBy=multi-user.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. Stop the pocket process if it is currently running.

    pocket stop
  9. Start the pocket service.

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

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

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

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

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

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

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

Troubleshooting

If you're the pocket.service doesn't start, the most likely cause is that the path to the pocket binary is not correct or the User is not set to the correct user.

To verify the path to the pocket binary, you can run pocket in tmux and then do the following:

  1. Get the pocket process id.
    top -b -n 1 | grep pocket
  2. Get the path to the pocket binary.
    readlink /proc/<pid>/exe

    replace <pid> with the process id

Resources