uWSGI

For some web servers to deliver the application, you need to install and start a service. This service allows the server to communicate with the Flask app over a socket.

The devices-skeleton and backend already provide the necessary uWSGI initialization file to start the service. On the devices, it is located in the top level directory of the source, called muscle_device.ini. The backend initialization file can also be found in the top level directory, called muscle.ini.

Configuration of the Service

The initialization files gets called by GNU/Linux systemd service. Create a service file that contains the needed configuration. An excerpt of a configuration is given below.

sudo vim /etc/systemd/system/<NAME>.service
[Unit]
Description=uWSGI instance <DESCRIPTION>
After=network.target

[Service]
User=<USER>
Group=www-data
WorkingDirectory=<PATH_TO_MUSCLE_ BACKEND | DEVICE _SOURCE>
Environment="PATH=<PATH_TO_SOURCE_VIRTUAL_ENVIRONMENT>/bin"
ExecStart=<PATH_TO_VENV>/bin/uwsgi --ini <INI_FILE>

[Install]
WantedBy=multi-user.target

An example using above excerpt for a device installed on a raspberry pi may look like shown below.

cat << EOF >  /etc/systemd/system/muscle_device.service
[Unit]
Description=uWSGI instance to serve the MUSCLE device RPC API
After=network.target

[Service]
User=pi
Group=www-data
WorkingDirectory=/home/pi/muscle
Environment="PATH=/home/pi/muscle/venv/bin"
ExecStart=/home/pi/muscle/venv/bin/uwsgi --ini muscle_device.ini

[Install]
WantedBy=multi-user.target
EOF

Registration of the Service

  • Start the service

    sudo systemctl start muscle_device.service
    
  • Enable the service

    sudo systemctl enable muscle_device.service
    
  • Check the status

    sudo systemctl status muscle_device.service
    

Background Threads

Note

If the implementation of the current device uses threads, adapt the configuration file muscle_device.ini. The configuration excerpt shows how to activate multi-threading capabilities.

enable-threads = true