2.7 Auto-Start on Boot
This guide explains how to make your program start automatically when the system boots. We’ll use a systemd user service, which applies to Bianbu system.
Step 1: Prepare Your Program for Auto Start
Before setting up auto-start, confirm your program runs correctly from the command line. Examples:
-
Python script:
python demo.py
-
Bash script:
bash executable_file
-
Node.js project:
npm run start
Step 2: Create the systemd Service File
In your working directory, create a new file named demo.service
with the following content:
[Unit]
Description=Demo Service
[Service]
Type=simple
WorkingDirectory=/path/to/your/workspace
ExecStart=/bin/bash -c 'exec /path/to/your/workspace/executable_file'
Restart=on-failure
StandardOutput=journal
StandardError=journal
Environment=SYSTEMD_LOG_LEVEL=debug
Environment=PYTHONPATH=/if/you/need
[Install]
WantedBy=default.target
Note:
WorkingDirectory
: Enter the path to your working directory.ExecStart
: Enter your startup command or the path to your executable file.- To add environment variables, just add more
Environment=
lines.
Step 3: Install the service file
Copy the demo.service
file to the ~/.config/systemd/user/
or /usr/lib/systemd/user/
directory
(the former is recommended, as user-level services do not require root permissions).
mkdir -p ~/.config/systemd/user
cp demo.service ~/.config/systemd/user/
Step 4: Enable and Start the Service
-
Enable the service to start automatically at boot:
systemctl --user enable demo.service
-
Start the service:
systemctl --user start demo.service
-
Check the service status:
systemctl --user status demo.service
A running
status indicates that the service is currently active:
Step 5: Verify Auto Start at Boot
Reboot your system, then run:
systemctl --user status demo.service
If configured correctly, it will be active automatically.
Common Issues
-
If you encounter permission issues, make sure your user has a systemd user instance enabled.
-
Logs can be viewed using:
journalctl --user -u demo.service
-
If the service does not start automatically, check the service file path, permissions, and whether the
ExecStart
command is correct.