diff --git a/Dockerfile b/Dockerfile index f4b41d9..6c6c1ba 100644 --- a/Dockerfile +++ b/Dockerfile @@ -27,7 +27,10 @@ RUN \ RUN locale-gen en_US.UTF-8 RUN \ - apt-key adv --keyserver keys.gnupg.net --recv-keys 1C4CBDCDCD2EFD2A && \ + apt-key adv --keyserver keys.gnupg.net --recv-keys 1C4CBDCDCD2EFD2A || \ + apt-key adv --keyserver hkp://keys.gnupg.net:80 --recv-keys 1C4CBDCDCD2EFD2A + +RUN \ echo "deb http://repo.percona.com/apt `lsb_release -cs` main" > /etc/apt/sources.list.d/percona.list && \ echo "deb-src http://repo.percona.com/apt `lsb_release -cs` main" >> /etc/apt/sources.list.d/percona.list && \ ln -fs /bin/true /usr/bin/chfn && \ @@ -46,7 +49,7 @@ ADD https://s3-us-west-2.amazonaws.com/opdemand/confd-v0.5.0-json /usr/local/bin RUN chmod +x /usr/local/bin/confd # Define mountable directories. -VOLUME ["/etc/mysql", "/var/lib/mysql"] +VOLUME ["/var/lib/mysql"] ADD . /app diff --git a/bin/boot b/bin/boot index eaf2a7e..a2bdf33 100644 --- a/bin/boot +++ b/bin/boot @@ -14,6 +14,7 @@ DIR=$(dirname $0) # functions . $DIR/functions +DB_OPTIONS="" MYSQL_USER=${MYSQL_USER:-admin} MYSQL_PASS=${MYSQL_PASS:-admin} REP_USER=${REP_USER:-replicator} @@ -26,6 +27,8 @@ if [[ -z $HOST ]]; then echo '==> $HOST not set. booting mysql without clustering.' init_database echo "==> database running..." + touch /var/log/mysql/error.log + tail -f /var/log/mysql/error.log & mysqld_safe $DB_OPTIONS exit $? fi @@ -79,12 +82,12 @@ if [[ -z $CLUSTER_MEMBERS ]]; then echo "-----> leader ready. Starting." sleep 5 echo "-----> joining cluster with known members: $CLUSTER_MEMBERS" - mysqld_safe --wsrep_cluster_address=gcomm://$CLUSTER_MEMBERS $WSREP_OPTIONS & + mysqld --wsrep_cluster_address=gcomm://$CLUSTER_MEMBERS $WSREP_OPTIONS & fi else cluster_members echo "-----> joining cluster with known members: $CLUSTER_MEMBERS" - mysqld_safe --wsrep_cluster_address=gcomm://$CLUSTER_MEMBERS $WSREP_OPTIONS & + mysqld --wsrep_cluster_address=gcomm://$CLUSTER_MEMBERS $WSREP_OPTIONS & fi @@ -106,6 +109,8 @@ while [[ -z $(netstat -lnt | awk "\$6 == \"LISTEN\" && \$4 ~ \".$PUBLISH\" && \$ echo "==> database running..." +tail -f /var/log/mysql/error.log & + # publish the service to etcd using the injected HOST and PORT if [[ ! -z $PUBLISH ]]; then diff --git a/bin/functions b/bin/functions index db5db46..6b0dc7c 100644 --- a/bin/functions +++ b/bin/functions @@ -15,6 +15,7 @@ function on_exit() { } function cluster_members() { + CLUSTER_MEMBERS= for key in $(etcdctl --no-sync -C $ETCD ls $ETCD_PATH/cluster/galeraEndpoints); do value=$(etcdctl --no-sync -C $ETCD get $key) LIST+="$(basename $value)," @@ -33,7 +34,6 @@ function publish_to_etcd() { } function init_database() { - DB_OPTIONS="--skip-syslog --verbose" chown -R mysql:mysql /var/lib/mysql if [[ ! -d /var/lib/mysql/mysql ]]; then echo "==> An empty or uninitialized database is detected in /var/lib/mysql" diff --git a/templates/my.cnf b/templates/my.cnf index af4653e..70f7012 100644 --- a/templates/my.cnf +++ b/templates/my.cnf @@ -90,6 +90,8 @@ query_cache_size = 64M # # Error logging goes to syslog due to /etc/mysql/conf.d/mysqld_safe_syslog.cnf. # +log_error = /var/log/mysql/error.log + # we do want to know about network errors and such log_warnings = 2 # diff --git a/user-data.erb b/user-data.erb index d3ff0c4..0e5fd30 100644 --- a/user-data.erb +++ b/user-data.erb @@ -23,6 +23,7 @@ coreos: BindIPv6Only=both [Install] WantedBy=sockets.target +<% unless ENV['dev'] %> - name: database.service command: start enable: true @@ -38,25 +39,26 @@ coreos: ExecStartPre=/usr/bin/docker pull paulczar/percona-galera:latest ExecStart=/bin/sh -c "/usr/bin/docker run --name database --rm -p 3306:3306 -p 4444:4444 -p 4567:4567 -p 4568:4568 -e PUBLISH=3306 -e HOST=$COREOS_PRIVATE_IPV4 -e CLUSTER=galera paulczar/percona-galera:latest" ExecStop=/usr/bin/docker stop database - +<% end %> write_files: - path: /etc/motd content: "Database Cluster Demo\n" - - path: /etc/profile.d/nse-function.sh + - path: /etc/profile.d/db-functions.sh permissions: '0755' content: | function nse() { sudo nsenter --pid --uts --mount --ipc --net --target $(docker inspect --format="{{ .State.Pid }}" $1) } - - path: /etc/profile.d/database_shell.sh - permissions: '0755' - content: | + function dev_db() { + eval `cat /etc/environment` + /usr/bin/docker run -it -e DEBUG=1 -p 3306:3306 -p 4444:4444 -p 4567:4567 -p 4568:4568 -e PUBLISH=3306 -e HOST=$COREOS_PRIVATE_IPV4 -e CLUSTER=galera paulczar/percona-galera:latest bash + } function database() { sudo nsenter --pid --uts --mount --ipc --net --target $(docker inspect --format="{{ .State.Pid }}" database) } - - path: /etc/profile.d/rebuild.sh - permissions: '0755' - content: | function rebuild() { docker build -t paulczar/percona-galera /home/core/share } + function cleanup() { + etcdctl rm --recursive /database + }