-
1Clone the repository
First, you'd need to clone this repository on the server where you'd like to install it. You can do so by using the following command:
git clone https://github.com/TheLastBilly/wol_control
-
2Set up a python virtual environment
Now that the repository is cloned, the next thing you'd like to do is to install
virtualenv
usingpip
. We're using a virtual environment for Wol Control to avoid conflicts with currently installed modules on your machine. You can skip this part if you want, but I don't recommend it.python3 -m pip install --user virtualenv
This will install
virtualenv
for your current user (no need for sudo).Next you'll have to create a python virtual environment and install all the necessary python dependencies on it. In order to do so, use the following commands:
Make sure to move to the repository's directory first.
python3 -m virtualenv ~/.wol_control_env
This command will create a virtual environment on your home directory (
~/
) namedwol_control_env
. The.
is used to make this a hidden folder so you wouldn't normally see it unless you actively look for it. Regardless, you can name it however you want.source ~/.wol_control_env/bin/activate python3 -m pip install -r requirements.txt
The first command will active your virtual environment and the second one will install all of the dependencies listed on the requirements.txt file.
-
3Set up Wol Control's databse and code
Now that all the necessary dependencies have been installed, you can now set-up Wol Control's database, create new users and add devices.
First things first, initialize a new database using the init_db.py script:
python3 init_db.py
Create a new user and add some devices using the manage_users.py and manage_devices.py scripts respectively:
python3 manage_users.py python3 manage_devices.py
And finally, go to the wol_control/main.py file and set the
remote_user
variable to the username that you'll use to shut down remote computers with over SSH (more on that later). -
4Set up Nginx
Wol Control uses
nginx
to handle remote requests from its clients. Assuming you already setupnginx
, you'll then have to create a settings file so Wol Control can be accessed by it.There's a file inluded in this repository, wol_control.nginx, which you can use as a template for that:
server { listen localhost:9090; location / { proxy_set_header Host $host:9090; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Host $server_name; proxy_pass http://unix:/home/sammy/wol_control/wol_control.sock:/; } }
Just replace the path in between
proxy_pass <a target="_blank" rel="noopener noreferrer" href="http://unix">http://unix</a>:
and/wol_control.sock:/
with the local path of this repository in your computer. Also, make sure to change the address thatnginx
will be listening to in thelisten
line at the beginning of the file fromlocalhost
to your machine's hostname/ip.Now you can copy the wol_control.nginx file into your nginx
/etc/nginx/sites-available/
folder and enable it.sudo cp ./wol_control.nginx /etc/nginx/sites-available/wol_control.nginx sudo ln -s /etc/nginx/sites-available/wol_control.nginx /etc/nginx/sites-enabled/wol_control.nginx
Finally, we can check our
nginx
configuration file with the following command:sudo nginx -t
And if everything is okay, restart
nginx
:sudo systemctl restart nginx
-
5Set up systemd
You'll have to setup a service file for Wol Control. There's already one provided with this repository wol_control.service, so you can use it as a template.
[Unit] Description=Gunicorn service of wol_control After=network.target [Service] User=sammy Group=www-data WorkingDirectory=/home/sammy/wol_control Environment="PATH=/home/sammy/.wol_control_env/bin:/usr/bin" ExecStart=/home/sammy/.wol_control_env/bin/gunicorn --workers 3 --access-logfile wol_control.log --bind unix:wol_control.sock -m 007 wsgi [Install] WantedBy=multi-user.target
This file assumes that you installed a virtual environment on
~/.wol_control_env
, so make sure you change that path with whatever directory you used on that step, or remove the use of a virtual environment from the file altogether. If you do remove any mentions of a virtual environment, your service file should end up looking like this:[Unit] Description=Gunicorn service of wol_control After=network.target [Service] User=sammy Group=www-data WorkingDirectory=/home/sammy/wol_control Environment="/usr/bin:/usr/local/bin" ExecStart=/usr/bin/python3 -m gunicorn --workers 3 --access-logfile wol_control.log --bind unix:wol_control.sock -m 007 wsgi [Install] WantedBy=multi-user.target
Just like with the
nginx
setup step, replace the path specified after theWorkingDirectory
variable with the path where you cloned this repository into. Also make sure to replace thesammy
user in theUser
variable with username of the user that has access to this repository.Then, copy the wol_control.service file to the
/etc/systemd/system
folder and reload thesystemd
daemon.sudo cp ./wol_control.service /etc/systemd/system/wol_control.service sudo systemctl daemon-reload
And finally, start the
wol_control
service and enable.sudo systemctl start wol_control sudo systemctl enable wol_control
-
6Access Wol Control From your browser
You should now be able to access Wol Control from your local network.
You can do so by accessing the following address from your browser:
http://[Your Server's Address]:9090
[Your Server's Address]
is the address that you used in thenginx
'slisten
line. -
7Extra step: Set up remote shut down
This is only supported on Unix based systems
Assuming the machine where Wol Control is running is Machine A and the one that you'd like to shut down remotely is Machine B, follow these steps:
First, create an user on Machine B with the same username that you used on the
remote_user
variable from the wol_control/main.py file back at the Wol Control setup step.Then, add the SSH key from the user running Wol Control on Machine A into the newly created user on Machine B:
If you don't have a SSH key set up on Machine A, you can do so by using the
ssh-keygen
command on it.On Machine A (Wol Control User)
ssh-copy-id [Machine B's user]@[Machine B's IP]
Make sure to log into Machine B from Machine A at least once, otherwise the
Turn Off
feature might not work. You can do that by using the following command:ssh [Machine B's user]@[Machine B's IP]
on Machine A.Lastly, create a folder named
.wol_control/
on Machine B's user's home directory and then create a file named ~/.wol_control/remote_shutdown.sh. Here you'll add the command that will shutdown Machine B whenever you click theTurn Off
button on Wol Control's interface. I personally just usepoweroff
but this may not work depending on your system:On Machine B
mkdir ~/.wol_control echo "poweroff" > ~/.wol_control/remote_shutdown.sh
Discussions
Become a Hackaday.io Member
Create an account to leave a comment. Already have an account? Log In.