Skip to content
How to Autostart Using Systemctl

Example How-To enable FileBrowser to autostart using systemctl

You need to create a systemd service unit file. Since you’ve already configured the binary with filebrowser config set, we just need to tell systemd how to run it, who should run it, and when.

Here is the step-by-step process:

  1. Create the Service Unit File

    Open a terminal and create a new service file. You usually place this in /etc/systemd/system/ for system-wide services (requires sudo) or ~/.config/systemd/user/ for a user-only service.

    For a system-wide service (recommended if you want it available to all):

    sudo nano /etc/systemd/system/filebrowser.service

    For a user-only service:

    mkdir -p ~/.config/systemd/user
    nano ~/.config/systemd/user/filebrowser.service
  2. Add the Configuration Content

    Paste the following content into the file. You must adjust a few paths based on your setup:

    • User: Replace your_username with the user account that should run FileBrowser.
    • ExecStart: Ensure the path /path/to/filebrowser points to where your actual binary is located. If you installed it via a package manager, it might be /usr/bin/filebrowser.
    • WorkingDirectory: This is important. Even though you used filebrowser config set, the .db and configuration files are often resolved relative to the directory where the command runs. It’s best to set this to the directory where your filebrowser.db lives, or wherever you want the default behavior to apply.
    [Unit]
    Description=File Browser Service
    After=network.target
    
    [Service]
    # Change 'your_username' to the actual user running the service
    User=your_username
    Group=your_groupname
    
    # The path to your filebrowser binary
    ExecStart=/path/to/filebrowser
    
    # Optional: Add arguments if needed, though config set usually handles the main flags
    # Example: --port 8080
    
    # Set the working directory (where the db/config is likely located)
    WorkingDirectory=/opt/filebrowser
    
    # Restart policy
    Restart=always
    RestartSec=5
    
    # Environment variables if needed
    Environment="HOME=/home/your_username"
    
    [Install]
    WantedBy=multi-user.target

Note: If you use a user-level service (in ~/.config/systemd/user/), change WantedBy=multi-user.target to WantedBy=default.target. 3. Reload Systemd and Enable the Service

Once the file is saved, reload the systemd daemon to recognize the new file and then enable/start the service.

System-wide:

sudo systemctl daemon-reload sudo systemctl enable filebrowser.service sudo systemctl start filebrowser.service

User-level (no sudo):

systemctl –user daemon-reload systemctl –user enable filebrowser.service systemctl –user start filebrowser.service

Note: To ensure user services start at boot even without login, you may need “linger” enabled:

sudo loginctl enable-linger your_username

  1. Verify Status

Check if the service is running correctly:

sudo systemctl status filebrowser.service

OR for user service

systemctl –user status filebrowser.service

If there are errors, check the logs:

sudo journalctl -u filebrowser.service -f