---
tags:
  - "#Linux/Service"
parents: "[[Linux Wflow]]"
date/time: 2024-10-15T22:07:00
---

# Make Appimage run on startup

To run an AppImage on startup in a Linux environment, you can create a systemd service. Here are the steps:

1. **Make the AppImage executable**:
   ```bash
   chmod +x /path/to/your/appimage
   ```

2. **Create a systemd service file**:
   ```bash
   sudo nano /etc/systemd/system/yourapp.service
   ```

3. **Add the following content to the service file**:
   ```ini
   [Unit]
   Description=Your AppImage Service
   After=network.target

   [Service]
   ExecStart=/path/to/your/appimage
   Restart=always
   User=yourusername

   [Install]
   WantedBy=default.target
   ```

4. **Reload systemd to recognize the new service**:
   ```bash
   sudo systemctl daemon-reload
   ```

5. **Enable the service to start on boot**:
   ```bash
   sudo systemctl enable yourapp.service
   ```

6. **Start the service immediately**:
   ```bash
   sudo systemctl start yourapp.service
   ```

Replace `/path/to/your/appimage` with the actual path to your AppImage and `yourusername` with your actual username.```

# General approach


```

[Unit]
Description=Your App Service
After=network.target

[Service]
ExecStart=/path/to/your/executable
ExecStop=/path/to/stop/command
ExecReload=/path/to/reload/command
Restart=on-failure
User=yourusername
WorkingDirectory=/path/to/working/directory
Environment="VAR_NAME=value"
Type=simple

[Install]
WantedBy=multi-user.target

```

where:


#### Unit Section

- **Description**: A short description of the service. This is displayed in systemd logs and status messages.
    
    Description=Your App Service
    
- **After**: Specifies the order in which units are started. In this case, the service will start after the `network.target` is reached, ensuring that network services are available.
    
    After=network.target
    

#### Service Section

- **ExecStart**: The command that starts the service. This should be the full path to the executable or script you want to run.
    
    ExecStart=/path/to/your/executable
    
- **Restart**: Defines the restart behavior of the service. Common values include:
    
    - `no`: Do not restart the service.
    - `always`: Always restart the service if it stops.
    - `on-failure`: Restart the service only if it exits with a non-zero status.
    
    Restart=always
    
- **User**: Specifies the user under which the service should run. This is useful for running services with non-root privileges.
    
    User=yourusername
    
- **WorkingDirectory**: (Optional) Sets the working directory for the service. If not specified, the service will use the root directory (`/`).
    
    WorkingDirectory=/path/to/working/directory
    
- **Environment**: (Optional) Sets environment variables for the service.
    
    Environment="VAR_NAME=value"
    

#### Install Section

- **WantedBy**: Specifies the target that the service should be started under. Common targets include:
    
    - `multi-user.target`: A multi-user, non-graphical system (common for servers).
    - `graphical.target`: A graphical system with a display manager (common for desktops).
    
    WantedBy=multi-user.target
    

### Additional Directives

- **ExecStop**: Command to run when stopping the service.
    
    ExecStop=/path/to/stop/command
    
- **ExecReload**: Command to run when reloading the service configuration.
    
    ExecReload=/path/to/reload/command
    
- **Type**: Specifies the process start-up type. Common values include:
    
    - `simple`: The service is considered started immediately after the `ExecStart` command is executed.
    - `forking`: The service is considered started after the process forks and the parent process exits.
    - `oneshot`: The service is considered started after the `ExecStart` command exits.
    - `notify`: The service will send a notification message via `sd_notify` when it has finished starting up.
    
    Type=simple
    



# References

Github Copilot

https://linuxhandbook.com/create-systemd-services/

