lxc-start
936 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#!/bin/sh
function lxc-start()
{
local LXC_START=/usr/bin/lxc-start
local TEST=/usr/bin/test
local ECHO=/bin/echo
local MKDIR=/bin/mkdir
local CHOWN=/bin/chown
local SUDO=/usr/bin/sudo
local TEE=/usr/bin/tee
(
PID=$(exec /bin/sh -c 'echo $PPID')
for ctrl in /sys/fs/cgroup/*
do
${TEST} ${ctrl##*/} = 'openrc' && continue
if ${TEST} ! -d ${ctrl}/${USER}
then
${TEST} ${ctrl##*/} = 'cpuset' && \
${ECHO} 1 | ${SUDO} ${TEE} ${ctrl}/cgroup.clone_children >/dev/null
${TEST} ${ctrl##*/} = 'memory' && \
${ECHO} 1 | ${SUDO} ${TEE} ${ctrl}/memory.use_hierarchy >/dev/null
${SUDO} ${MKDIR} ${ctrl}/${USER}/
${SUDO} ${CHOWN} ${USER}: ${ctrl}/${USER}
${SUDO} ${CHOWN} ${USER}: ${ctrl}/${USER}/tasks
${SUDO} ${CHOWN} ${USER}: ${ctrl}/${USER}/cgroup.procs
fi
${ECHO} ${PID} >>"${ctrl}/${USER}/tasks"
done
${LXC_START} $@
)
}
export -f lxc-start
# vim: set ft=sh ts=4 sw=4: