Skip to content
This repository has been archived by the owner on Aug 29, 2018. It is now read-only.

Commit

Permalink
Fix bug 981622
Browse files Browse the repository at this point in the history
  • Loading branch information
pmorie committed Jul 10, 2013
1 parent f19ecb4 commit fded385
Show file tree
Hide file tree
Showing 5 changed files with 86 additions and 3 deletions.
16 changes: 14 additions & 2 deletions cartridges/openshift-origin-cartridge-mysql/bin/control
Expand Up @@ -38,10 +38,20 @@ function start {
}

function wait_for_mysqld_availability {
test_select=${1:-false}

for i in {1..30}; do
is_running && return 0
if is_running; then
if $test_select; then
run_sql 'select 1' 2> /dev/null && return 0
else
return 0
fi
fi

sleep 1
done

return 1
}

Expand Down Expand Up @@ -83,8 +93,10 @@ function status {
}

function pre_snapshot {
# TODO: add support for scalable apps, where DB is not located on primary gear
start
# The following call is necessary due to race conditions that can arise if mysql
# is recovering from a force-stop
wait_for_mysqld_availability true

echo "$OPENSHIFT_MYSQL_DB_USERNAME" > $OPENSHIFT_DATA_DIR/mysql_db_username
echo "$OPENSHIFT_MYSQL_DB_HOST" > $OPENSHIFT_DATA_DIR/mysql_db_host
Expand Down
4 changes: 3 additions & 1 deletion cartridges/openshift-origin-cartridge-mysql/bin/post_install
@@ -1,5 +1,7 @@
#!/bin/bash -e

source $OPENSHIFT_CARTRIDGE_SDK_BASH

dbname=$OPENSHIFT_APP_NAME
socket_file=$OPENSHIFT_MYSQL_DB_SOCKET
username=$OPENSHIFT_MYSQL_DB_USERNAME
Expand All @@ -8,7 +10,7 @@ password=$OPENSHIFT_MYSQL_DB_PASSWORD
# TODO: Should be we running mysql_secure_installation

echo "drop database test;
create database \`${dbname}\` DEFAULT CHARACTER SET utf8 DEFAULT COLLATE utf8_general_ci;" | mysql -u root -S "$socket_file" > /dev/null || error 'Failed to create database', 188
create database \`${dbname}\` DEFAULT CHARACTER SET utf8 DEFAULT COLLATE utf8_general_ci;" | mysql -u root -S "$socket_file" > /dev/null || error 'Failed to create database' 188

echo "
delete from user;
Expand Down
Expand Up @@ -25,6 +25,7 @@ def write_snapshot_archive(exclusions)
run_in_container_context(tar_cmd,
env: gear_env,
out: $stdout,
err: $stderr,
chdir: @config.get('GEAR_BASE_DIR'),
timeout: @hourglass.remaining,
expected_exitstatus: 0)
Expand Down
63 changes: 63 additions & 0 deletions node/lib/openshift-origin-node/utils/logger/stderr_logger.rb
@@ -0,0 +1,63 @@
#--
# Copyright 2013 Red Hat, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#++

require 'logger'

module OpenShift
module Runtime
module NodeLogger
#
# This NodeLogger implementation is backed by the Ruby stdlib +logger+ class.
#
# NOTE: The +trace+ method is unimplemented.
#
class StderrLogger
def initialize(config=nil, context=nil)
@context = context
reinitialize
end

def reinitialize
@logger = Logger.new(STDERR)
end

def info(*args, &block)
@logger.info(*args, &block)
end

def debug(*args, &block)
@logger.info(*args, &block)
end

def warn(*args, &block)
@logger.warn(*args, &block)
end

def error(*args, &block)
@logger.error(*args, &block)
end

def fatal(*args, &block)
@logger.fatal(*args, &block)
end

def trace(*args, &block)
# not supported
end
end
end
end
end
5 changes: 5 additions & 0 deletions node/lib/openshift-origin-node/utils/node_logger.rb
Expand Up @@ -20,6 +20,7 @@
require 'openshift-origin-node/utils/logger/split_trace_logger'
require 'openshift-origin-node/utils/logger/null_logger'
require 'openshift-origin-node/utils/logger/stdout_logger'
require 'openshift-origin-node/utils/logger/stderr_logger'

module OpenShift
module Runtime
Expand Down Expand Up @@ -107,6 +108,10 @@ def self.disable
@logger = NullLogger.new
end

def self.stderr
@logger = StderrLogger.new
end

def logger
NodeLogger.logger
end
Expand Down

0 comments on commit fded385

Please sign in to comment.