Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- # autossh init file for mysql perso
- #
- # chkconfig: - 81 81
- # description: autossh port forward mysql 3307 to 3306
- #
- # processname: /usr/bin/autossh
- # pidfile: /var/run/autossh_mysql_perso.pid
- ### BEGIN INIT INFO
- # Provides: autossh
- # Required-Start: $local_fs $network
- # Required-Stop: $local_fs $network
- # Should-Start:
- # Should-Stop:
- # Default-Start:
- # Default-Stop:
- # Short-Description: start and stop autossh to mysql server
- # Description: autossh tunnel to mysql server
- ### END INIT INFO
- RETVAL=0
- prog="autossh"
- binary=/usr/bin/autossh
- pidfile=/var/run/autossh_mysql_perso.pid
- start() {
- [ -x $binary ] || exit 5
- echo -n $"Starting $prog: "
- autossh -M 0 -q -f -N -o "Port 52001" -o "ServerAliveInterval 60" -o "ServerAliveCountMax 3" -L 3307:localhost:3306 host.domain.tld
- RETVAL=$?
- if [ $RETVAL -eq 0 ]; then
- touch /var/lock/subsys/autossh_mysql_perso
- ps -eaf | grep -v grep | grep "autossh" | grep "3307:localhost:3306" | awk '{print $2}' >${pidfile}
- fi
- echo
- return $RETVAL
- }
- stop() {
- echo -n $"Stopping $prog: "
- killproc -p $pidfile $binary
- RETVAL=$?
- [ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/autossh_mysql_perso
- echo
- return $RETVAL
- }
- restart(){
- stop
- start
- }
- condrestart(){
- [ -e /var/lock/subsys/autossh_mysql_perso ] && restart
- return 0
- }
- case "$1" in
- start)
- start
- RETVAL=$?
- ;;
- stop)
- stop
- RETVAL=$?
- ;;
- restart)
- restart
- RETVAL=$?
- ;;
- condrestart|try-restart)
- condrestart
- RETVAL=$?
- ;;
- status)
- status autossh
- RETVAL=$?
- ;;
- *)
- echo $"Usage: $0 {start|stop|status|restart|condrestart}"
- RETVAL=2
- esac
- exit $RETVAL
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement