Implement lxc-build HALT and fix some minor regressions

This commit is contained in:
Disassembler 2018-09-18 16:27:42 +02:00
parent fc99f7f6ab
commit 00154ef899
No known key found for this signature in database
GPG Key ID: 524BD33A0EE29499
8 changed files with 27 additions and 9 deletions

View File

@ -56,3 +56,4 @@ MOUNT DIR /srv/crisiscleanup/conf srv/crisiscleanup/config
USER 8005 8005
WORKDIR /srv/crisiscleanup
CMD rails server
HALT SIGTERM

View File

@ -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

View File

@ -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

View File

@ -0,0 +1,3 @@
#!/bin/sh
/bin/true

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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)