Advertisement
teuk

autossh mysql

Mar 18th, 2017
242
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.90 KB | None | 0 0
  1. #!/bin/bash
  2. # autossh init file for mysql perso
  3. #
  4. # chkconfig: - 81 81
  5. # description: autossh port forward mysql 3307 to 3306
  6. #
  7. # processname: /usr/bin/autossh
  8. # pidfile: /var/run/autossh_mysql_perso.pid
  9.  
  10. ### BEGIN INIT INFO
  11. # Provides: autossh
  12. # Required-Start: $local_fs $network
  13. # Required-Stop: $local_fs $network
  14. # Should-Start:
  15. # Should-Stop:
  16. # Default-Start:
  17. # Default-Stop:
  18. # Short-Description: start and stop autossh to mysql server
  19. # Description: autossh tunnel to mysql server
  20. ### END INIT INFO
  21.  
  22. RETVAL=0
  23. prog="autossh"
  24. binary=/usr/bin/autossh
  25. pidfile=/var/run/autossh_mysql_perso.pid
  26.  
  27. start() {
  28.         [ -x $binary ] || exit 5
  29.         echo -n $"Starting $prog: "
  30.         autossh -M 0 -q -f -N -o "Port 52001" -o "ServerAliveInterval 60" -o "ServerAliveCountMax 3" -L 3307:localhost:3306 host.domain.tld
  31.         RETVAL=$?
  32.         if [ $RETVAL -eq 0 ]; then
  33.                 touch /var/lock/subsys/autossh_mysql_perso
  34.                 ps -eaf | grep -v grep | grep "autossh" | grep "3307:localhost:3306" | awk '{print $2}' >${pidfile}
  35.         fi
  36.         echo
  37.         return $RETVAL
  38. }
  39.  
  40. stop() {
  41.         echo -n $"Stopping $prog: "
  42.         killproc -p $pidfile $binary
  43.         RETVAL=$?
  44.         [ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/autossh_mysql_perso
  45.         echo
  46.         return $RETVAL
  47. }
  48.  
  49. restart(){
  50.         stop
  51.         start
  52. }
  53.  
  54. condrestart(){
  55.     [ -e /var/lock/subsys/autossh_mysql_perso ] && restart
  56.     return 0
  57. }
  58.  
  59. case "$1" in
  60.   start)
  61.         start
  62.         RETVAL=$?
  63.         ;;
  64.   stop)
  65.         stop
  66.         RETVAL=$?
  67.         ;;
  68.   restart)
  69.         restart
  70.         RETVAL=$?
  71.         ;;
  72.   condrestart|try-restart)
  73.         condrestart
  74.         RETVAL=$?
  75.         ;;
  76.   status)
  77.         status autossh
  78.         RETVAL=$?
  79.         ;;
  80.   *)
  81.         echo $"Usage: $0 {start|stop|status|restart|condrestart}"
  82.         RETVAL=2
  83. esac
  84.  
  85. exit $RETVAL
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement