Subject: mysqld rc.d script
To: NetBSD Packages <tech-pkg@netbsd.org>
From: Xavier HUMBERT <xavier@xavhome.fr.eu.org>
List: tech-pkg
Date: 02/10/2002 11:41:20
I tried to use th "mysql.server" which is installed in
/usr/pkg/share/mysql

It is pure RedHatism, God bless me !

The main problem is that the database is launched by the wrapper
safe_mysqld. And that, iirc, a clean shutdown is not issued to the
database, when shutting down the system.


So I wrote a NetBSD style rc script :

Thanks for the comments.


=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-==-=-=-=-=-=-=-=--==-=


If you dont'have a mysql user, you're required to create one :

---> /etc/group:
mysql:*:99:

---> /etc/master.passwd:
mysql:*:99:99::0:0:& Group:/var/mysql:/sbin/nologin



---> In rc.conf
mysqld=YES              mysqld_flags="--user=mysql"


Note that you *must* use a custom start command, since for obscure
reason safe_mysqld needs to be launched explicitely in background.

---> In rc.d/mysqld
#!/bin/sh
#
# $NetBSD: mysql,v 1.0 2002/02/10 01:44:37 xavier Exp $
#

# PROVIDE: mysqld
# REQUIRE: DAEMON LOGIN mountall
# KEYWORD: shutdown

. /etc/rc.subr

name="mysqld"
rcvar=$name
command="/usr/pkg/bin/safe_mysqld"
pidfile="/var/mysql/`hostname`.pid"
start_cmd="mysqld_start"
restart_cmd="mysqld_restart"
stop_cmd="mysqld_stop"
status_cmd="mysqld_status"
required_files="/var/mysql/mysql/host.frm"


mysqld_status()
{
    check_pidfile $pidfile $name
    if [ -n "$_pid" ]; then
        echo "${name} is running as pid $_pid."
    else
        echo "${name} is not running."
        return 1
    fi
}

mysqld_start()
{
    echo "Starting mysqld"
    ${command} ${mysqld_flags} &
}

mysqld_restart()
{
    check_pidfile $pidfile $name
    mysqld_stop
    echo "Waiting for shutdown to complete"
    wait_for_pids $_pid
    mysqld_start
}

mysqld_stop()
{
    echo "Shutting down mysqld"
    check_pidfile $pidfile $name
    if [ -n "$_pid" ]; then
        kill -SIGTERM $_pid
    fi
}

load_rc_config $name
run_rc_command "$1"


-- 
Xav
http://www.freetibet.org
http://www.tibet.fr/