#!/bin/dash
# mariadb database server
# Description: MariaDB Database Server
#
# Note: must run "mysqladmin -u root password" to set administrator
# password when running for the first time. Otherwise security problem.
#

DBUSER=mysql
SOCKDIR=/run/mysqld
LOGFILE=/var/log/mariadb.log

start() {
	# make sure sockdir exist and correctly owned
	install -v -m755 -o mysql -g mysql -d $SOCKDIR &&
	mysqld_safe --user=$DBUSER 2>&1 >> $LOGFILE &
}

stop() {
	killall mysqld 2> /dev/null
}

is_up() {
	killall -0 mysqld 2> /dev/null
}

case "$1" in
	start|restart|reload)
		stop
		sleep 1
		start
		;;

	stop)
		stop
		;;
		
	status)
		is_up && echo "mariadb is running." || echo "mariadb is stopped."
		;;		
		
esac
