GithubHelp home page GithubHelp logo

Comments (17)

VBart avatar VBart commented on June 24, 2024 1

There are 3 methods supported at the moment: GET, PUT, DELETE. You can operate over the configuration root / as well as any sublayers, like /listeners, /listeners/IP:PORT, /listeners/IP:PORT/application, /applications, /applications/NAME, /applications/NAME/workers, etc...

from unit.

VBart avatar VBart commented on June 24, 2024 1

You can add an application and then a listener, thus with two requests. For now, there's only one way to add both a listener and an application with just one request: by uploading the full resulting configuration to the root /.

Support for the MERGE/PATCH methods in conformity with RFC 7396 is planned.

from unit.

VBart avatar VBart commented on June 24, 2024 1

I also can suggest a nice and very powerful utility for operating with JSON:

% cat conf.json                     
{
        "listeners": {
                "127.0.0.1:8081": {
                        "application": "test"
                }
        },

        "applications": {
                "test": {
                        "type": "python",
                        "module": "wsgi",
                        "path": "/home/vbart/Development/tests"
                }
        }
}
% <conf.json | jq .applications.test
{
  "type": "python",
  "module": "wsgi",
  "path": "/home/vbart/Development/tests"
}
% <conf.json | jq '.listeners[]' 
{
  "application": "test"
}

https://stedolan.github.io/jq/

from unit.

VBart avatar VBart commented on June 24, 2024 1

And you can merge JSON files with it:

% cat conf.json
{
        "listeners": {
                "127.0.0.1:8081": {
                        "application": "test"
                }
        },

        "applications": {
                "test": {
                        "type": "python",
                        "module": "wsgi",
                        "path": "/home/vbart/Development/tests"
                }
        }
}
% cat conf_t.json
{
     "listeners": {
         "*:8300": {
             "application": "php56domaincom"
         }
     },
     "applications": {
         "php56domaincom": {
             "type": "php",
              "workers": 10,
              "root": "/home/nginx/domains/domain.com/public",
              "user": "vbart",
              "group": "users",
              "index": "index.php"
         }
     }
}
% jq -s '.[0] * .[1]' conf.json conf_t.json
{
  "listeners": {
    "127.0.0.1:8081": {
      "application": "test"
    },
    "*:8300": {
      "application": "php56domaincom"
    }
  },
  "applications": {
    "test": {
      "type": "python",
      "module": "wsgi",
      "path": "/home/vbart/Development/tests"
    },
    "php56domaincom": {
      "type": "php",
      "workers": 10,
      "root": "/home/nginx/domains/domain.com/public",
      "user": "vbart",
      "group": "users",
      "index": "index.php"
    }
  }
}

from unit.

VBart avatar VBart commented on June 24, 2024 1

Yes, you have to define it in URI: /listeners/*:8300

from unit.

VBart avatar VBart commented on June 24, 2024 1

Merging with jq also works fine:

% jq -s '.[0] * .[1]' conf.json conf_t.json | curl -X PUT -d@-  http://127.0.0.1:8443
{
        "success": "Reconfiguration done."
}
% curl http://127.0.0.1:8443
{
        "listeners": {
                "127.0.0.1:8081": {
                        "application": "test"
                },

                "*:8300": {
                        "application": "php56domaincom"
                }
        },

        "applications": {
                "test": {
                        "type": "python",
                        "module": "wsgi",
                        "path": "/home/vbart/Development/tests"
                },

                "php56domaincom": {
                        "type": "php",
                        "workers": 10,
                        "root": "/home/nginx/domains/domain.com/public",
                        "user": "vbart",
                        "group": "users",
                        "index": "index.php"
                }
        }
}

from unit.

VBart avatar VBart commented on June 24, 2024 1

That error comes from nginx, not unit. =)

Note, that I used curl command without unix socket, because I run my Unit with control socket set to 127.0.0.1:8443.

from unit.

VBart avatar VBart commented on June 24, 2024 1

If you have the modules collection that you mentioned in #47, then php 7.1.9 is missing.

from unit.

VBart avatar VBart commented on June 24, 2024

This state directory isn't a configuration storage. It was introduced just for runtime configuration persistence in order to allow Unit to survive server reloads without additional tricks. It's up to you where to store and how to manage your configurations.

from unit.

centminmod avatar centminmod commented on June 24, 2024

i see but even if i do not restart unitd service, i can only list the last added php720start.json configuration ? the previous 3 configs are gone ?

curl --unix-socket /opt/unit/control.unit.sock http://localhost/                                                     
{
        "listeners": {
                "*:8600": {
                        "application": "php72domaincom"
                }
        },

        "applications": {
                "php72domaincom": {
                        "type": "php 7.2.0",
                        "workers": 20,
                        "root": "/home/nginx/domains/domain.com/public",
                        "user": "nginx",
                        "group": "nginx",
                        "index": "index.php"
                }
        }
}

unitd.log

2017/09/24 01:04:42 [info] 18356#18356 discovery started
2017/09/24 01:04:42 [notice] 18356#18356 module: php 5.6.31 "/opt/unit/modules/php5631.unit.so"
2017/09/24 01:04:42 [notice] 18356#18356 module: python 2.7.5 "/opt/unit/modules/python.unit.so"
2017/09/24 01:04:42 [notice] 18356#18356 module: php 5.6.31 "/opt/unit/modules/remiphp5631.unit.so"
2017/09/24 01:04:42 [notice] 18356#18356 ignoring /opt/unit/modules/remiphp5631.unit.so module with the same application language version php 5.6.31 as in /opt/unit/modules/php5631.unit.so
2017/09/24 01:04:42 [notice] 18356#18356 module: php 7.0.24RC1 "/opt/unit/modules/remiphp7023.unit.so"
2017/09/24 01:04:42 [notice] 18356#18356 module: php 7.1.10RC1 "/opt/unit/modules/remiphp719.unit.so"
2017/09/24 01:04:42 [notice] 18356#18356 module: php 7.2.0RC2 "/opt/unit/modules/remiphp720.unit.so"
2017/09/24 01:04:42 [info] 18357#18357 controller started
2017/09/24 01:04:42 [info] 18358#18358 router started
2017/09/24 01:04:42 [crit] 18358#18358 epoll_ctl(3, 3, 9) failed (2: No such file or directory)
2017/09/24 01:04:42 [crit] 18357#18357 epoll_ctl(3, 3, 9) failed (2: No such file or directory)
2017/09/24 01:04:42 [notice] 18355#18355 process 18356 exited with code 0

from unit.

VBart avatar VBart commented on June 24, 2024

They are gone not because of the reload. When you do PUT command to the root of the configuration / it's replaced by the provided object. The PUT has create or replace semantic.

from unit.

centminmod avatar centminmod commented on June 24, 2024

hmm the docs at isn't exactly clear on this http://unit.nginx.org/docs-configuration.html#creating-configuration-objects we have to separately add the listener and applications from separate json files ?

from unit.

centminmod avatar centminmod commented on June 24, 2024

cheers but don't we need to define the actual listener *:8300 too ?

cat /root/tools/unitconfigs/php5631start.json 
{
     "listeners": {
         "*:8300": {
             "application": "php56domaincom"
         }
     },
     "applications": {
         "php56domaincom": {
             "type": "php 5.6.31",
              "workers": 20,
              "root": "/home/nginx/domains/domain.com/public",
              "user": "nginx",
              "group": "nginx",
              "index": "index.php"
         }
     }
}

if contents of /root/tools/unitconfigs/php5631start-app.json is

cat /root/tools/unitconfigs/php5631start.json | jq .applications.php56domaincom
{
  "type": "php 5.6.31",
  "workers": 20,
  "root": "/home/nginx/domains/domain.com/public",
  "user": "nginx",
  "group": "nginx",
  "index": "index.php"
}

for

curl -X PUT -d @/root/tools/unitconfigs/php5631start-app.json --unix-socket /opt/unit/control.unit.sock http://localhost/applications/php56domaincom

and for /root/tools/unitconfigs/php5631start-listener.json contents would be

cat /root/tools/unitconfigs/php5631start.json | jq '.listeners[]'
{
  "application": "php56domaincom"
}

for

curl -X PUT -d @/root/tools/unitconfigs/php5631start-listener.json --unix-socket /opt/unit/control.unit.sock http://localhost/listeners

??

from unit.

centminmod avatar centminmod commented on June 24, 2024

cheers so

curl -X PUT -d @/root/tools/unitconfigs/php5631start-listener.json --unix-socket /opt/unit/control.unit.sock http://localhost/listeners/*:8300

lots to digest.. thanks

Hope this info makes it into official documentation manual too :)

from unit.

centminmod avatar centminmod commented on June 24, 2024

@VBart thanks merging seems easier to do as I can script it to read all .json files within a config directory for merging :)

jq -s '.[0] * .[1] * .[2] * .[3] * .[4]' php5631start.json php7024start.json php719start.json php720start.json php7110start.json 
{
  "listeners": {
    "*:8300": {
      "application": "php56domaincom"
    },
    "*:8400": {
      "application": "php71domaincom"
    },
    "*:8600": {
      "application": "php72domaincom"
    },
    "*:8500": {
      "application": "php71domaincom"
    }
  },
  "applications": {
    "php56domaincom": {
      "type": "php 7.1.9",
      "workers": 20,
      "root": "/home/nginx/domains/domain.com/public",
      "user": "nginx",
      "group": "nginx",
      "index": "index.php"
    },
    "php70domaincom": {
      "type": "php 7.0.24",
      "workers": 20,
      "root": "/home/nginx/domains/domain.com/public",
      "user": "nginx",
      "group": "nginx",
      "index": "index.php"
    },
    "php72domaincom": {
      "type": "php 7.2.0",
      "workers": 20,
      "root": "/home/nginx/domains/domain.com/public",
      "user": "nginx",
      "group": "nginx",
      "index": "index.php"
    },
    "php71domaincom": {
      "type": "php 7.1.10",
      "workers": 20,
      "root": "/home/nginx/domains/domain.com/public",
      "user": "nginx",
      "group": "nginx",
      "index": "index.php"
    }
  }
}

though getting 405 not allowed error

 jq -s '.[0] * .[1] * .[2] * .[3] * .[4]' php5631start.json php7024start.json php719start.json php720start.json php7110start.json  | curl -X PUT -d@-  http://localhost
<html>
<head><title>405 Not Allowed</title></head>
<body bgcolor="white">
<center><h1>405 Not Allowed</h1></center>
<hr><center>nginx</center>
</body>
</html>

from unit.

centminmod avatar centminmod commented on June 24, 2024

thanks for the hint added the control socket back

jq -s '.[0] * .[1] * .[2] * .[3] * .[4]' php5631start.json php7024start.json php719start.json php720start.json php7110start.json | curl -X PUT -d@- --unix-socket /opt/unit/control.unit.sock http://localhost/ 
{
        "error": "Invalid configuration."
}
jq -s '.[0] * .[1] * .[2] * .[3] * .[4]' php5631start.json php7024start.json php719start.json php720start.json php7110start.json
{
  "listeners": {
    "*:8300": {
      "application": "php56domaincom"
    },
    "*:8400": {
      "application": "php71domaincom"
    },
    "*:8600": {
      "application": "php72domaincom"
    },
    "*:8500": {
      "application": "php71domaincom"
    }
  },
  "applications": {
    "php56domaincom": {
      "type": "php 7.1.9",
      "workers": 20,
      "root": "/home/nginx/domains/domain.com/public",
      "user": "nginx",
      "group": "nginx",
      "index": "index.php"
    },
    "php70domaincom": {
      "type": "php 7.0.24",
      "workers": 20,
      "root": "/home/nginx/domains/domain.com/public",
      "user": "nginx",
      "group": "nginx",
      "index": "index.php"
    },
    "php72domaincom": {
      "type": "php 7.2.0",
      "workers": 20,
      "root": "/home/nginx/domains/domain.com/public",
      "user": "nginx",
      "group": "nginx",
      "index": "index.php"
    },
    "php71domaincom": {
      "type": "php 7.1.10",
      "workers": 20,
      "root": "/home/nginx/domains/domain.com/public",
      "user": "nginx",
      "group": "nginx",
      "index": "index.php"
    }
  }
}

from unit.

centminmod avatar centminmod commented on June 24, 2024

ah ha thanks @VBart needed that second set of eyes :)

jq -s '.[0] * .[1] * .[2] * .[3]' php5631start.json php7024start.json php720start.json php7110start.json  | curl -X PUT -d@- --unix-socket /opt/unit/control.unit.sock http://localhost
{
        "success": "Reconfiguration done."
}
curl --unix-socket /opt/unit/control.unit.sock http://localhost/
{
        "listeners": {
                "*:8300": {
                        "application": "php56domaincom"
                },

                "*:8400": {
                        "application": "php70domaincom"
                },

                "*:8600": {
                        "application": "php72domaincom"
                },

                "*:8500": {
                        "application": "php71domaincom"
                }
        },

        "applications": {
                "php56domaincom": {
                        "type": "php 5.6.31",
                        "workers": 20,
                        "root": "/home/nginx/domains/domain.com/public",
                        "user": "nginx",
                        "group": "nginx",
                        "index": "index.php"
                },

                "php70domaincom": {
                        "type": "php 7.0.24",
                        "workers": 20,
                        "root": "/home/nginx/domains/domain.com/public",
                        "user": "nginx",
                        "group": "nginx",
                        "index": "index.php"
                },

                "php72domaincom": {
                        "type": "php 7.2.0",
                        "workers": 20,
                        "root": "/home/nginx/domains/domain.com/public",
                        "user": "nginx",
                        "group": "nginx",
                        "index": "index.php"
                },

                "php71domaincom": {
                        "type": "php 7.1.10",
                        "workers": 20,
                        "root": "/home/nginx/domains/domain.com/public",
                        "user": "nginx",
                        "group": "nginx",
                        "index": "index.php"
                }
        }
}

from unit.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.