Fading Coder

One Final Commit for the Last Sprint

Home > Tech > Content

Configuring Automatic Startup for Applications on Kylin OS

Tech 1

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:

  1. Copy an existing .desktop file as a template:
    sudo cp /etc/xdg/autostart/bluetooth.desktop /etc/xdg/autostart/myapp.desktop
    
  2. Edit the file with a text editor:
    sudo nano /etc/xdg/autostart/myapp.desktop
    
  3. Modify the Exec= line to point to your startup script:
    Exec=/home/user/applications/startup_script.sh
    
  4. 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 .desktop files are readable.
  • Path Issues: Verify all paths in scripts and .desktop files are absolute and correct.
  • Service Not Starting: Check systemd logs with sudo journalctl -u your-service-name.
  • Desktop Entry Not Working: Ensure the .desktop file is in the correct autostart directory and has proper syntax.

Best Practices

  1. Use absolute paths in all configuration files
  2. Test scripts manually before configuring autostart
  3. Keep startup scripts simple and focused on initialization
  4. Document environment requirements in startup scripts
  5. Consider using systemd for daemon processes and desktop entries for GUI applications

Related Articles

Understanding Strong and Weak References in Java

Strong References Strong reference are the most prevalent type of object referencing in Java. When an object has a strong reference pointing to it, the garbage collector will not reclaim its memory. F...

Comprehensive Guide to SSTI Explained with Payload Bypass Techniques

Introduction Server-Side Template Injection (SSTI) is a vulnerability in web applications where user input is improper handled within the template engine and executed on the server. This exploit can r...

Implement Image Upload Functionality for Django Integrated TinyMCE Editor

Django’s Admin panel is highly user-friendly, and pairing it with TinyMCE, an effective rich text editor, simplifies content management significantly. Combining the two is particular useful for bloggi...

Leave a Comment

Anonymous

◎Feel free to join the discussion and share your thoughts.