summaryrefslogtreecommitdiff
path: root/user/mariadb/mariadb.initd
blob: 4e1cf8d3e5e89dc8444e543c86b8d2cc04c1adae (plain) (blame)
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
#!/sbin/openrc-run

getconf() {
	v=$(my_print_defaults --mysqld | grep ^--$1)
	[ -z $v ] && echo $2 || echo ${v#*=}
}

retry="60"
extra_stopped_commands="setup"

user=${MYSQLD_USER:-mysql}
group=${MYSQLD_GROUP:-mysql}
default_datadir=$(getconf datadir "/var/lib/mariadb")
datadir=${MYSQLD_DATADIR:-$default_datadir}

command="/usr/bin/mysqld_safe"
command_args="--syslog --nowatch --user=$user"

depend() {
	use net
	need localmount
}

setup() {
	checkpath -d -m 1775 -o $user:$group /run/mariadb
	ebegin "Creating a new MySQL database in $datadir"
	mysql_install_db --user=$user --datadir=$datadir
	eend $?
}

start_pre() {
	pidfile=$(getconf pid-file "/run/mariadb/mysqld.pid")
	command_args="$command_args --pid-file=$pidfile"
	if [ ! -d $datadir/mysql ]; then
		eerror "Data directory '$datadir' is empty or invalid."
		eerror "Run '/etc/init.d/mariadb setup' to create new database."
	fi
}

start_post() {
	ewaitfile 10 $(getconf socket "/run/mariadb/mysqld.sock")
}

stop_pre() {
	pidfile=$(getconf pid-file "/run/mariadb/mysqld.pid")
}