summaryrefslogtreecommitdiff
path: root/package/mariadb/S97mysqld
blob: 62357fa8c489bec157a9d75ca57add58f0d517e7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#!/bin/sh
#
# mysql
#

MYSQL_LIB="/var/lib/mysql"
MYSQL_RUN="/run/mysql"
MYSQL_PID="$MYSQL_RUN/mysqld.pid"
MYSQL_BIN="/usr/bin"

wait_for_ready() {
	WAIT_DELAY=5
	while [ $WAIT_DELAY -gt 0 ]; do
		if $MYSQL_BIN/mysqladmin ping > /dev/null 2>&1; then
			return 0
		fi
		sleep 1
		: $((WAIT_DELAY -= 1))
	done
	return 1
}

start() {
	if [ `ls -1 $MYSQL_LIB | wc -l` = 0 ] ; then
		printf "Creating mysql system tables ... "
		$MYSQL_BIN/mysql_install_db --basedir=/usr --user=mysql \
			--datadir=$MYSQL_LIB > /dev/null 2>&1
		if [ $? != 0 ]; then
			echo "FAIL"
			exit 1
		fi
		echo "OK"
	fi

	# mysqld runs as user mysql, but /run is only writable by root
	# so create a subdirectory for mysql.
	install -d -o mysql -g root -m 0755 $MYSQL_RUN

	# We don't use start-stop-daemon because mysqld has its own
	# wrapper script.
	printf "Starting mysql ... "
	$MYSQL_BIN/mysqld_safe --pid-file=$MYSQL_PID --user=mysql \
		> /dev/null 2>&1 &
	wait_for_ready
	[ $? = 0 ] && echo "OK" || echo "FAIL"
}

stop() {
	printf "Stopping mysql ... "
	if [ -f $MYSQL_PID ]; then
		kill `cat $MYSQL_PID` > /dev/null 2>&1
		[ $? = 0 ] && echo "OK" || echo "FAIL"
	else
		echo "FAIL"
	fi
}

restart() {
	stop
	sleep 1
	start
}

case "$1" in
  start)
	start
	;;
  stop)
	stop
	;;
  restart)
	restart
	;;
  *)
	echo "Usage: $0 {start|stop|restart}"
	;;
esac