Configuring Automatic Startup for Applications on Kylin OS
Using systemd for Service Management
Systemd service files are stored in /etc/systemd/system/. Below is an example configuration for a Qt-based application:
[Unit]
Description=Qt Application Service
After=network.target
[Service]
Type=simple
Environment="PATH=/opt/java/jdk1.8.0_401/bin:/opt/java/jdk1.8.0_401/jre/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin"
User=root
Group=root
ExecStart=/opt/applications/display/api/launch_service.sh start
Restart=on-failure
[Install]
WantedBy=multi-user.target
To enable the service:
sudo systemctl daemon-reload
sudo systemctl enable your-service-name.service
sudo systemctl start your-service-name.service
Creating Desktop Autostart Entries
For graphical applications, create .desktop files in autostart directories. The primary location is /etc/xdg/autostart/ for system-wide configuration.
Example .desktop file:
[Desktop Entry]
Type=Application
Exec=/home/user/applications/launch_robot_detector.sh
Hidden=false
NoDisplay=false
X-GNOME-Autostart-enabled=true
Name=Robot Detection
Comment=Qt application for robot detection
To configure:
- Copy an existing
.desktopfile as a template:sudo cp /etc/xdg/autostart/bluetooth.desktop /etc/xdg/autostart/myapp.desktop - Edit the file with a text editor:
sudo nano /etc/xdg/autostart/myapp.desktop - Modify the
Exec=line to point to your startup script:Exec=/home/user/applications/startup_script.sh - Ensure your startup script has execute permissions:
sudo chmod +x /home/user/applications/startup_script.sh
User-Specific Autostart Configuration
For user-specific autostart, use ~/.config/autostart/. Create the directory if it doesn't exist:
mkdir -p ~/.config/autostart/
Copy your .desktop file to this location:
cp /path/to/your/application.desktop ~/.config/autostart/
chmod +x ~/.config/autostart/application.desktop
Verify the file is present:
ls -l ~/.config/autostart/
Startup Script Preparation
Create a startup script that sets necessary environment variables and launches your application:
#!/bin/bash
# Set library path
export LD_LIBRARY_PATH=/home/user/apps/project/bin:$LD_LIBRARY_PATH
# Launch application
/home/user/apps/project/bin/ApplicationMain
Make the script executable:
chmod +x /home/user/apps/project/bin/startup_script.sh
Troubleshooting Common Issues
- Permission Denied Errors: Ensure scripts have execute permissions (
chmod +x) and.desktopfiles are readable. - Path Issues: Verify all paths in scripts and
.desktopfiles are absolute and correct. - Service Not Starting: Check systemd logs with
sudo journalctl -u your-service-name. - Desktop Entry Not Working: Ensure the
.desktopfile is in the correct autostart directory and has proper syntax.
Best Practices
- Use absolute paths in all configuration files
- Test scripts manually before configuring autostart
- Keep startup scripts simple and focused on initialization
- Document environment requirements in startup scripts
- Consider using systemd for daemon processes and desktop entries for GUI applications