# mariadb
#
# starts mariadb

description	"Start mariadb"
author		"Arjan Bouter <abouter@sourcemage.org>"

start on mounted-remotefs

pre-start script
  . /etc/sysconfig/mariadb
  [[ -d "$DATA_DIR" ]] || mkdir -p "$DATA_DIR"
end script

script
  . /etc/sysconfig/mariadb
  # set some defaults for mariadb.server
  datadir="${DATA_DIR}"
  if [[ -z "$basedir" ]]; then
    basedir=/usr
    bindir=/usr/bin
  else
    bindir="${basedir}/bin"
  fi
  export PATH="/sbin:/usr/sbin:/bin:/usr/bin:$bindir"
  if [[ -z pid_file ]]; then
    pid_file="${datadir}/$(hostname).pid"  
  else
    case "$pid_file" in
      /* ) ;;
      * ) pid_file="${datadir}/${pid_file}" ;;
    esac
  fi
  exec $bindir/mysqld_safe --datadir="${datadir}"
end script

pre-stop script
  . /etc/sysconfig/mariadb
  HOSTNAME=$(hostname)
  kill $(cat "${DATADIR}/${HOSTNAME}.pid")
end script
