Permalink
Switch branches/tags
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
192 lines (160 sloc) 9.2 KB
#cloud-config
hostname: aerofs
coreos:
units:
- name: docker.service
command: start
drop-ins:
- name: 50-extra-options.conf
content: |
[Service]
Environment='DOCKER_OPTS=--userland-proxy=false'
- name: getty-restart.path
command: start
content: |
[Unit]
Description=Getty Restart path
[Path]
PathExists=/etc/systemd/system/getty@tty1.service.d/50-ship.conf
- name: getty-restart.service
content: |
[Unit]
Description=Restart Getty
[Service]
ExecStart=/ship/getty/restart
- name: swap.service
command: start
content: |
[Unit]
Description=Enable Swap
[Service]
ExecStart=/ship/enable-swap
- name: ship.service
command: start
content: |
[Unit]
Description=Ship Enterprise
After=docker.service
[Service]
ExecStart=/ship/sail
- name: httpd.service
content: |
[Unit]
Description=Bash httpd
[Service]
WorkingDirectory=/ship/httpd
ExecStart=/usr/bin/ncat --keep-open -lp 80 -e /ship/httpd/httpd.sh
oem:
id: ship-enterprise
name: Ship Enterprise
version-id: 0.1.1
home-url: http://www.aerofs.com/
bug-report-url: http://support.aerofs.com/
update:
reboot-strategy: off
write_files:
- path: /ship/getty/restart
permissions: 0700
content: |
#!/bin/bash -ex
if [ -f /ship/getty/restarted ]; then exit 0; fi
systemctl daemon-reload
systemctl restart getty@tty1
touch /ship/getty/restarted
- path: /etc/systemd/system/getty@tty1.service.d/50-ship.conf
content: |
[Service]
ExecStart=
ExecStart=-/sbin/agetty --noclear --skip-login --autologin root --login-program /ship/getty/run %I $TERM
- path: /ship/getty/run
permissions: 0700
content: |
#!/bin/bash -e
dmesg -n 1
echo 'Loading console service...'
[[ -f /ship/loader/run/tag ]] || { echo; echo 'Waiting for application images to be downloaded...'; }
while [[ ! -f /ship/loader/run/tag ]]; do sleep 1; done
IMAGE="$(cat /ship/loader/run/repo)/aerofs/loader:$(cat /ship/loader/run/tag)"
docker run --rm -v /ship/loader/getty:/host -v /var/run/docker.sock:/var/run/docker.sock "${IMAGE}" install-getty /host
while true; do /ship/loader/getty/run; done
- path: /ship/enable-swap
permissions: 0700
content: |
#!/bin/bash
set -e
if [ 4096 = 0 ]; then exit 0; fi
if [ ! -f /swap ]; then
fallocate -l 4096m /swap
chmod 600 /swap
mkswap /swap
fi
swapon /swap
- path: /ship/sail
permissions: 0700
content: |
#!/bin/bash -ex
mkdir -p /ship/loader/run
[[ -f /ship/loader/run/repo ]] || echo 'registry.aerofs.com' > /ship/loader/run/repo
[[ -f /ship/loader/run/target ]] || echo 'maintenance' > /ship/loader/run/target
write_status_json() {
cat > /ship/httpd/status.json <<END
{"done":$1,"total":$2}
END
}
write_status_json 0 0
systemctl start httpd.service
[[ -f /ship/loader/run/tag ]] || {
TAG=$(docker run --rm -v /var/run/docker.sock:/var/run/docker.sock $(cat /ship/loader/run/repo)/aerofs/loader tag)
echo ${TAG} > /ship/loader/run/tag
}
IMAGES=$(docker run --rm -v /var/run/docker.sock:/var/run/docker.sock $(cat /ship/loader/run/repo)/aerofs/loader images)
TOTAL=$(wc -w <<< "${IMAGES}")
DONE=0
write_status_json ${DONE} ${TOTAL}
for i in ${IMAGES}; do
IMAGE="$(cat /ship/loader/run/repo)/${i}:$(cat /ship/loader/run/tag)"
set +e; docker inspect "${IMAGE}" 1>/dev/null 2>/dev/null; EXIT=$?; set -e
[[ ${EXIT} = 0 ]] || docker pull "${IMAGE}"
DONE=$((DONE+1))
write_status_json ${DONE} ${TOTAL}
done
systemctl stop httpd.service
while true; do
RUNNING="$(docker ps -q --no-trunc)"
for SCOPE in $(systemctl list-units --no-legend 'docker-*.scope' | awk '{print $1}'); do
ID=$(echo ${SCOPE} | sed -e 's/^docker-\(.*\)\.scope$/\1/')
[[ "$(echo "${RUNNING}" | grep ${ID})" ]] || (
echo "Stopping dangling unit ${SCOPE}..."
systemctl stop ${SCOPE}
)
done
IMAGE="$(cat /ship/loader/run/repo)/aerofs/loader:$(cat /ship/loader/run/tag)"
CONTAINER=loader-$(cat /ship/loader/run/tag)
[[ "$(docker ps -a | grep ${CONTAINER})" ]] || \
docker create --name "${CONTAINER}" \
-v /var/run/docker.sock:/var/run/docker.sock \
-v /ship/loader/run/repo:/host/ship/loader/run/repo \
-v /ship/loader/run/tag:/host/ship/loader/run/tag \
-v /ship/loader/run/target:/host/ship/loader/run/target \
"${IMAGE}" load /host/ship/loader/run/repo /host/ship/loader/run/tag /host/ship/loader/run/target
echo 'Starting Loader...'
docker start -a "${CONTAINER}"
echo 'Loader stopped'
done
- path: /ship/httpd/httpd.conf
content: |
serve_ship_log() { journalctl -u ship.service; exit 0; }
serve_404() { send_response 404 <<< "404 Not Found"; exit 0; }
on_uri_match '^/$' serve_file "/ship/httpd/index.html"
on_uri_match '^/ship.log$' serve_ship_log
on_uri_match '^/status.json$' serve_file "/ship/httpd/status.json"
unconditionally serve_404
- path: /ship/httpd/index.html
encoding: gz+b64
content: |
H4sIANNybFYC/61X62/bNhD/nr/ipqaQtNlSXhs6vz6sLbACK1agwYBh6AeaoiymFKmRVJx0yP++I/W0a3vtUAeIrLvjve9+9OK7V7+/vP3z3WsobClWZwv3AEHkZhkwGTgCI9nqDPCzsNwKtnpf8ApeS8t0pblhi7QhNyIlswRoQbRhdhnUNp++CFqW4PIjaCaWgbGPgpmCMRtAoVm+DAprKzNL05I80Ewma6WssZpU7oWqMu0J6XVyndyk1JiBlpQcpYxx3qaNu4u1yh7xkfF7oIIYswyokpZwyXTnz4in1bal7nOoEtMym14Fq0WK5JNCL0Y6Tls4oeTy6oCcly2ugWfLwGc7WL2R3HIi+CcuN2ALBubRWFYmSYI5uD6iYmSu0mqjmU8awJcKT9dEw/hligXgFcuAUMvvWQBaCTbIo0QAvtrLYMszW8zg8uLi+fyo0d6wi7Q3JMiaic8qsHfqOPMI6wD5EGmviN4z7CWDgU6/QVWr1XtfOFC1rWo7W6TVMUnNxsb7xBaMbwo7g5sfL6qHOawJ/bjRqpbZFI0rPYNnV9T9zaF7v7n8+aebyznkOBJTwz+xGZiSCOFmA+1r9o2SBQXPWJMxQWpJC+zVb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