Skip to main content
systemd is an init system and service manager for Linux. It manages the startup and control of system processes and services.
To run a Bun application as a daemon with systemd, create a service file in /lib/systemd/system/.
terminal

Here is a typical service file that runs an application on system start. Use it as a template for your own service. Replace YOUR_USER with the name of the user to run the application as. To run as root, replace YOUR_USER with root, though this is not recommended for security reasons. Refer to the systemd documentation for details on each setting.
my-app.service

If your application starts a webserver, non-root users cannot listen on ports 80 or 443 by default. To permanently allow Bun to listen on these ports when run by a non-root user, use the following command. This step isn’t necessary when running as root.
terminal

With the service file configured, enable the service. Once enabled, it starts automatically on reboot. This requires sudo permissions.
terminal

To start the service without rebooting, start it manually.
terminal

Check the status of your application with systemctl status. If the app started successfully, the output looks like this:
terminal

To update the service, edit the service file, then reload the daemon.
terminal

For a complete guide to service unit configuration, see the systemd.service documentation. Or use this cheatsheet of common commands:
terminal