From 2862faf676a044149cc089d0a46c693f66174acc Mon Sep 17 00:00:00 2001 From: sneak Date: Mon, 9 Dec 2019 05:11:52 -0800 Subject: [PATCH] fix some bugs --- Dockerfile | 5 +++++ README.md | 15 +++++++++++++++ rootfs/etc/service/postfix/run | 19 +++++++++---------- rootfs/etc/service/postgres/run | 8 ++++++++ 4 files changed, 37 insertions(+), 10 deletions(-) diff --git a/Dockerfile b/Dockerfile index 467f766..ed25096 100644 --- a/Dockerfile +++ b/Dockerfile @@ -3,6 +3,11 @@ FROM phusion/baseimage:0.11 # Use baseimage-docker's init system. CMD ["/sbin/my_init"] +# make some SSH keys that will never get used just so that +# the container doesn't generate new ones each and every boot +# (sshd is not enabled in the container) +RUN /etc/my_init.d/00_regen_ssh_host_keys.sh + ENV \ RUN_DB_MIGRATIONS=true \ SIDEKIQ_WORKERS=5 \ diff --git a/README.md b/README.md index f5276b4..79bf8b4 100644 --- a/README.md +++ b/README.md @@ -35,11 +35,16 @@ Mastodon instance. * `RUN_DB_MIGRATIONS` (default: `true`, set to empty string `""` to disable) * `SIDEKIQ_WORKERS`: (default: `5`) * others: https://github.com/tootsuite/mastodon/blob/master/.env.production.sample + # Volumes * `/state` - everything lives in here, db, redis, static files, logs, everything +Note that `/state/envdir` is an environment-variable-defining directory that +is used for all service invocations, so you can set environment settings +here for all processes without restarting the docker container. + # Ports * 3000: mastodon web (no tls, do that elsewhere) @@ -75,3 +80,13 @@ Google.) "imageName": "sneak/mastodon:v3.0.1" } ``` + +# After First Run + +``` +# docker exec -ti /bin/bash +root@c81a376bf546:~/app# su - mastodon +mastodon@c81a376bf546:~$ cd app +mastodon@c81a376bf546:~/app$ RAILS_ENV=production envdir /state/envdir bin/tootctl accounts create --email --confirmed --role admin +``` + diff --git a/rootfs/etc/service/postfix/run b/rootfs/etc/service/postfix/run index 07daea2..e672694 100644 --- a/rootfs/etc/service/postfix/run +++ b/rootfs/etc/service/postfix/run @@ -9,19 +9,18 @@ if [[ ! -d /state/envdir ]]; then chown mastodon:mastodon /state/envdir fi -if [[ ! -e /state/envdir/WEB_DOMAIN ]]; then - if [[ -n "$WEB_DOMAIN" ]]; then - echo "$WEB_DOMAIN" > /state/envdir/WEB_DOMAIN - else - hostname --fqdn > /state/envdir/WEB_DOMAIN - fi - chown mastodon:mastodon /state/envdir/* +if [[ -z "$WEB_DOMAIN" ]]; then + WEB_DOMAIN="$(hostname --fqdn)" fi -cat /etc/postfix/main.cf | grep -v '^myhostname' > /etc/postfix/main.new +if [[ -e /state/envdir/WEB_DOMAIN ]]; then + WEB_DOMAIN="$(cat /state/envdir/WEB_DOMAIN)" +fi + +cat /etc/postfix/main.cf | grep -v '^myhostname' | grep -v '^myorigin' > /etc/postfix/main.new rm /etc/postfix/main.cf -echo "myhostname = $(cat /state/envdir/WEB_DOMAIN)" >> /etc/postfix/main.cf -echo "myorigin = $(cat /state/envdir/WEB_DOMAIN)" >> /etc/postfix/main.cf +echo "myhostname = $WEB_DOMAIN" >> /etc/postfix/main.cf +echo "myorigin = $WEB_DOMAIN" >> /etc/postfix/main.cf cat /etc/postfix/main.new >> /etc/postfix/main.cf rm /etc/postfix/main.new diff --git a/rootfs/etc/service/postgres/run b/rootfs/etc/service/postgres/run index e36f1b3..bf6b0bc 100644 --- a/rootfs/etc/service/postgres/run +++ b/rootfs/etc/service/postgres/run @@ -24,6 +24,14 @@ if [[ ! -d /state/db ]]; then chmod go-rwx /state/db/data fi +function shutdown() +{ + echo "Shutting down PostgreSQL" + pkill postgres +} + +trap shutdown HUP INT QUIT ABRT KILL ALRM TERM TSTP + exec \ chpst -u mastodon:mastodon \ /usr/lib/postgresql/10/bin/postmaster -D /state/db 2>&1