Subversion Repositories ALCASAR

Rev

Rev 3321 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log

Rev 3321 Rev 3322
Line 40... Line 40...
40
	del_remote_as_primary
40
	del_remote_as_primary
41
	# Delete SSH tunnel service file
41
	# Delete SSH tunnel service file
42
	service_file="replication-$remote_name.service"
42
	service_file="replication-$remote_name.service"
43
	service_path="/etc/systemd/system/$service_file"
43
	service_path="/etc/systemd/system/$service_file"
44
	[ -f "$service_file" ] && rm "$service_file"
44
	[ -f "$service_file" ] && rm "$service_file"
-
 
45
	sed -i "/^REPLICATION_TO=/s/$ip:$port,//" /usr/local/etc/alcasar.conf
45
	return "$error_code"
46
	return "$error_code"
46
}
47
}
47
 
48
 
48
# Add remote as primary
49
# Add remote as primary
49
add_remote_as_primary() {
50
add_remote_as_primary() {
Line 301... Line 302...
301
	echo "Primary database dump locally copied"
302
	echo "Primary database dump locally copied"
302
	alcasar-mariadb.sh --import /tmp/alcasar-users-database-primary.sql.gz
303
	alcasar-mariadb.sh --import /tmp/alcasar-users-database-primary.sql.gz
303
	rm -f /tmp/alcasar-users-database-primary.sql.gz
304
	rm -f /tmp/alcasar-users-database-primary.sql.gz
304
}
305
}
305
 
306
 
306
push_local_info_to_primary() {
307
add_symmetric_replication() {
307
	hostname="$(/usr/local/bin/alcasar-replication-ssh-keys-management.sh --show-pubkey | cut -d' ' -f3 | cut -d'@' -f2)"
308
	hostname="$(/usr/local/bin/alcasar-replication-ssh-keys-management.sh --show-pubkey | cut -d' ' -f3 | cut -d'@' -f2 |cut -d'.' -f1)"
308
	active_db_port="$(/usr/local/bin/alcasar-replication-list.sh --all |grep Master_Port|cut -d" " -f2)"
309
	active_db_port="$(/usr/local/bin/alcasar-replication-list.sh --all |grep Master_Port|cut -d" " -f2)"
-
 
310
	echo "adding symmetric replication (--name=$hostname --bind-port=$active_db_port --db-user=db_replication --db-password=$REPL_DB_USER_PWD)"
-
 
311
# First idea  : copy local db_user passwd remotely.
309
	if ! /usr/bin/scp -q -P "$remote_ssh_port" /home/replication/local-db_replication-pwd.txt "$remote_ssh_user"@"$remote_addr":secondary-"$hostname"-"$active_db_port"-db_replication-pwd.txt
312
#if ! /usr/bin/scp -q -P "$remote_ssh_port" /home/replication/local-db_replication-pwd.txt "$remote_ssh_user"@"$remote_addr":secondary-"$hostname"-"$active_db_port"-db_replication-pwd.txt
-
 
313
	# second idea : remotely add the replication.
-
 
314
	if ! /usr/bin/ssh -p "$remote_ssh_port" "$remote_ssh_user"@"$remote_addr" -- "sudo /usr/local/bin/alcasar-replication-add.sh --to-secondary --name=$hostname --bind-port=$active_db_port --db-user=db_replication --db-password=$REPL_DB_USER_PWD"
310
	then
315
	then
311
		echo "error: cannot send primary db_user pass" >&2
316
		echo "error: cannot add symmetric replication" >&2
312
		return 7
317
		return 7
313
	fi
318
	fi
314
	echo "Successfully send primary db_user pass"
319
	echo "Successfully add symmetric replication"
315
}
320
}
316
 
321
 
317
find_common_free_port() {
322
find_common_free_port() {
318
	remote_busy_ports_file=/tmp/remote_busy_ports
323
	remote_busy_ports_file=/tmp/remote_busy_ports
319
	local_busy_ports_file=/tmp/local_busy_ports
324
	local_busy_ports_file=/tmp/local_busy_ports
Line 423... Line 428...
423
		tmp_allow_outbound_connection || abort "$?" || exit
428
		tmp_allow_outbound_connection || abort "$?" || exit
424
		check_primary_credentials || abort "$?" || exit
429
		check_primary_credentials || abort "$?" || exit
425
		create_ssh_tunnel || abort "$?" || exit
430
		create_ssh_tunnel || abort "$?" || exit
426
		retrieve_primary_database || abort "$?" || exit
431
		retrieve_primary_database || abort "$?" || exit
427
		add_remote_as_primary || abort "$?" || exit
432
		add_remote_as_primary || abort "$?" || exit
428
		push_local_info_to_primary || abort "$?" || exit
-
 
429
		echo -n "Allowing outbound connection to remote SSH "
433
		echo -n "Allowing outbound connection to remote SSH "
430
		# Get remote IP and port from its name
434
		# Get remote IP and port from its name
431
		port="$(grep "ExecStart" "$service_path" | cut -d ' ' -f 9)"
435
		port="$(grep "ExecStart" "$service_path" | cut -d ' ' -f 9)"
432
		ip="$(grep "ExecStart" "$service_path" | cut -d ' ' -f 14 | cut -d '@' -f2)"
436
		ip="$(grep "ExecStart" "$service_path" | cut -d ' ' -f 14 | cut -d '@' -f2)"
-
 
437
		echo "$ip:$port"
433
		/usr/bin/sed -i -E "/^REPLICATION_TO=/s/=(.*)/=\1$ip:$port,/" /usr/local/etc/alcasar.conf
438
		/usr/bin/sed -i -E "/^REPLICATION_TO=/s/=(.*)/=\1$ip:$port,/" /usr/local/etc/alcasar.conf
434
		/usr/local/bin/alcasar-iptables.sh
439
		/usr/local/bin/alcasar-iptables.sh
-
 
440
		add_symmetric_replication || abort "$?" || exit
435
		;;
441
		;;
436
	secondary)
442
	secondary)
437
		check_secondary_credentials || exit
443
		check_secondary_credentials || exit
438
		add_remote_as_primary || abort "$?" || exit # In a federation, primary/secondary is define by SSH role (sshd-server=primary; ssh-client=secondary)
444
		add_remote_as_primary || abort "$?" || exit # In a federation, primary/secondary is define by SSH role (sshd-server=primary; ssh-client=secondary)
439
		;;
445
		;;