9-BoNUS
admin
Red Panda .Service

To create a production-like systemctl service for running your binary with the required environment variable, follow these steps:


1. Move the Binary to a System Path

Move your redpanda-console binary to a system directory, such as /usr/local/bin:

sudo mv ./redpanda-console /usr/local/bin/
sudo chmod +x /usr/local/bin/redpanda-console

2. Create a Systemd Service File

Create a new service file for redpanda-console. Use your preferred editor, e.g., nano or vim:

sudo nano /etc/systemd/system/redpanda-console.service

Add the following content to the file:

[Unit]
Description=Redpanda Console Service
After=network.target
 
[Service]
Environment="KAFKA_BROKERS=kafka.x.com:9092"
ExecStart=/usr/local/bin/redpanda-console
Restart=always
User=redpanda
Group=redpanda
WorkingDirectory=/usr/local/bin
 
[Install]
WantedBy=multi-user.target

Explanation of Key Fields:

  • Environment: Sets the environment variable KAFKA_BROKERS.
  • ExecStart: The command to run the binary.
  • Restart: Ensures the service restarts automatically if it fails.
  • User and Group: Use a specific user for security (redpanda in this case). Create this user if it doesn’t exist.
  • WorkingDirectory: Sets the working directory.

3. Create a User for the Service

For security, create a dedicated redpanda user:

sudo useradd -r -s /bin/false redpanda
sudo chown redpanda:redpanda /usr/local/bin/redpanda-console

4. Reload Systemd and Start the Service

Reload systemd to recognize the new service file, then enable and start the service:

sudo systemctl daemon-reload
sudo systemctl enable redpanda-console
sudo systemctl start redpanda-console

5. Check Service Status

Verify that the service is running correctly:

sudo systemctl status redpanda-console

If everything is configured correctly, you should see the service active and running.


6. Logs and Troubleshooting

To view logs for the service, use:

journalctl -u redpanda-console -f

This setup ensures redpanda-console runs in a production-like environment, managed by systemctl. Let me know if you encounter any issues!


💬 Need a Quick Summary?

Hey! Don't have time to read everything? I get it. 😊
Click below and I'll give you the main points and what matters most on this page.
Takes about 5 seconds • Uses Perplexity AI