Thursday, February 02, 2023

How to restart sidekiq automatically when Ubuntu is rebooted?

You can restart Sidekiq automatically after a reboot on Ubuntu by adding a Systemd service unit file. Here's how you can create the file:


1. Create a new file at /etc/systemd/system/sidekiq.service

2. Add the following contents to the file, replacing <user> with the username running Sidekiq and <path_to_sidekiq> with the path to the Sidekiq binary:



[Unit]

Description=Sidekiq


[Service]

Type=simple

User=<user>

WorkingDirectory=<path_to_sidekiq>

ExecStart=<path_to_sidekiq>/bin/sidekiq

Restart=always


[Install]

WantedBy=multi-user.target


3. Reload Systemd to pick up the new service file: sudo systemctl daemon-reload

4. Enable the Sidekiq service to start at boot: sudo systemctl enable sidekiq

5. Start the Sidekiq service: sudo systemctl start sidekiq


After these steps, Sidekiq should automatically restart after a reboot on your Ubuntu system.