blob: bda36bd221f4064424aaa98ca5ec21eaa321f244 (
plain)
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
|
#!/bin/sh /etc/rc.common
. "${IPKG_INSTROOT}"/lib/functions.sh
START=99
STOP=00
run_command() {
local command="$1"
$command
}
start_container() {
local cfg="$1"
local name
config_get name "$cfg" name
config_list_foreach "$cfg" command run_command
if [ -n "$name" ]; then
/usr/bin/lxc-start -n "$name"
fi
}
max_timeout=0
stop_container() {
local cfg="$1"
local name timeout
config_get name "$cfg" name
config_get timeout "$cfg" timeout 300
if [ "$max_timeout" -lt "$timeout" ]; then
max_timeout=$timeout
fi
if [ -n "$name" ]; then
[ "$timeout" = "0" ] && postargs=" -t $max_timeout"
/usr/bin/lxc-stop -n "$name" "$postargs" &
export STOPPID=$!
fi
}
start() {
config_load lxc-auto
local wait_dnsmasq
local dnsmasq_timeout
config_get_bool wait_dnsmasq global wait_dnsmasq 0
config_get dnsmasq_timeout global dnsmasq_timeout 30
if [ "$wait_dnsmasq" -eq 1 ]; then
local count=0
while [ $count -lt $dnsmasq_timeout ]; do
local dnsmasq_running=$(ubus call service list '{"name":"dnsmasq"}' 2>/dev/null | jsonfilter -e '@.dnsmasq.instances.*.running')
if [ "$dnsmasq_running" = "true" ]; then
logger -t lxc-auto "dnsmasq service confirmed running via procd"
break
fi
sleep 1
count=$((count + 1))
done
if [ $count -ge $dnsmasq_timeout ]; then
logger -t lxc-auto "WARNING: dnsmasq not running after ${dnsmasq_timeout}s, starting containers anyway"
fi
fi
config_load lxc-auto
config_foreach start_container container
}
stop() {
config_load lxc-auto
config_foreach stop_container container
# ensure e.g. shutdown doesn't occur before maximum timeout on
# containers that are shutting down
if [ $max_timeout -gt 0 ]; then
for i in $(seq 1 $max_timeout); do
if [ -d /proc/"$STOPPID" ]; then
sleep 1s
else
return 0
fi
done
fi
}
#Export systemd cgroups
boot() {
if [ ! -d /sys/fs/cgroup/systemd ]; then
mkdir -p /sys/fs/cgroup/systemd
mount -t cgroup -o rw,nosuid,nodev,noexec,relatime,none,name=systemd cgroup /sys/fs/cgroup/systemd
fi
start
}
|