View | Details | Raw Unified | Return to bug 221542
Collapse All | Expand All

(-)databases/proxysql-admin/Makefile (+46 lines)
Line 0 Link Here
1
# Created by: Jake Smith <jake@xz.cx>
2
# $FreeBSD$
3
4
PORTNAME=	proxysql-admin
5
PORTVERSION=	1.3.7
6
CATEGORIES=	databases
7
8
MAINTAINER=	jake@xz.cx
9
COMMENT=	Configures Percona XtraDB cluster nodes into ProxySQL
10
11
LICENSE=	GPLv2
12
13
RUN_DEPENDS=	bash:shells/bash \
14
		getopt:misc/getopt \
15
		pidof:sysutils/pidof
16
17
NO_ARCH=	yes
18
NO_BUILD=	yes
19
20
USES=		shebangfix
21
22
SHEBANG_FILES=	${PORTNAME} proxysql_*
23
24
USE_GITHUB=	yes
25
GH_ACCOUNT=	percona
26
GH_PROJECT=	proxysql-admin-tool
27
GH_TAGNAME=	${PORTVERSION}
28
29
do-install:
30
	${INSTALL_SCRIPT} ${WRKSRC}/proxysql-admin \
31
		${STAGEDIR}${PREFIX}/bin/proxysql-admin
32
33
	${MKDIR} ${STAGEDIR}${PREFIX}/libexec/${PORTNAME}
34
	${INSTALL_SCRIPT} ${WRKSRC}/proxysql_galera_checker \
35
		${STAGEDIR}${PREFIX}/libexec/${PORTNAME}/
36
	${INSTALL_SCRIPT} ${WRKSRC}/proxysql_node_monitor \
37
		${STAGEDIR}${PREFIX}/libexec/${PORTNAME}/
38
39
	${INSTALL_DATA} ${WRKSRC}/proxysql-admin.cnf \
40
		${STAGEDIR}${PREFIX}/etc/proxysql-admin.cnf.sample
41
42
post-install:
43
	${INSTALL_DATA} ${FILESDIR}/proxysql-admin.conf \
44
		${STAGEDIR}${PREFIX}/etc/newsyslog.conf.d/
45
46
.include <bsd.port.mk>
(-)databases/proxysql-admin/distinfo (+3 lines)
Line 0 Link Here
1
TIMESTAMP = 1502718138
2
SHA256 (percona-proxysql-admin-tool-1.3.7_GH0.tar.gz) = 8ab8d0b3ffb35c22956703fd98574e74594de85fe87e89747fe68220eee8f4cf
3
SIZE (percona-proxysql-admin-tool-1.3.7_GH0.tar.gz) = 23259
(-)databases/proxysql-admin/files/patch-proxysql-admin (+120 lines)
Line 0 Link Here
1
--- proxysql-admin.orig	2017-08-15 14:06:53 UTC
2
+++ proxysql-admin
3
@@ -64,9 +64,9 @@ usage () {
4
 }
5
 
6
 # Check if we have a functional getopt(1)
7
-if ! getopt --test
8
+if ! /usr/local/bin/getopt --test
9
   then
10
-  go_out="$(getopt --options=edv --longoptions=config-file:,proxysql-username:,proxysql-password::,proxysql-hostname:,proxysql-port:,cluster-username:,cluster-password::,cluster-hostname:,cluster-port:,monitor-username:,monitor-password:,cluster-app-username:,cluster-app-password:,node-check-interval:,quick-demo,mode:,write-node:,enable,disable,adduser,syncusers,version,help \
11
+  go_out="$(/usr/local/bin/getopt --options=edv --longoptions=config-file:,proxysql-username:,proxysql-password::,proxysql-hostname:,proxysql-port:,cluster-username:,cluster-password::,cluster-hostname:,cluster-port:,monitor-username:,monitor-password:,cluster-app-username:,cluster-app-password:,node-check-interval:,quick-demo,mode:,write-node:,enable,disable,adduser,syncusers,version,help \
12
   --name="$(basename "$0")" -- "$@")"
13
   test $? -eq 0 || exit 1
14
   eval set -- "$go_out"
15
@@ -80,12 +80,12 @@ fi
16
 if ! echo "$go_out" | grep -q 'config-file'; then
17
   if ! echo "$go_out" | grep -q 'quick-demo'; then
18
     # Reading default variables from default configuration file location.
19
-    if [ -e "/etc/proxysql-admin.cnf" ]; then
20
-      # Loading default configuration from /etc/proxysql-admin.cnf
21
-      source /etc/proxysql-admin.cnf
22
-      CONFIG_FILE="/etc/proxysql-admin.cnf"
23
+    if [ -e "/usr/local/etc/proxysql-admin.cnf" ]; then
24
+      # Loading default configuration from /usr/local/etc/proxysql-admin.cnf
25
+      source /usr/local/etc/proxysql-admin.cnf
26
+      CONFIG_FILE="/usr/local/etc/proxysql-admin.cnf"
27
     else
28
-      echo "WARNING! Default configuration file (/etc/proxysql-admin.cnf) does not exist"
29
+      echo "WARNING! Default configuration file (/usr/local/etc/proxysql-admin.cnf) does not exist"
30
     fi
31
   fi
32
 fi
33
@@ -362,13 +362,13 @@ if [ $MODE == "loadbal" ]; then
34
   WRITE_HOSTGROUP_ID=10
35
   READ_HOSTGROUP_ID=10
36
   if [ -e "${CONFIG_FILE}" ]; then
37
-    sudo sed -i "0,/^[ \t]*export MODE[ \t]*=.*$/s|^[ \t]*export MODE[ \t]*=.*$|export MODE=\"loadbal\"|" "${CONFIG_FILE}"
38
+    sed -i "" "0,/^[ 	]*export MODE[ 	]*=.*$/s|^[ 	]*export MODE[ 	]*=.*$|export MODE=\"loadbal\"|" "${CONFIG_FILE}"
39
   fi
40
 elif [ $MODE == "singlewrite" ]; then
41
   WRITE_HOSTGROUP_ID=10
42
   READ_HOSTGROUP_ID=11
43
   if [ -e "${CONFIG_FILE}" ]; then
44
-    sudo sed -i "0,/^[ \t]*export MODE[ \t]*=.*$/s|^[ \t]*export MODE[ \t]*=.*$|export MODE=\"singlewrite\"|" "${CONFIG_FILE}"
45
+    sed -i "" "0,/^[ 	]*export MODE[ 	]*=.*$/s|^[ 	]*export MODE[ 	]*=.*$|export MODE=\"singlewrite\"|" "${CONFIG_FILE}"
46
   fi
47
 fi
48
 
49
@@ -413,7 +413,7 @@ check_cmd(){
50
 
51
 check_proxysql(){
52
   if ! pidof proxysql >/dev/null ; then
53
-    echo "ProxySQL is not running, please check the error log at /var/lib/proxysql/proxysql.log"
54
+    echo "ProxySQL is not running, please check the error log at /var/log/proxysql.log"
55
     exit 1
56
   fi
57
 }
58
@@ -574,7 +574,7 @@ enable_proxysql(){
59
     proxysql_exec "DELETE FROM mysql_query_rules WHERE destination_hostgroup in ($WRITE_HOSTGROUP_ID,$READ_HOSTGROUP_ID)"
60
     if [ -z "$QUICK_DEMO" ]; then
61
       if [ -z "$WRITE_NODE" ]; then
62
-        writer_ws_ip=$(mysql_exec "show variables like 'wsrep_provider_options'" | grep -o -P '(?<=base_host =).*(?=; base_port)' | xargs)
63
+        writer_ws_ip=$(mysql_exec "show variables like 'wsrep_provider_options'" | sed -r 's/.*base_host =( [^ ]+);.*/\1/' | xargs)
64
         writer_ws_port=$CLUSTER_PORT
65
       else
66
         writer_ws_ip=$(echo "$WRITE_NODE" | awk -F':' '{print $1}')
67
@@ -591,7 +591,7 @@ enable_proxysql(){
68
         fi
69
       fi
70
     else
71
-      writer_ws_ip=$(mysql_exec "show variables like 'wsrep_provider_options'" | grep -o -P '(?<=base_host =).*(?=; base_port)' | xargs)
72
+      writer_ws_ip=$(mysql_exec "show variables like 'wsrep_provider_options'" | sed -r 's/.*base_host =( [^ ]+);.*/\1/' | xargs)
73
       writer_ws_port=$CLUSTER_PORT
74
     fi
75
     proxysql_exec "DELETE FROM mysql_servers WHERE hostgroup_id=$WRITE_HOSTGROUP_ID"
76
@@ -629,7 +629,7 @@ enable_proxysql(){
77
   else
78
     NUMBER_WRITERS=0
79
   fi
80
-  proxysql_exec "INSERT  INTO SCHEDULER (id,active,interval_ms,filename,arg1,arg2,arg3,arg4,arg5) VALUES (10,1,$NODE_CHECK_INTERVAL,'$PROXYSQL_GALERA_CHECK',$WRITE_HOSTGROUP_ID,$READ_HOSTGROUP_ID,$NUMBER_WRITERS,1,'/var/lib/proxysql/proxysql_galera_check.log');"
81
+  proxysql_exec "INSERT  INTO SCHEDULER (id,active,interval_ms,filename,arg1,arg2,arg3,arg4,arg5) VALUES (10,1,$NODE_CHECK_INTERVAL,'$PROXYSQL_GALERA_CHECK',$WRITE_HOSTGROUP_ID,$READ_HOSTGROUP_ID,$NUMBER_WRITERS,1,'/var/log/proxysql_galera_check.log');"
82
   check_cmd $? "Failed to add the Percona XtraDB Cluster monitoring scheduler in ProxySQL. Please check username, password and other options for connecting to ProxySQL database"
83
 
84
   # Adding Percona XtraDB Cluster membership checking scheduler
85
@@ -722,13 +722,13 @@ syncusers() {
86
   MYSQLVER=$(mysql_exec "SELECT VERSION();" | tail -1 | cut -d'.' -f1,2 )
87
 
88
   case $MYSQLVER in
89
-    5.6)
90
-      password_field="Password";;
91
     5.7)
92
       password_field="authentication_string";;
93
+    *)
94
+      password_field="Password";;
95
   esac
96
-  
97
-  mysql_users=$(mysql_exec "SELECT User,${password_field} FROM mysql.user where ${password_field}!=''" | sed 's/\t/,/g' | egrep -v "User,${password_field}|mysql.sys" | sort | uniq )
98
+
99
+  mysql_users=$(mysql_exec "SELECT User,${password_field} FROM mysql.user where ${password_field}!=''" | sed 's/	/,/g' | egrep -v "User,${password_field}|mysql.sys" | sort | uniq )
100
   check_cmd $? "Failed to load user list from Percona XtraDB Cluster. Please check username, password and other options for connecting to Percona XtraDB Cluster"
101
   #Checking whether user is part of proxysql admin user list
102
   proxysql_admin_user_check(){
103
@@ -741,7 +741,7 @@ syncusers() {
104
     fi
105
   }
106
   # Get current ProxySQL users and filter out header row
107
-  proxysql_users=$(proxysql_exec "SELECT username,password FROM mysql_users where password!=''" | sed 's/\t/,/g' | egrep -v "username,password" | sort | uniq )
108
+  proxysql_users=$(proxysql_exec "SELECT username,password FROM mysql_users where password!=''" | sed 's/	/,/g' | egrep -v "username,password" | sort | uniq )
109
   check_cmd $? "Failed to load user list from ProxySQL database. Please check username, password and other options for connecting to ProxySQL database"
110
 
111
   echo -e "\nSyncing user accounts from Percona XtraDB Cluster to ProxySQL"
112
@@ -805,7 +805,7 @@ if [ "$ENABLE" == 1 ] || [ "$DISABLE" ==
113
     echo -e "\nProxySQL read/write configuration mode is ${BD}$MODE${NBD}"
114
     enable_proxysql
115
     echo -e "\nProxySQL configuration completed!\n"
116
-    PROXYSQL_CLIENT_PORT=$(proxysql_exec "SELECT * FROM runtime_global_variables WHERE variable_name='mysql-interfaces'" | awk '{print $2}' | grep -o -P '(?<=:).*(?=;)')
117
+    PROXYSQL_CLIENT_PORT=$(proxysql_exec "SELECT * FROM runtime_global_variables WHERE variable_name='mysql-interfaces'" | awk -F ':' '/:/ {print $NF}')
118
     echo -e "ProxySQL has been successfully configured to use with Percona XtraDB Cluster\n"
119
     echo -e "You can use the following login credentials to connect your application through ProxySQL\n"
120
     if [ -z "$QUICK_DEMO" ]; then
(-)databases/proxysql-admin/files/patch-proxysql-admin.cnf (+9 lines)
Line 0 Link Here
1
--- proxysql-admin.cnf.orig	2017-06-27 09:48:53 UTC
2
+++ proxysql-admin.cnf
3
@@ -1,3 +1,6 @@
4
+# add scheduler scripts to path
5
+export PATH=$PATH:/usr/local/libexec/proxysql-admin
6
+
7
 # proxysql admin interface credentials.
8
 export PROXYSQL_USERNAME="admin"
9
 export PROXYSQL_PASSWORD="admin"
(-)databases/proxysql-admin/files/patch-proxysql__galera__checker (+31 lines)
Line 0 Link Here
1
--- proxysql_galera_checker.orig	2017-08-15 14:06:53 UTC
2
+++ proxysql_galera_checker
3
@@ -1,10 +1,10 @@
4
 #!/usr/local/bin/bash
5
 ## inspired by Percona clustercheck.sh
6
 
7
-if [ -f /etc/proxysql-admin.cnf ]; then
8
-  source /etc/proxysql-admin.cnf
9
+if [ -f /usr/local/etc/proxysql-admin.cnf ]; then
10
+  source /usr/local/etc/proxysql-admin.cnf
11
 else
12
-  echo "Assert! proxysql-admin configuration file :/etc/proxysql-admin.cnf does not exists, Terminating!" >> $ERR_FILE
13
+  echo "Assert! proxysql-admin configuration file :/usr/local/etc/proxysql-admin.cnf does not exists, Terminating!" >> $ERR_FILE
14
   exit 1
15
 fi
16
 #
17
@@ -50,11 +50,11 @@ WRITER_IS_READER="${4:-1}"
18
 ERR_FILE="${5:-/dev/null}"
19
 CHECK_STATUS=0
20
 #Running proxysql_node_monitor script.
21
-if [ ! -f /usr/bin/proxysql_node_monitor ] ;then
22
-  echo "`date` ERROR! Could not run /usr/bin/proxysql_node_monitor. Monitoring script does not exists in default location. Terminating" >> ${ERR_FILE}
23
+if [ ! -f /usr/local/libexec/proxysql-admin/proxysql_node_monitor ] ;then
24
+  echo "`date` ERROR! Could not run /usr/local/libexec/proxysql-admin/proxysql_node_monitor. Monitoring script does not exists in default location. Terminating" >> ${ERR_FILE}
25
   exit 1  
26
 else
27
-  /usr/bin/proxysql_node_monitor $HOSTGROUP_WRITER_ID $HOSTGROUP_READER_ID /var/lib/proxysql/proxysql_node_monitor.log
28
+  /usr/local/libexec/proxysql-admin/proxysql_node_monitor $HOSTGROUP_WRITER_ID $HOSTGROUP_READER_ID /var/log/proxysql_node_monitor.log
29
 fi
30
 
31
 
(-)databases/proxysql-admin/files/patch-proxysql__node__monitor (+34 lines)
Line 0 Link Here
1
--- proxysql_node_monitor.orig	2017-08-15 14:06:53 UTC
2
+++ proxysql_node_monitor
3
@@ -2,10 +2,10 @@
4
 # This script will assist to setup Percona XtraDB cluster ProxySQL monitoring script.
5
 #####################################################################################
6
 
7
-if [ -f /etc/proxysql-admin.cnf ]; then
8
-  source /etc/proxysql-admin.cnf
9
+if [ -f /usr/local/etc/proxysql-admin.cnf ]; then
10
+  source /usr/local/etc/proxysql-admin.cnf
11
 else
12
-  echo "`date` Assert! proxysql-admin configuration file :/etc/proxysql-admin.cnf does not exists, Terminating!" >> $ERR_FILE
13
+  echo "`date` Assert! proxysql-admin configuration file :/usr/local/etc/proxysql-admin.cnf does not exists, Terminating!" >> $ERR_FILE
14
   exit 1
15
 fi
16
 
17
@@ -41,7 +41,7 @@ mysql_exec() {
18
 
19
 # Update Percona XtraDB Cluster nodes in ProxySQL database
20
 update_cluster(){
21
-  current_hosts=(`proxysql_exec "SELECT hostname,port FROM mysql_servers where hostgroup_id in ( $WRITE_HOSTGROUP_ID, $READ_HOSTGROUP_ID )" | sed 's|\t|:|g' | tr '\n' ' '`)
22
+  current_hosts=(`proxysql_exec "SELECT hostname,port FROM mysql_servers where hostgroup_id in ( $WRITE_HOSTGROUP_ID, $READ_HOSTGROUP_ID )" | sed 's|	|:|g' | tr '\n' ' '`)
23
   wsrep_address=(`mysql_exec "SHOW STATUS LIKE 'wsrep_incoming_addresses'" | awk '{print $2}' | sed 's|,| |g'`)
24
   if [ ${#wsrep_address[@]} -eq 0 ]; then
25
     echo "`date` Alert! wsrep_incoming_addresses is empty. Terminating!" >> $ERR_FILE
26
@@ -104,7 +104,7 @@ mode_change_check(){
27
   if [[ -n "$checkwriter_hid" ]]; then
28
     proxysql_exec "UPDATE mysql_servers set hostgroup_id = $READ_HOSTGROUP_ID, comment='READ', weight=1000 WHERE comment='WRITE' and status='OFFLINE_SOFT'"
29
     check_cmd $? "Cannot update Percona XtraDB Cluster writer node in ProxySQL database, Please check proxysql credentials"
30
-    current_hosts=(`proxysql_exec "SELECT hostname,port FROM mysql_servers WHERE  status='ONLINE' and comment='READ'  ORDER BY random() LIMIT 1" | sed 's|\t|:|g' | tr '\n' ' '`)
31
+    current_hosts=(`proxysql_exec "SELECT hostname,port FROM mysql_servers WHERE  status='ONLINE' and comment='READ'  ORDER BY random() LIMIT 1" | sed 's|	|:|g' | tr '\n' ' '`)
32
     ws_ip=$(echo $current_hosts | cut -d':' -f1)
33
     ws_port=$(echo $current_hosts | cut -d':' -f2)
34
     proxysql_exec "UPDATE mysql_servers set hostgroup_id = $WRITE_HOSTGROUP_ID, comment='WRITE', weight=1000000 WHERE hostname='$ws_ip' and port=$ws_port"
(-)databases/proxysql-admin/files/proxysql-admin.conf (+7 lines)
Line 0 Link Here
1
# configuration file for newsyslog for net-snmp
2
#
3
# see newsyslog.conf(5) for details
4
#
5
# logfilename          [owner:group]    mode count size when  flags [/pid_file] [sig_num]
6
/var/log/proxysql_node_monitor.log  			644  7	   100	*     J
7
/var/log/proxysql_galera_check.log			644  7	   100	*     J
(-)databases/proxysql-admin/pkg-descr (+4 lines)
Line 0 Link Here
1
The ProxySQL Admin (proxysql-admin) solution configures
2
Percona XtraDB cluster nodes into ProxySQL.
3
4
WWW: https://github.com/percona/proxysql-admin-tool
(-)databases/proxysql-admin/pkg-message (+4 lines)
Line 0 Link Here
1
Pre-requisites before use
2
3
- ProxySQL and Cluster should be up and running
4
- MySQL client (or fork) should be installed locally
(-)databases/proxysql-admin/pkg-plist (+5 lines)
Line 0 Link Here
1
bin/proxysql-admin
2
libexec/proxysql-admin/proxysql_galera_checker
3
libexec/proxysql-admin/proxysql_node_monitor
4
etc/newsyslog.conf.d/proxysql-admin.conf
5
@sample etc/proxysql-admin.cnf.sample

Return to bug 221542