I had to figure out how to setup mySQL Proxy to run as a daemon (system service).
The original information came from this page and has been slightly modified.
It is assumed that mySQL Proxy has been installed and the mysql-proxy executable is located at /usr/local/sbin/mysql-proxy.
The first file is the init.d launch script:
/etc/init.d/mysql-proxy
#!/bin/sh # # mysql-proxy This script starts and stops the mysql-proxy daemon # # chkconfig: - 78 30 # processname: mysql-proxy # description: mysql-proxy is a proxy daemon to mysql # Source function library. . /etc/rc.d/init.d/functions PROXY_PATH="/usr/local/sbin" prog="mysql-proxy" # Source networking configuration. . /etc/sysconfig/network # Check that networking is up. [ ${NETWORKING} = "no" ] && exit 0 # Set default mysql-proxy configuration. PROXY_OPTIONS="--daemon" PROXY_PID=/var/run/mysql-proxy.pid # Source mysql-proxy configuration. if [ -f /etc/sysconfig/mysql-proxy ] ; then . /etc/sysconfig/mysql-proxy fi PATH=$PATH:/usr/bin:/usr/local/bin:$PROXY_PATH # By default it's all good RETVAL=0 # See how we were called. case "$1" in start) # Start daemon. echo -n $"Starting $prog: " daemon $NICELEVEL $PROXY_PATH/mysql-proxy $PROXY_OPTIONS --pid-file $PROXY_PID RETVAL=$? echo if [ $RETVAL = 0 ]; then touch /var/lock/subsys/mysql-proxy fi ;; stop) # Stop daemons. echo -n $"Stopping $prog: " killproc $prog RETVAL=$? echo if [ $RETVAL = 0 ]; then rm -f /var/lock/subsys/mysql-proxy rm -f $PROXY_PID fi ;; restart) $0 stop sleep 3 $0 start ;; condrestart) [ -e /var/lock/subsys/mysql-proxy ] && $0 restart ;; status) status mysql-proxy RETVAL=$? ;; *) echo "Usage: $0 {start|stop|restart|status|condrestart}" RETVAL=1 ;; esac exit $RETVAL
The launch script will either use the default configuration or read it from the file /etc/sysconfig/mysql-proxy if it exists.
To set mysql-proxy parameters create:
/etc/sysconfig/mysql-proxy
# Options to mysql-proxy # do not remove --daemon PROXY_OPTIONS=" --daemon --proxy-backend-addresses=127.0.0.1:3306 --proxy-backend-addresses=127.0.0.1:3307 --proxy-lua-script=load-balancing.lua"