Skipole WSGI generator.

Topics:

Introduction Getting Started Your Code skiadmin start_call submit_data end_call Exceptions PageData SectionData skicall Serving wsgi Code Examples

Development at GitHub:

github.com/bernie-skipole/skipole

Simple serving for a Raspberry Pi

Serving your application

skipole is used to create a project which results in a wsgi application. Once you have produced such an application you will want to serve it via a web server. The instructions here describe how the Python web server 'Waitress' can be used to serve your application whenever your Pi is powered up.

These instructions assume you have no other web server running (so port 80 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 (best start with something simple!).

This method uses Waitress running as root. Operating as root is not secure enough for Internet connection, but for a simple control project it may be suitable.

Waitress is not available in the Python standard library, you need to install it first:

apt-get install python3-waitress

As always skipole must be installed:

pip install skipole

Assuming your project is called 'myproj'.

Copy the projectfiles directory into /opt, creating directory:

/opt/projectfiles/

Ensure skilift and the skiadmin application are removed and myproj.py is edited with the following:


    from waitress import serve
    serve(application, host='0.0.0.0', port=80)

(So 'application' is served on all interfaces with port 80)

Give the directory and contents root ownership

sudo chown -R root:root /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

    WorkingDirectory=/opt/projectfiles
    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.

Useful functions to test the service:

sudo systemctl start myproj

sudo systemctl stop myproj

sudo systemctl restart myproj

sudo systemctl status myproj

sudo systemctl disable myproj

Display last lines of the journal

sudo journalctl -n

Display and continuously print the latest journal entries

sudo journalctl -f

The myproj web service is running in the background, with all logging output going to /dev/null.