donaldzou / WGDashboard

Simple dashboard for WireGuard VPN written in Python & Vue.js
https://donaldzou.github.io/WGDashboard-Documentation/
Apache License 2.0
1.61k stars 242 forks source link

failed to start after following auto start instrucions #162

Open MehrabD123 opened 2 years ago

MehrabD123 commented 2 years ago

after following the steps to enable on startup start for wg-dashboard, i get this error when doing sudo systemctl start wg-dashboard.service

OS Information:

image

donaldzou commented 2 years ago

Hi, could you post your wg-dashboard.service file so I can have a look?

MehrabD123 commented 2 years ago

image here is the file

donaldzou commented 2 years ago

Yeah my bad, i did not fix this issue... Here is a working copy of it that i have in v2.3:

[Unit]
After=netword.service

[Service]
WorkingDirectory=<your dashboard directory full path here>
ExecStart=/usr/bin/python3 <your dashboard directory full path here>dashboard.py
Restart=always

[Install]
WantedBy=default.target

Make sure you remove everything in wg-dashboard.service, paste the stuff above, and you follow this instruction:


In the src folder, it contained a file called wg-dashboard.service, we can use this file to let our system to autostart the dashboard after reboot. The following guide has tested on Ubuntu, most Debian based OS might be the same, but some might not. Please don't hesitate to provide your system if you have tested the autostart on another system.

  1. Changing the directory to the dashboard's directory

    cd wireguard-dashboard/src
  2. Get the full path of the dashboard's directory

    pwd
    #Output: /root/wireguard-dashboard/src

    For this example, the output is /root/wireguard-dashboard/src, your path might be different since it depends on where you downloaded the dashboard in the first place. Copy the the output to somewhere, we will need this in the next step.

  3. Edit the service file, the service file is located in wireguard-dashboard/src, you can use other editor you like, here will be using nano

    nano wg-dashboard.service

    You will see something like this:

    [Unit]
    After=netword.service
    
    [Service]
    WorkingDirectory=<your dashboard directory full path here>
    ExecStart=/usr/bin/python3 <your dashboard directory full path here>/dashboard.py
    Restart=always
    
    [Install]
    WantedBy=default.target

    Now, we need to replace both <your dashboard directory full path here> to the one you just copied from step 2. After doing this, the file will become something like this, your file might be different:

    [Unit]
    After=netword.service
    
    [Service]
    WorkingDirectory=/root/wireguard-dashboard/src
    ExecStart=/usr/bin/python3 /root/wireguard-dashboard/src/dashboard.py
    Restart=always
    
    [Install]
    WantedBy=default.target

    Be aware that after the value of WorkingDirectory, it does not have a / (slash). And then save the file after you edited it

  4. Copy the service file to systemd folder

    $ cp wg-dashboard.service /etc/systemd/system/wg-dashboard.service

    To make sure you copy the file successfully, you can use this command cat /etc/systemd/system/wg-dashboard.service to see if it will output the file you just edited.

  5. Enable the service

    $ sudo chmod 664 /etc/systemd/system/wg-dashboard.service
    $ sudo systemctl daemon-reload
    $ sudo systemctl enable wg-dashboard.service
    $ sudo systemctl start wg-dashboard.service  # <-- To start the service
  6. Check if the service run correctly

    $ sudo systemctl status wg-dashboard.service

    And you should see something like this

    ● wg-dashboard.service
        Loaded: loaded (/etc/systemd/system/wg-dashboard.service; enabled; vendor preset: enabled)
        Active: active (running) since Tue 2021-08-03 22:31:26 UTC; 4s ago
      Main PID: 6602 (python3)
         Tasks: 1 (limit: 453)
        Memory: 26.1M
        CGroup: /system.slice/wg-dashboard.service
                └─6602 /usr/bin/python3 /root/wireguard-dashboard/src/dashboard.py
    
    Aug 03 22:31:26 ubuntu-wg systemd[1]: Started wg-dashboard.service.
    Aug 03 22:31:27 ubuntu-wg python3[6602]:  * Serving Flask app "Wireguard Dashboard" (lazy loading)
    Aug 03 22:31:27 ubuntu-wg python3[6602]:  * Environment: production
    Aug 03 22:31:27 ubuntu-wg python3[6602]:    WARNING: This is a development server. Do not use it in a production deployment.
    Aug 03 22:31:27 ubuntu-wg python3[6602]:    Use a production WSGI server instead.
    Aug 03 22:31:27 ubuntu-wg python3[6602]:  * Debug mode: off
    Aug 03 22:31:27 ubuntu-wg python3[6602]:  * Running on all addresses.
    Aug 03 22:31:27 ubuntu-wg python3[6602]:    WARNING: This is a development server. Do not use it in a production deployment.
    Aug 03 22:31:27 ubuntu-wg python3[6602]:  * Running on http://0.0.0.0:10086/ (Press CTRL+C to quit)

    If you see Active: followed by active (running) since... then it means it run correctly.

  7. Stop/Start/Restart the service

    sudo systemctl stop wg-dashboard.service      # <-- To stop the service
    sudo systemctl start wg-dashboard.service     # <-- To start the service
    sudo systemctl restart wg-dashboard.service   # <-- To restart the service
  8. And now you can reboot your system, and use the command at step 6 to see if it will auto start after the reboot, or just simply access the dashboard through your browser. If you have any questions or problem, please report it in the issue page.

Let me know how it goes ;)

MehrabD123 commented 2 years ago

this worked perfectly! thank you so much for the help i really appreciate it

MehrabD123 commented 2 years ago

i may have spoke too soon, this is the error i got on system reboot image any ideas as to what the issue is?

MehrabD123 commented 2 years ago

it works when i run sudo systemctl start wg-dashboard.service i am just unsure why it did not start on reboot

adrinux commented 2 years ago

it works when i run sudo systemctl start wg-dashboard.service i am just unsure why it did not start on reboot

@MehrabD123 You'll also need to do sudo systemctl enable wg-dashboard.service to have it auto start on reboot.

MehrabD123 commented 2 years ago

i had already enabled it when following the instructions, but i still get the same issue i posted above

adrinux commented 2 years ago

@MehrabD123 The actual error isn't given in that screen shot try journalctl -xeu wg-dashboard.service, you should be able to scroll back far enough to see a real error.

donaldzou commented 2 years ago

It might because you did not reload the file, try systemctl daemon-reload

donaldzou commented 2 years ago

also could try which python3 on your pi? It should tell you where python installed, it might different from the example I provided above.

DaanSelen commented 6 days ago

@MehrabD123 is this still relevant?