#!@l_prefix@/lib/openpkg/bash @l_prefix@/etc/rc
##
##  rc.mysql -- Run-Command for MySQL Database
##

%config
    mysql_enable="yes"
    mysql_pwd_file=@l_prefix@/etc/mysql/my.pwd
    mysql_cnf_file=@l_prefix@/etc/mysql/my.cnf
    mysql_log_prolog="true"
    mysql_log_epilog="true"
    mysql_log_numfiles="10"
    mysql_log_minsize="1M"
    mysql_log_complevel="9"
    #
    # same files as in my.cnf
    mysql_pid_file=@l_prefix@/var/mysql/mysqld.pid
    mysql_log_err=@l_prefix@/var/mysql/mysqld.err
    mysql_log_common=@l_prefix@/var/mysql/common.log
    mysql_log_update=@l_prefix@/var/mysql/update.log

%start -p 200 -u @l_rusr@
    opServiceEnabled mysql || exit 0
    cd @l_prefix@
    @l_prefix@/bin/safe_mysqld >/dev/null 2>&1 \
        --mysqld=@mysqld@ \
        --pid-file="$mysql_pid_file" \
        --err-log="$mysql_log_err" &

%stop -p 200 -u @l_rusr@
    opServiceEnabled mysql || exit 0
    @l_prefix@/bin/mysqladmin \
        --defaults-extra-file=${mysql_pwd_file} \
        shutdown

%restart -u @l_rusr@
    opServiceEnabled mysql || exit 0
    cd @l_prefix@
    @l_prefix@/bin/mysqladmin \
        --defaults-extra-file=${mysql_pwd_file} \
        shutdown
    @l_prefix@/bin/safe_mysqld >/dev/null 2>&1 \
        --mysqld=@mysqld@ \
        --pid-file="$mysql_pid_file" \
        --err-log="$mysql_log_err" &

%daily -u @l_rusr@
    opServiceEnabled mysql || exit 0
    shtool rotate -f \
        -n${mysql_log_numfiles} -s${mysql_log_minsize} -d \
        -z${mysql_log_complevel} -o@l_rusr@ -g@l_rgrp@ -m644 \
        -P "${mysql_log_prolog}" \
        -E "@l_prefix@/bin/mysqladmin \
            --defaults-extra-file=${mysql_pwd_file} \
            flush-logs ; ${mysql_log_epilog}" \
        ${mysql_log_common} \
        ${mysql_log_update} \
        ${mysql_log_err}
