unit
unit copied to clipboard
PUT should create parent objects in config when they don't exist
Imagine I have an empty configuration like:
curl --unix-socket /usr/local/var/run/unit/control.sock localhost/config
{}
I now want to add an application like:
curl -X PUT -d '{
"type": "external",
"executable":"/path/to/my/binary"
}' --unix-socket /usr/local/var/run/unit/control.sock localhost/config/applications/app
But what I get is:
{
"error": "Value doesn't exist."
}
Because there is no applications
container.
If I create the applications container it works fine:
curl -X PUT -d '{
"app": {
"type": "external",
"executable":"/path/to/my/binary"
}
}' --unix-socket /usr/local/var/run/unit/control.sock localhost/config/applications
{
"success": "Reconfiguration done."
}
The problem is that I don't want to mess with other applications that could be currently installed in Unit, I just want to add a new one.
What I propose as a different behavior is to add an empty container when you try to PUT
a setting that doesn't have already a parent.
So when the current config is {}
, running:
curl -X PUT -d '{
"type": "external",
"executable":"/path/to/my/binary"
}' --unix-socket /usr/local/var/run/unit/control.sock localhost/config/applications/app
would result in the following config:
{
"applications": {
"app": {
"type": "external",
"executable":"/path/to/my/binary"
}
}
Thanks for sharing your use case!
This behaviour is consistent for all "top level" objects. The workaround is to create an empty "applications": {}
object when "value does not exist". Then child objects can be created by name on the URI.