<commit_before>#!/bin/bash
#
# $Id: replicate.sh 3.4 2016-12-05 14:37:00 cmayer $
#
# install HA to a controller pair
#
# this must be run on the primary, and ssh and rsync must be set up 
# on both machines.
#
# if replication isn't broken before you run this, it certainly will be
# during.
#
# this has very limited sanity checking, so please be very careful.
#
# Copyright 2016 AppDynamics, 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.
#
cd $(dirname $0)

LOGNAME=replicate.log

# source function libraries
. lib/log.sh
. lib/runuser.sh
. lib/conf.sh
. lib/ha.sh
. lib/password.sh
. lib/sql.sh

#
# place to put certs for ssl replication
#
CERTS=$APPD_ROOT/ssl_certs

#
# the services in this list must appear in the order in which they should be
# stopped
#
appdynamics_service_list=( appdcontroller appdcontroller-db )

#
# a place to scribble
#
tmpdir=/tmp/ha.$$

#
# global variables that are to be changed by command line args
#
primary=`hostname`
internal_vip=
external_vip=
monitor=
secondary=
datadir=
innodb_logdir=
debug=false
appserver_only_sync=false
upgrade=false
final=false
unencrypted=false
start_appserver=true
watchdog_enable=false
ssl_replication=false
ma_ssl_enabled=false
ssl_enabled=false
wildcard=false
unbreak=false
rsync_throttle="--bwlimit=20000"
rsync_compression=""
rsync_opts="-PavpW --del --inplace --exclude=ibdata1"
final_rsync_opts="-PavpW --del --inplace"
machine_agent=""
ma_conf=""

#
# make sure that we are running as the appdynamics user in db.cnf
# if this is root, then we don't need a privilege escalation method
#
if [ `id -u` -eq 0 ] ; then
	if [ $db_user != root ] ; then
		fatal 1 "replicate must run as $db_user"
	fi
	running_as_root=true
else
	running_as_root=false
fi

# wrapping bag of portable checks for installed service
function check_installed_service {
   	(( $# == 1 )) || abend "check_installed_service: needs 1 arg"
	
   	local svc_name=$1
   	local chkconfig=$(which /sbin/chkconfig 2>/dev/null)		# returns path if exists
   	local lservice=$service_bin

   	[[ -f /etc/init.d/$svc_name ]] || return 1
	
   	if [[ -n "$chkconfig" ]] ; then
		return $($chkconfig --list $svc_name >/dev/null 2>&1)
   	fi

   	return $($lservice --status-all 2>/dev/null| grep -q '\b'$svc_name'\b')<commit_msg>Fixed minor bug where replicate.sh referred to db_user rather than dbuser - set by lib/sql.sh<commit_after>#!/bin/bash
#
# $Id: replicate.sh 3.4 2016-12-05 14:37:00 cmayer $
#
# install HA to a controller pair
#
# this must be run on the primary, and ssh and rsync must be set up 
# on both machines.
#
# if replication isn't broken before you run this, it certainly will be
# during.
#
# this has very limited sanity checking, so please be very careful.
#
# Copyright 2016 AppDynamics, 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.
#
cd $(dirname $0)

LOGNAME=replicate.log

# source function libraries
. lib/log.sh
. lib/runuser.sh
. lib/conf.sh
. lib/ha.sh
. lib/password.sh
. lib/sql.sh

#
# place to put certs for ssl replication
#
CERTS=$APPD_ROOT/ssl_certs

#
# the services in this list must appear in the order in which they should be
# stopped
#
appdynamics_service_list=( appdcontroller appdcontroller-db )

#
# a place to scribble
#
tmpdir=/tmp/ha.$$

#
# global variables that are to be changed by command line args
#
primary=`hostname`
internal_vip=
external_vip=
monitor=
secondary=
datadir=
innodb_logdir=
debug=false
appserver_only_sync=false
upgrade=false
final=false
unencrypted=false
start_appserver=true
watchdog_enable=false
ssl_replication=false
ma_ssl_enabled=false
ssl_enabled=false
wildcard=false
unbreak=false
rsync_throttle="--bwlimit=20000"
rsync_compression=""
rsync_opts="-PavpW --del --inplace --exclude=ibdata1"
final_rsync_opts="-PavpW --del --inplace"
machine_agent=""
ma_conf=""

#
# make sure that we are running as the appdynamics user in db.cnf
# if this is root, then we don't need a privilege escalation method
#
if [ `id -u` -eq 0 ] ; then
	if [ $dbuser != root ] ; then
		fatal 1 "replicate must run as $dbuser"
	fi
	running_as_root=true
else
	running_as_root=false
fi

# wrapping bag of portable checks for installed service
function check_installed_service {
   	(( $# == 1 )) || abend "check_installed_service: needs 1 arg"
	
   	local svc_name=$1
   	local chkconfig=$(which /sbin/chkconfig 2>/dev/null)		# returns path if exists
   	local lservice=$service_bin

   	[[ -f /etc/init.d/$svc_name ]] || return 1
	
   	if [[ -n "$chkconfig" ]] ; then
		return $($chkconfig --list $svc_name >/dev/null 2>&1)
   	fi

   	return $($lservice --status-all 2>/dev/null| grep -q '\b'$svc_name'\b')
{'fraction_non_alphanumeric': 0.10259140930067448, 'fraction_numerical': 0.01455449059282925, 'mean_word_length': 4.0, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3337373', 'n_tokens_mistral': 1969, 'n_tokens_neox': 1863, 'n_words': 650}