Thanks for your reply @rimelek
I show more information here so that we can understand each other.
Let’s do an experiment, first we get an ubuntu 20.04 image and bring up.
More specifically, we need to add some capabilities, e.g: –cap-add CAP_SYS_ADMIN --cap-add CAP_CHOWN
[on container side]
Inside the container, we create a new cgroup’s group, named ‘bar’:
mkdir bar && mount -t cgroup -o none,name=bar bar bar/
Then we create a new sub-group named ‘foo’:
mkdir bar/foo
Now, its directory structure will look like this:
bar
|-- cgroup.clone_children
|-- cgroup.procs
|-- cgroup.sane_behavior
|-- foo
| |-- cgroup.clone_children
| |-- cgroup.procs
| |-- notify_on_release
| `-- tasks
|-- notify_on_release
|-- release_agent
`-- tasks
Then we create an executable script inside the container, the full name is: ‘/tmp/hello.sh’:
cat << EOF > /tmp/hello.sh
#!/bin/bash
touch /tmp/on___container
exit 0
EOF
We add permissions to it to make sure it can be executed:
chmod a+x /tmp/hello.sh
After that, we write the full name of the script to the ‘bar/release_agent’ node.
For example:
echo "/tmp/hello.sh" > bar/release_agent
To trigger it, we enable 'bar/foo/notify_on_release’, which is set to 1:
echo 1 > bar/foo/notify_on_release
Finally, the trigger script is as follows:
sh -c "echo \$\$ > bar/foo/tasks"
I found that the ‘/tmp/on___container’ file is NOT generated inside the container.
Let’s try another experiment on the host.
[on host side]
I make a new script with the same name: /tmp/hello.sh on the host.
cat << EOF > /tmp/hello.sh
#!/bin/bash
touch /tmp/on___host
exit 0
EOF
caution: in this script, when it is called, a file on___host will be generated (NOT on___container)
Likewise, we add exceutable permissions to this script.
chmod a+x /tmp/hello.sh
We go back to the container and try to trigger release_agent again.
[on container side]
sh -c "echo \$\$ > bar/foo/tasks"
In the container environment, the ‘/tmp/on___host’ file is NOT generated, which is to be expected.
[on host side]
But, we can get the file ‘/tmp/on___host’ in the host.
It turns out that the file ‘/tmp/on___host’ has been generated in the host environment.
[QUESTION]
Can we really not use the release_agent node in a container and ONLY in the container environment NOT host environment?
Thanks.