Skipole WSGI generator.
The instructions here describe how Pound and Waitress can be used to serve your application whenever your debian-based server is powered up.
They assume you have no other web server running (so port 80 and port 8000 is free), and you are familiar with shell commands, changing directories, creating text files and setting permissions. You should also have used skipole to create an application.
In this example Pound proxies calls to the Waitress web server which is running your wsgi python application. The settings here use default values provided by the operating system to keep the setup simple.
Install the packages 'pound' and 'python3-waitress'
apt-get install pound
apt-get install python3-waitress
Assuming your project is called 'myproj'.
Copy the projectfiles directory into /opt, creating directory:
/opt/projectfiles/
Ensure skilift, skiadmin and the development server are removed and myproj.py is edited with the following:
from waitress import serve serve(application, host='127.0.0.1', port=8000)
Give the directory and contents www-data:www-data ownership
sudo chown -R www-data:www-data /opt/projectfiles
Then create a file :
/lib/systemd/system/myproj.service
containing the following:
[Unit] Description=My project description After=multi-user.target [Service] Type=idle ExecStart=/usr/bin/python3 /opt/projectfiles/myproj.py User=www-data Restart=on-failure # Connects standard output to /dev/null StandardOutput=null # Connects standard error to journal StandardError=journal [Install] WantedBy=multi-user.target
Then set permissions of the file
sudo chown root:root /lib/systemd/system/myproj.service
sudo chmod 644 /lib/systemd/system/myproj.service
Enable the service
sudo systemctl daemon-reload
sudo systemctl enable myproj.service
This starts /opt/projectfiles/myproj.py on boot up.
edit the pound cfg file at /etc/pound/pound.cfg to read:
## Minimal sample pound.cfg ## ## see pound(8) for details ###################################################################### ## global options: User "www-data" Group "www-data" #RootJail "/chroot/pound" ## Logging: (goes to syslog by default) ## 0 no logging ## 1 normal ## 2 extended ## 3 Apache-style (common log format) LogLevel 1 ## check backend every X secs: Alive 30 ## use hardware-accelleration card supported by openssl(1): #SSLEngine "" # poundctl control socket Control "/var/run/pound/poundctl.socket" ###################################################################### ## listen, redirect and ... to: ## redirect all requests on port 8080 ("ListenHTTP") to the local webserver (see "Service" below): ListenHTTP Address 192.168.122.3 Port 80 ## allow PUT and DELETE also (by default only GET, POST and HEAD)?: xHTTP 1 Service BackEnd Address 127.0.0.1 Port 8000 End End End
The changes from default are - listen is port 80, backend is port 8000 and ip address is whatever is required (in my test case it was 192.168.122.3)
Enable pound to start by editing /etc/default/pound
and setting
startup=1
Finally reboot - note: as pound may start before the project, give the server a minute before testing.
The configuration is given here as a basis which could be expanded - to multiple backend services in a load balancing application perhaps.