-
Notifications
You must be signed in to change notification settings - Fork 8
/
runX
executable file
·148 lines (137 loc) · 2.7 KB
/
runX
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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
#!/bin/bash
workpath=/usr/share/runX
rundir=/run/runX
guestconsole=""
cmd=""
root=""
bundle=""
pidfile=""
containerid=""
while (( "$#" ))
do
if [[ $1 = "--root" ]]
then
root=$2
shift
shift
continue
fi
if [[ $1 = "--bundle" ]]
then
bundle=$2
shift
shift
continue
fi
if [[ $1 = "--pid-file" ]]
then
pidfile=$2
shift
shift
continue
fi
if [[ $1 = "--console-socket" ]]
then
guestconsole="$2"
shift
shift
continue
fi
if [[ $1 = "--no-pivot" ]]
then
shift
continue
fi
if [[ $1 = "--"* ]]
then
shift
shift
continue
fi
if test -z "$cmd"
then
cmd=$1
shift
continue
fi
containerid=$1
break
done
if ! test "$containerid"
then
echo "no containerid given, exiting"
exit 1
fi
crundir="$rundir"/"$containerid"
if test "$cmd" = "create"
then
rm -rf "$crundir"
fi
if test ! -d "$crundir"
then
mkdir -p "$crundir"
fi
if test \( "$bundle" \) -a \( ! -f "$crundir"/bundle \)
then
echo -n "$bundle" > "$crundir"/bundle
if test -f "$bundle"/config.json
then
rootfs="$( jq -r -c '.["root"]["path"]' "$bundle"/config.json )"
if [[ "$rootfs" != /* ]]
then
rootfs="$bundle"/"$rootfs"
fi
echo -n "$rootfs" > "$crundir"/rootfs
else
echo "can't determine rootfs, erring out"
exit 1
fi
fi
if test \( "$pidfile" \) -a \( ! -f "$crundir"/pidfile \)
then
echo -n "$pidfile" > "$crundir"/pidfile
fi
if test $cmd = "state"
then
$workpath/state $containerid "$crundir"
elif test $cmd = "start"
then
$workpath/start $containerid
elif test $cmd = "pause"
then
$workpath/pause $containerid pause
elif test $cmd = "resume"
then
$workpath/pause $containerid resume
elif test $cmd = "kill"
then
$workpath/delete $containerid
$workpath/mount $containerid "$crundir" unmount
elif test $cmd = "create"
then
$workpath/mount $containerid "$crundir" mount
$workpath/create $containerid "$crundir"
if test "$guestconsole"
then
daemonize $workpath/serial_start \
"$containerid" \
"$crundir"/console_pty
for n in 10 9 8 7 6 5 4 3 2 1; do
if [ ! -L "$crundir"/console_pty ]; then
sleep .1
else
break
fi;
done
daemonize $workpath/sendfd \
"$guestconsole" \
"$crundir"/console_pty
else
echo "connect to container console with 'xl console $containerid'"
fi
elif test $cmd = "delete"
then
rm -rf "$crundir"
else
:
fi