In this short tutorial, we will go through the process of configuring Ubuntu server to automatically start a command like bpytop at boot time.
bpytopIf you haven’t already installed bpytop, you can do so using the following commands:
sudo apt update
sudo apt install bpytop
bpytop is a system resource monitor and it can be installed easily using package manager or pip.
To run bpytop (or any other command) at boot, you can create a systemd service. Systemd is the system and service manager for Linux that initializes the system components after booting.
Create a new service file:
Use a text editor like nano to create a new service file:
sudo nano /etc/systemd/system/bpytop.service
Add the following configuration:
Paste the following content into the file. This tells systemd how to start bpytop and ensures it runs as a service:
[Unit]
Description=Run bpytop on boot
After=network.target
[Service]
Type=simple
ExecStart=/usr/bin/bpytop
User=your-username
WorkingDirectory=/home/your-username
[Install]
WantedBy=multi-user.target
Replace your-username with your actual username on the server. The ExecStart line points to the bpytop executable. If you’ve installed it in a custom location, adjust the path accordingly.
After creating the service file, you need to reload systemd so it recognizes the new service. Then, enable the service to start on boot.
Reload systemd:
sudo systemctl daemon-reload
Enable the service to start on boot:
sudo systemctl enable bpytop.service
This command creates a symbolic link in the system’s service directory, which tells systemd to start the service at boot.
Start the service immediately (optional):
If you want to start bpytop right away without rebooting, use:
sudo systemctl start bpytop.service
You can check the status of your service to ensure it’s running correctly:
sudo systemctl status bpytop.service
This command should display the current status of the bpytop service. If it’s running properly, you should see an “Active (running)” status.
Finally, reboot your server to ensure that the command starts automatically on boot:
sudo reboot
After the reboot, you can verify that bpytop is running by checking the status again:
sudo systemctl status bpytop.service
If the service isn’t running as expected, you can check the systemd logs for more detailed error messages:
journalctl -xe
This command will show you logs that might indicate why the service failed to start.
To remove the bpytop service you created, follow these steps:
Stop the Service:
If the service is currently running, stop it first:
sudo systemctl stop bpytop.service
Disable the Service:
Disable it to prevent it from starting on boot:
sudo systemctl disable bpytop.service
Remove the Service File:
Delete the service file:
sudo rm /etc/systemd/system/bpytop.service
Reload Systemd:
Reload the systemd daemon to apply the changes:
sudo systemctl daemon-reload
Verify Removal:
Check to make sure the service has been removed by listing available services:
systemctl list-units --type=service | grep bpytop
You should not see bpytop listed anymore.