1
0
mirror of https://github.com/mail-in-a-box/mailinabox.git synced 2026-03-18 18:07:22 +01:00

dockerize (work in progress)

Docker support was initially worked on in 2bbb7a5e7e, but it never really worked.

This extends f7d7434012800c3572049af82a501743d4aed583 which was an old branch for docker work.
This commit is contained in:
Joshua Tauberer
2014-08-17 08:48:27 -04:00
parent 7ec662c83f
commit dd5de8acf3
8 changed files with 270 additions and 8 deletions

View File

@@ -70,12 +70,20 @@ function get_default_hostname {
# Guess the machine's hostname. It should be a fully qualified
# domain name suitable for DNS. None of these calls may provide
# the right value, but it's the best guess we can make.
set -- $(hostname --fqdn 2>/dev/null ||
hostname --all-fqdns 2>/dev/null ||
hostname 2>/dev/null)
set -- $(
get_hostname_from_reversedns ||
hostname --fqdn 2>/dev/null ||
hostname --all-fqdns 2>/dev/null ||
hostname 2>/dev/null)
printf '%s\n' "$1" # return this value
}
function get_hostname_from_reversedns {
# Do a reverse DNS lookup on our public IPv4 address. The output of
# `host` is complex -- use sed to get the FDQN.
host $(get_publicip_from_web_service 4) | sed "s/.*pointer \(.*\)\./\1/"
}
function get_publicip_from_web_service {
# This seems to be the most reliable way to determine the
# machine's public IP address: asking a very nice web API
@@ -151,7 +159,25 @@ function ufw_allow {
}
function restart_service {
hide_output service $1 restart
# Restart a service quietly.
if [ ! "$IS_DOCKER" ]; then
# The normal way to restart a service.
hide_output service $1 restart
else
# On docker, sysvinit is not present. Our base image provides
# a weird way to manage running services. But we're not going
# to use it. Just execute the init.d script directly.
if [ "$1" == "dovecot" ]; then
# Dovecot does not provide an init.d script. It just provides
# an upstart init configuration. But Docker doesn't provide
# upstart. Start Dovecot specially.
killall dovecot
dovecot -c /etc/dovecot/dovecot.conf
else
hide_output /etc/init.d/$1 restart
fi
fi
}
## Dialog Functions ##

View File

@@ -4,7 +4,7 @@ if [[ $EUID -ne 0 ]]; then
echo
echo "sudo $0"
echo
exit
exit 1
fi
# Check that we are running on Ubuntu 14.04 LTS (or 14.04.xx).
@@ -14,7 +14,7 @@ if [ "`lsb_release -d | sed 's/.*:\s*//' | sed 's/14\.04\.[0-9]/14.04/' `" != "U
lsb_release -d | sed 's/.*:\s*//'
echo
echo "We can't write scripts that run on every possible setup, sorry."
exit
exit 1
fi
# Check that we have enough memory.
@@ -30,6 +30,6 @@ if [ ! -d /vagrant ]; then
echo "Your Mail-in-a-Box needs more memory (RAM) to function properly."
echo "Please provision a machine with at least 768 MB, 1 GB recommended."
echo "This machine has $TOTAL_PHYSICAL_MEM MB memory."
exit
exit 1
fi
fi

View File

@@ -59,7 +59,11 @@ if [ "$PUBLIC_IPV6" = "auto" ]; then
# Use a public API to get our public IPv6 address, or fall back to local network configuration.
PUBLIC_IPV6=$(get_publicip_from_web_service 6 || get_default_privateip 6)
fi
if [ "$PRIMARY_HOSTNAME" = "auto-easy" ]; then
if [ "$PRIMARY_HOSTNAME" = "auto" ]; then
# Use reverse DNS to get this machine's hostname. Install bind9-host early.
hide_output apt-get -y install bind9-host
PRIMARY_HOSTNAME=$(get_default_hostname)
elif [ "$PRIMARY_HOSTNAME" = "auto-easy" ]; then
# Generate a probably-unique subdomain under our justtesting.email domain.
PRIMARY_HOSTNAME=`echo $PUBLIC_IP | sha1sum | cut -c1-5`.justtesting.email
fi