Autostart Configuration
This article describes how to configure an application to start automatically at boot on the Rhino Pi IQ9N Ubuntu system.
Method Comparison
| Method | Use Case | Characteristics |
|---|---|---|
| systemd service | Background services, long-running programs | Supports automatic restart and log management; the recommended approach |
| crontab | Simple scripts | Simple to configure, but not suitable for long-running services |
| rc.local | One-shot startup scripts | Must be created manually and given executable permissions |
Using systemd (Recommended)
- Create the service file:
bash
sudo nano /etc/systemd/system/myapp.service- Write the following content:
ini
[Unit]
Description=My Application
After=network.target
[Service]
Type=simple
User=aidlux
WorkingDirectory=/home/aidlux/myapp
ExecStart=/home/aidlux/myapp/run.sh
Restart=on-failure
RestartSec=5
[Install]
WantedBy=multi-user.target- Reload the configuration and enable the service:
bash
sudo systemctl daemon-reload
sudo systemctl enable myapp.service
sudo systemctl start myapp.service- Check the service status and logs:
bash
sudo systemctl status myapp.service
journalctl -u myapp.service -fUsing crontab
The cron service is enabled by default on the IQ9N. Edit the current user's scheduled tasks:
bash
crontab -eAdd a task to the file, for example to run a script once at boot:
text
@reboot /home/aidlux/myapp/run.shView the currently configured tasks:
bash
crontab -lcrontab is suitable for running simple scripts or scheduled tasks; long-running services should still use the systemd approach.
Using rc.local
The system already includes rc-local.service. This service is of type static, so systemctl enable is neither needed nor possible; when /etc/rc.local exists and has executable permissions, systemd runs it automatically at boot.
- Create
/etc/rc.local:
bash
sudo nano /etc/rc.local- Write the following content:
bash
#!/bin/sh
/home/aidlux/myapp/run.sh &
exit 0- Give it executable permissions:
bash
sudo chmod +x /etc/rc.local- Reboot for the configuration to take effect. You can also verify without rebooting:
bash
sudo systemctl start rc-local
sudo systemctl status rc-localFAQ
- The service did not start: use
journalctl -u <service name>to check the failure reason. - The script has no executable permission: run
chmod +x <script path>. - Wrong path:
ExecStartmust use an absolute path. - rc.local does not take effect: confirm that
/etc/rc.localexists and has executable permissions (ls -l /etc/rc.local), then reboot the system after granting permissions.