From 00154ef899a6894292d66de5388eb1ea0cc0ce61 Mon Sep 17 00:00:00 2001 From: Disassembler Date: Tue, 18 Sep 2018 16:27:42 +0200 Subject: [PATCH] Implement lxc-build HALT and fix some minor regressions --- crisiscleanup/lxcfile | 1 + crisiscleanup/setup.sh | 3 +-- frontlinesms/lxcfile | 1 + openmapkit/lxc/etc/services.d/.s6-svscan/finish | 3 +++ openmapkit/lxc/etc/services.d/openmapkit/run | 6 ++++++ openmapkit/lxcfile | 7 +++---- pandora/lxcfile | 1 - zz-extra/lxc-build | 14 ++++++++++++-- 8 files changed, 27 insertions(+), 9 deletions(-) create mode 100755 openmapkit/lxc/etc/services.d/.s6-svscan/finish create mode 100755 openmapkit/lxc/etc/services.d/openmapkit/run diff --git a/crisiscleanup/lxcfile b/crisiscleanup/lxcfile index 5a821c9..dd10ef2 100644 --- a/crisiscleanup/lxcfile +++ b/crisiscleanup/lxcfile @@ -56,3 +56,4 @@ MOUNT DIR /srv/crisiscleanup/conf srv/crisiscleanup/config USER 8005 8005 WORKDIR /srv/crisiscleanup CMD rails server +HALT SIGTERM diff --git a/crisiscleanup/setup.sh b/crisiscleanup/setup.sh index 9fb529e..82aaf18 100755 --- a/crisiscleanup/setup.sh +++ b/crisiscleanup/setup.sh @@ -26,10 +26,9 @@ cp ${SOURCE_DIR}/srv/crisiscleanup/conf/environments/production.rb /srv/crisiscl vmmgr update-login crisiscleanup "${CRISISCLEANUP_ADMIN_EMAIL}" "${CRISISCLEANUP_ADMIN_PWD}" # Populate database -envsubst <${SOURCE_DIR}/srv/crisiscleanup/db/seeds.rb >/var/lib/lxc/crisiscleanup/crisiscleanup/tmp/seeds.rb +envsubst <${SOURCE_DIR}/srv/crisiscleanup/db/seeds.rb >/var/lib/lxc/crisiscleanup/crisiscleanup/srv/crisiscleanup/db/seeds.rb lxc-execute crisiscleanup -- rake db:schema:load lxc-execute crisiscleanup -- rake db:seed -rm /var/lib/lxc/crisiscleanup/crisiscleanup/tmp/seeds.rb # Install service cp ${SOURCE_DIR}/etc/init.d/crisiscleanup /etc/init.d/crisiscleanup diff --git a/frontlinesms/lxcfile b/frontlinesms/lxcfile index 5b572f1..3517aba 100644 --- a/frontlinesms/lxcfile +++ b/frontlinesms/lxcfile @@ -10,6 +10,7 @@ RUN EOF # Create OS user addgroup -S -g 8018 sms adduser -S -u 8018 -h /srv/frontlinesms -s /bin/sh -g sms -G sms sms + adduser sms dialout # Install FrontlineSMS wget http://download-frontlinesms.s3.amazonaws.com/frontlinesms2_unix_2.6.5.sh -O /tmp/frontlinesms2.sh diff --git a/openmapkit/lxc/etc/services.d/.s6-svscan/finish b/openmapkit/lxc/etc/services.d/.s6-svscan/finish new file mode 100755 index 0000000..78d5fdc --- /dev/null +++ b/openmapkit/lxc/etc/services.d/.s6-svscan/finish @@ -0,0 +1,3 @@ +#!/bin/sh + +/bin/true diff --git a/openmapkit/lxc/etc/services.d/openmapkit/run b/openmapkit/lxc/etc/services.d/openmapkit/run new file mode 100755 index 0000000..091fcc2 --- /dev/null +++ b/openmapkit/lxc/etc/services.d/openmapkit/run @@ -0,0 +1,6 @@ +#!/bin/execlineb -P + +fdmove -c 2 1 +export NODE_ENV production +s6-setuidgid 8007:8007 +/usr/bin/node /srv/openmapkit/server.js diff --git a/openmapkit/lxcfile b/openmapkit/lxcfile index 724181b..4751ddb 100644 --- a/openmapkit/lxcfile +++ b/openmapkit/lxcfile @@ -36,10 +36,9 @@ RUN EOF rm -rf /root/.cache /root/.config /root/.node-gyp /root/.npm EOF +COPY lxc + MOUNT FILE /srv/openmapkit/conf/settings.js srv/openmapkit/settings.js MOUNT DIR /srv/openmapkit/data srv/openmapkit/data -USER 8007 8007 -ENV NODE_ENV production -WORKDIR /srv/openmapkit -CMD node server.js +CMD s6-svscan /etc/services.d diff --git a/pandora/lxcfile b/pandora/lxcfile index c74ceb9..585227b 100644 --- a/pandora/lxcfile +++ b/pandora/lxcfile @@ -93,5 +93,4 @@ EOF MOUNT DIR /srv/pandora/conf srv/pandora/conf MOUNT DIR /srv/pandora/data srv/pandora/data -WORKDIR /srv/pandora CMD s6-svscan /etc/services.d diff --git a/zz-extra/lxc-build b/zz-extra/lxc-build index 4953786..acbe979 100755 --- a/zz-extra/lxc-build +++ b/zz-extra/lxc-build @@ -34,7 +34,7 @@ lxc.environment = PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/ {env} # Halt -lxc.signal.halt = SIGTERM +lxc.signal.halt = {halt} # Log lxc.console.size = 1MB @@ -59,6 +59,7 @@ class LXCImage: self.gid = 0 self.cmd = '/bin/true' self.cwd = '/' + self.halt = 'SIGINT' if os.path.isfile(build_path): self.lxcfile = os.path.realpath(build_path) @@ -106,6 +107,8 @@ class LXCImage: self.set_cmd(' '.join(line.split()[1:])) elif line.startswith('WORKDIR'): self.set_cwd(line.split()[1]) + elif line.startswith('HALT'): + self.set_halt(line.split()[1]) # Add the final layer which can be treated as ephemeral self.add_layer('{}/delta0'.format(self.name)) @@ -118,7 +121,10 @@ class LXCImage: mounts = '\n'.join(self.mounts) env = '\n'.join(self.env) with open(os.path.join(LXC_ROOT, self.name, 'config'), 'w') as fd: - fd.write(CONFIG_TEMPLATE.format(name=self.name, rootfs=rootfs, mounts=mounts, env=env, uid=self.uid, gid=self.gid, cmd=self.cmd, cwd=self.cwd)) + fd.write(CONFIG_TEMPLATE.format(name=self.name, + rootfs=rootfs, mounts=mounts, env=env, + uid=self.uid, gid=self.gid, + cmd=self.cmd, cwd=self.cwd, halt=self.halt)) def run_script(self, script): sh = os.path.join(self.layers[-1], 'run.sh') @@ -167,6 +173,10 @@ class LXCImage: self.cwd = cwd self.rebuild_config() + def set_halt(self, cwd): + self.halt = halt + self.rebuild_config() + def copy_tree(src, dst): if not os.path.isdir(src): shutil.copy2(src, dst)