Profile
Pastes: 71937
Members: 1384

Paste

Plain view | Edit code: here. | Add this to your website. | Report abuse.

Short URL: http://goo.gl/abGcn

Pasted as Plain Text by dscrd on Sunday, January 27th, 2013 11:51pm ( 1 year ago )

  1. #!/bin/bash
  2.  
  3. # general config
  4. . /etc/rc.conf
  5. . /etc/rc.d/functions
  6.  
  7. getPID() {
  8.    echo $(pgrep -u mysql mysqld 2>/dev/null);
  9. }
  10.  
  11. case "$1" in
  12.   start)
  13.     stat_busy "Starting MySQL Server"
  14.     [ ! -d /run/mysqld ] && install -d -g mysql -o mysql /run/mysqld &>/dev/null
  15.     if [ -z "$(getPID)" ]; then
  16.        /usr/bin/mysqld_safe --user=mysql &>/dev/null &
  17.       if [ $? -gt 0 ]; then
  18.         stat_fail
  19.         exit 1
  20.       else
  21.         timeo=30
  22.         while [ $timeo -gt 0 ]; do
  23.           response=`/usr/bin/mysqladmin -uUNKNOWN_USER ping 2>&1` && break
  24.           echo "$response" | grep -q "mysqld is alive" && break
  25.           sleep 1
  26.           let timeo=${timeo}-1
  27.         done
  28.         if [ $timeo -eq 0 ]; then
  29.           stat_fail
  30.           exit 1
  31.         else
  32.           echo $(getPID) > /run/mysqld/mysqld.pid
  33.           add_daemon mysqld
  34.           stat_done
  35.         fi
  36.       fi
  37.     else
  38.       stat_fail
  39.       exit 1
  40.     fi
  41.     ;;
  42.  
  43.   stop)
  44.     stat_busy "Stopping MySQL Server"
  45.     if [ ! -z "$(getPID)" ]; then
  46.       timeo=30
  47.       kill $(getPID) &> /dev/null
  48.       if [ $? -gt 0 ]; then
  49.         stat_fail
  50.         exit 1
  51.       fi
  52.       while [ ! -z "$(getPID)" -a $timeo -gt 0 ]; do
  53.         sleep 1
  54.         let timeo=${timeo}-1
  55.       done
  56.       if [ -z "$(getPID)" ]; then
  57.         rm -f /run/mysqld/mysqld.pid &>/dev/null
  58.         rm_daemon mysqld
  59.         stat_done
  60.       else
  61.         stat_fail
  62.         exit 1
  63.       fi
  64.     else
  65.       stat_fail
  66.       exit 1
  67.     fi
  68.     ;;
  69.  
  70.   restart)
  71.     $0 stop
  72.     $0 start
  73.     ;;
  74.   *)
  75.     echo "usage: $0 {start|stop|restart}"
  76. esac
  77. exit 0

Revise this Paste
Your Name:
Code Language:
 
Security Image:
Text seen in Image:
Comments

Nothing has been added as yet. Post a comment.