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 35... Line 35...
35
	# Loop over all args
35
	# Loop over all args
36
	while true
36
	while true
37
	do
37
	do
38
		case "$1" in
38
		case "$1" in
39
			--all | -a)
39
			--all | -a)
40
				echo "Stopping all connections."
-
 
41
				remote_to_stop="ALL"
40
				remote_to_stop="ALL"
42
				break
41
				break
43
				;;
42
				;;
44
			--name | -n)
43
			--name | -n)
45
				echo "Stopping connection to $2."
-
 
46
				remote_to_stop="$2"
44
				remote_to_stop="$2"
47
				shift
45
				shift
48
				break
46
				break
49
				;;
47
				;;
50
			--help | -h)
48
			--help | -h)
Line 76... Line 74...
76
	if [ $# -lt 1 ]
74
	if [ $# -lt 1 ]
77
	then
75
	then
78
		echo "usage: $0 \"SQL query\" <DB user> <DB password> <SQL server address> <SQL server port>"
76
		echo "usage: $0 \"SQL query\" <DB user> <DB password> <SQL server address> <SQL server port>"
79
		return 2
77
		return 2
80
	fi
78
	fi
81
 
-
 
82
	# Execute the query
79
	# Execute the query
83
	/usr/bin/mariadb --user="root" --password="$DB_ROOT_PWD" --execute="$1"
80
	/usr/bin/mariadb --user="root" --password="$DB_ROOT_PWD" --execute="$1"
84
}
81
}
85
 
82
 
86
# Stop all or specific replication with remotes
83
# Stop all or specific replication with remotes
Line 93... Line 90...
93
		return 1
90
		return 1
94
	fi
91
	fi
95
 
92
 
96
	name="$1"
93
	name="$1"
97
	service_file="/etc/systemd/system/replication-$name.service"
94
	service_file="/etc/systemd/system/replication-$name.service"
98
 
-
 
99
	echo "Stopping replication with '$name'..."
-
 
100
	exec_query "STOP REPLICA '$name'" || return
-
 
101
 
-
 
102
	# Skip if the connection is received (like on a primary)
-
 
103
	if [ -f "$service_file" ]
95
	if [ -f "$service_file" ]
104
	then
96
	then
105
		echo "Stopping SSH tunnel with '$name'..."
97
		echo "Stopping replication with '$name'"
106
		/usr/bin/systemctl stop "replication-$name"
-
 
107
		/usr/bin/systemctl disable "replication-$name"
98
		exec_query "STOP REPLICA '$name'" || return
108
 
99
	else
109
		# Get remote IP and port from its name
100
		echo "Remote $name doesn't exists !"
110
		ip="$(/usr/local/bin/alcasar-replication-list.sh --name=$name | grep "Master_Host" | cut -d ' ' -f 2-)"
-
 
111
		port="$(grep "ExecStart" "$service_file" | cut -d ' ' -f 9)"
-
 
112
 
-
 
113
		echo "Disabling outbound connection to remote SSH..."
-
 
114
		sed -i "/^REPLICATION_TO=/s/$ip:$port,//" /usr/local/etc/alcasar.conf
-
 
115
		/usr/local/bin/alcasar-iptables.sh
-
 
116
	fi
101
	fi
117
}
102
}
118
 
103
 
119
# Print help message
104
# Print help message
120
usage() {
105
usage() {
Line 135... Line 120...
135
# Stop all or specific remote
120
# Stop all or specific remote
136
if [ "$remote_to_stop" == "ALL" ]
121
if [ "$remote_to_stop" == "ALL" ]
137
then
122
then
138
        # Get remotes names from database
123
        # Get remotes names from database
139
        remotes_names=$(/usr/local/bin/alcasar-replication-list.sh --all | grep "Connection_name" | cut -d ':' -f 2-)
124
        remotes_names=$(/usr/local/bin/alcasar-replication-list.sh --all | grep "Connection_name" | cut -d ':' -f 2-)
140
 
-
 
141
        # Loop over names
125
        # Loop over names
142
        for name in $remotes_names
126
        for name in $remotes_names
143
        do
127
        do
144
                stop_remote "$name"
128
                stop_remote "$name"
145
        done
129
        done