Subversion Repositories ALCASAR

Rev

Rev 3294 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log

Rev 3294 Rev 3313
Line 36... Line 36...
36
	# Loop over all args
36
	# Loop over all args
37
	while true
37
	while true
38
	do
38
	do
39
		case "$1" in
39
		case "$1" in
40
			--all | -a)
40
			--all | -a)
41
				echo "Starting all connections."
-
 
42
				remote_to_start="ALL"
41
				remote_to_start="ALL"
43
				break
42
				break
44
				;;
43
				;;
45
			--name | -n)
44
			--name | -n)
46
				echo "Starting connection to $2."
-
 
47
				remote_to_start="$2"
45
				remote_to_start="$2"
48
				shift
46
				shift
49
				break
47
				break
50
				;;
48
				;;
51
			--help | -h)
49
			--help | -h)
Line 93... Line 91...
93
		return 1
91
		return 1
94
	fi
92
	fi
95
 
93
 
96
	name="$1"
94
	name="$1"
97
	service_file="/etc/systemd/system/replication-$name.service"
95
	service_file="/etc/systemd/system/replication-$name.service"
98
 
-
 
99
	# Skip if the connection is received (like on a primary)
-
 
100
	if [ -f "$service_file" ]
96
	if [ -f "$service_file" ]
101
	then
97
	then
102
		echo "Starting SSH tunnel with '$name'..."
-
 
103
		/usr/bin/systemctl start "replication-$name"
-
 
104
		/usr/bin/systemctl enable "replication-$name"
-
 
105
 
-
 
106
		# Get remote IP and port from its name
-
 
107
		ip="$(/usr/local/bin/alcasar-replication-list.sh --name=$name | grep "Master_Host" | cut -d ' ' -f 2-)"
-
 
108
		port="$(grep "ExecStart" "$service_file" | cut -d ' ' -f 9)"
-
 
109
 
-
 
110
		echo "Allowing outbound connection to remote SSH..."
-
 
111
		/usr/bin/sed -i -E "/^REPLICATION_TO=/s/=(.*)/=\1$ip:$port,/" /usr/local/etc/alcasar.conf
-
 
112
		/usr/local/bin/alcasar-iptables.sh
-
 
113
	fi
-
 
114
 
-
 
115
	echo "Starting replication with '$name'..."
98
	echo "Starting replication with '$name'"
116
	exec_query "START REPLICA '$name'" || return
99
	exec_query "START REPLICA '$name'" || return
-
 
100
	else
-
 
101
		echo "Remote $name doesn't exists !"
-
 
102
	fi
117
}
103
}
118
 
104
 
119
# Print help message
105
# Print help message
120
usage() {
106
usage() {
121
	echo "usage: $0 OPTIONS"
107
	echo "usage: $0 OPTIONS"
Line 135... Line 121...
135
# Stop all or specific remote
121
# Stop all or specific remote
136
if [ "$remote_to_start" == "ALL" ]
122
if [ "$remote_to_start" == "ALL" ]
137
then
123
then
138
	# Get remotes names from database
124
	# Get remotes names from database
139
	remotes_names=$(/usr/local/bin/alcasar-replication-list.sh --all | grep "Connection_name" | cut -d ':' -f 2-)
125
	remotes_names=$(/usr/local/bin/alcasar-replication-list.sh --all | grep "Connection_name" | cut -d ':' -f 2-)
140
 
-
 
141
	# Loop over names
126
	# Loop over names
142
	for name in $remotes_names
127
	for name in $remotes_names
143
	do
128
	do
144
		start_remote "$name"
129
		start_remote "$name"
145
	done
130
	done