Websitetemplate.org

Welcome > MySQL > MySQL: Startup Script - RHEL3

MySQL: Startup Script - RHEL3

For some inexplicable reason, installing the mysql packages from the RHEL3 CD's does not install an init script. Here's one that works - not elegant, but it works.

#!/bin/sh
# Copyright Abandoned 1996 TCX DataKonsult AB & Monty Program KB & Detron HB
# This file is public domain and comes with NO WARRANTY of any kind
# MySQL daemon start/stop script.
# Modified/customized 01/10/07 by George Toft
 
PATH=/sbin:/usr/sbin:/bin:/usr/bin:$basedir/bin
export PATH
mode=$1 # start or stop
pid_file=/var/run/mysqld/mysqld.pid
# Safeguard (relative paths, core dumps..)
cd var/lib/mysql
case "$mode" in
  'start')
    # Start daemon
    echo $echo_n "Starting MySQL"
    safe_mysqld &
    sleep 5
    # Make lock for RedHat / SuSE
    if test -w /var/lock/subsys
    then
        touch /var/lock/subsys/mysqlmanager
    fi
    ;;
 
  'stop')
    # Stop daemon. We use a signal here to avoid having to know the
    # root password.
    # The RedHat / SuSE lock directory to remove
    lock_dir=/var/lock/subsys/mysqlmanager
    # If the manager pid_file doesn't exist, try the server's
    if test ! -s "$pid_file"
    then
        pid_file=$server_pid_file
        lock_dir=/var/lock/subsys/mysql
    fi
    if test -s "$pid_file"
    then
        mysqlmanager_pid=`cat $pid_file`
        echo $echo_n "Shutting down MySQL"
        kill $mysqlmanager_pid
        # mysqlmanager should remove the pid_file when it exits, so wait for it.
        sleep 5
        # delete lock for RedHat / SuSE
        if test -f $lock_dir
        then
            rm -f $lock_dir
        fi
    fi
    ;;
 
  'restart')
# Stop the service and regardless of whether it was # running or not, start it again. $0 stop $other_args $0 start $other_args ;;   *) # usage echo "Usage: $0 {start|stop|restart} [ MySQL server options ]" exit 1 ;; esac

Content Copyright 2003-2014 George Toft