Unit: How to apply changes to wsgi.py ?

Created on 8 Sep 2017  路  15Comments  路  Source: nginx/unit

Pushing the json doesn't seem to work:-

sudo curl -X PUT -d @hello.json --unix-socket /var/run/control.unit.sock http://localhost/
{
    "success": "Reconfiguration done."
}

But it still reading the old file. So I have to restart unitd but then it cause issue #16.

enhancement

Most helpful comment

@andyvanee Yes, for now that's one of the best workarounds. Usually I recommend something like this:
curl -X PUT -d "{\"gen\":\"$RANDOM\"}" --unix-socket /var/run/control.unit.sock /config/applications/<name>/environment

The interface for controlling application processes is planned for Q1/2019. Then the restarting processes command will be straightforward:
curl --unix-socket /var/run/control.unit.sock /control/applications/<name>/restart

Edit: Sorry, Q1 is passed. Q3/2019 is more realistic now (upd: moved to Q1/2020)

All 15 comments

The interface for reloading applications is planned.
Currently, an application can be reloaded by changing its name.

More specifically, in order to ensure smooth transition to the new application version, you can you the following workflow:

  1. Create new application with a different name, same settings.
  2. Assign the application to a new listener/port.
  3. Test that it's working, by connecting to the new port, or assigning a portion of traffic to this new port.
  4. Change the value of /listeners/<id>/application object in the API to the name of new application, using PUT request. Now traffic will be served by the new application.
  5. Remove old application using DELETE request to the API.
  6. Remove unused listeners, if needed.

How to apply changes to wsgi.py?
It's very critical. Delete and create the applet incorrectly
Reload is required for python.

+1. It's very important feature.

+1

Hello,

Any info about this issue ? I can confirm it still exists with the latest version of unit - 1.4. Changes to the application are not applied unless it is reconfigured as a new application within unit, or deleted and sent to the unit configuration with the same settings again.

I've had the same issue, and worked around it by adding the current timestamp as an environment variable in my application. Although it seems hacky, I haven't had any issues with it so far. If the environment changes, the application is forced to reload in order to pick up the change.

curl -X PUT -d '{"APPVERSION":"'$(date +"%s")'"}' --unix-socket /var/run/control.unit.sock http://localhost/config/applications/myapp/environment

The upside to this is there is no need to update your application name or port.

@andyvanee Yes, for now that's one of the best workarounds. Usually I recommend something like this:
curl -X PUT -d "{\"gen\":\"$RANDOM\"}" --unix-socket /var/run/control.unit.sock /config/applications/<name>/environment

The interface for controlling application processes is planned for Q1/2019. Then the restarting processes command will be straightforward:
curl --unix-socket /var/run/control.unit.sock /control/applications/<name>/restart

Edit: Sorry, Q1 is passed. Q3/2019 is more realistic now (upd: moved to Q1/2020)

Ubuntu 18.04, I use systemctl restart unit and it looks fine

@xiangnanscu I think the point is to be able to restart a single service - if you have many services running, you don't want to restart all of them just to reload a single one.

You can kill the PIDs for now. Until this is resolved it may be best to generate a script that kills multiple PIDs related to a service when the service is initiated (per process).

I've had the same issue, and worked around it by adding the current timestamp as an environment variable in my application. Although it seems hacky, I haven't had any issues with it so far. If the environment changes, the application is forced to reload in order to pick up the change.

curl -X PUT -d '{"APPVERSION":"'$(date +"%s")'"}' --unix-socket /var/run/control.unit.sock http://localhost/config/applications/myapp/environment

The upside to this is there is no need to update your application name or port.

Info for those noobs as me - in json file it would be:

"environment": {
            "APPVERSION": "$(date + %s)"
               }

I've had the same issue, and worked around it by adding the current timestamp as an environment variable in my application. Although it seems hacky, I haven't had any issues with it so far. If the environment changes, the application is forced to reload in order to pick up the change.
curl -X PUT -d '{"APPVERSION":"'$(date +"%s")'"}' --unix-socket /var/run/control.unit.sock http://localhost/config/applications/myapp/environment
The upside to this is there is no need to update your application name or port.

Info for those noobs as me - in json file it would be:

"environment": {
          "APPVERSION": "$(date + %s)"
               }

It's a shell expression that substitutes current timestamp:

$ echo '{"APPVERSION":"'$(date +"%s")'"}'
{"APPVERSION":"1572958385"}

Issue still there.
Workaround also still works. Ansible template example:

    "applications": {
        "flask_app": {
            ...
            "environment": {
                "version": "{{ '%Y-%m-%d_%H:%M:%S' | strftime }}"
            }
        }
    }

Thanks to everyone suggesting their workarounds! Here's the doc piece: https://unit.nginx.org/configuration/#configuration-management

Was this page helpful?
0 / 5 - 0 ratings

Related issues

sandeep048 picture sandeep048  路  5Comments

lolgab picture lolgab  路  3Comments

ElDarco picture ElDarco  路  4Comments

xiongxin picture xiongxin  路  5Comments

R4z0R7 picture R4z0R7  路  3Comments