source: trunk/gsdl3/gs3-mysql-server.sh@ 6915

Last change on this file since 6915 was 6915, checked in by kjdon, 20 years ago

oops, last commit I left in an exit; that wasn't supposed to be there

  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
File size: 5.6 KB
Line 
1#!/bin/sh
2# Copyright Abandoned 1996 TCX DataKonsult AB & Monty Program KB & Detron HB
3# This file is public domain and comes with NO WARRANTY of any kind
4
5# MySQL daemon start/stop script.
6
7# Usually this is put in /etc/init.d (at least on machines SYSV R4 based
8# systems) and linked to /etc/rc3.d/S99mysql and /etc/rc0.d/K01mysql.
9# When this is done the mysql server will be started when the machine is
10# started and shut down when the systems goes down.
11
12# Comments to support chkconfig on RedHat Linux
13# chkconfig: 2345 90 20
14# description: A very fast and reliable SQL database engine.
15
16# Comments to support LSB init script conventions
17### BEGIN INIT INFO
18# Provides: mysql
19# Required-Start: $local_fs $network $remote_fs
20# Required-Stop: $local_fs $network $remote_fs
21# Default-Start: 2 3 4 5
22# Default-Stop: 0 1 6
23# Short-Description: start and stop MySQL
24# Description: MySQL is a very fast and reliable SQL database engine.
25### END INIT INFO
26
27# If you install MySQL on some other places than /home/grbuchan/working/gsdl3/packages/mysql, then you
28# have to do one of the following things for this script to work:
29#
30# - Run this script from within the MySQL installation directory
31# - Create a /etc/my.cnf file with the following information:
32# [mysqld]
33# basedir=<path-to-mysql-installation-directory>
34# - Add the above to any other configuration file (for example ~/.my.ini)
35# and copy my_print_defaults to /usr/bin
36# - Add the path to the mysql-installation-directory to the basedir variable
37# below.
38#
39# If you want to affect other MySQL variables, you should make your changes
40# in the /etc/my.cnf, ~/.my.cnf or other MySQL configuration files.
41
42if [ ! -f gs3-setup.sh ]; then
43 echo "You must run this script from within the Greenstone home directory"
44 exit 1
45fi
46
47#check that GSDL3HOME is set
48if test -z "$GSDL3HOME" ; then
49 source gs3-setup.sh
50fi
51
52basedir=
53
54# The following variables are only set for letting mysql.server find things.
55
56
57# Set some defaults
58datadir=$GSDL3HOME/packages/mysql/var
59pid_file=
60if test -z "$basedir"
61then
62 basedir=$GSDL3HOME/packages/mysql
63 bindir=$GSDL3HOME/packages/mysql/bin
64else
65 bindir="$basedir/bin"
66fi
67
68PATH=/sbin:/usr/sbin:/bin:/usr/bin:$basedir/bin
69export PATH
70
71mode=$1 # start or stop
72
73parse_arguments() {
74 for arg do
75 case "$arg" in
76 --basedir=*) basedir=`echo "$arg" | sed -e 's/^[^=]*=//'` ;;
77 --datadir=*) datadir=`echo "$arg" | sed -e 's/^[^=]*=//'` ;;
78 --pid-file=*) pid_file=`echo "$arg" | sed -e 's/^[^=]*=//'` ;;
79 esac
80 done
81}
82
83# Get arguments from the my.cnf file,
84# groups [mysqld] [mysql_server] and [mysql.server]
85if test -x ./bin/my_print_defaults
86then
87 print_defaults="./bin/my_print_defaults"
88elif test -x $bindir/my_print_defaults
89then
90 print_defaults="$bindir/my_print_defaults"
91elif test -x $bindir/mysql_print_defaults
92then
93 print_defaults="$bindir/mysql_print_defaults"
94else
95 # Try to find basedir in /etc/my.cnf
96 conf=/etc/my.cnf
97 print_defaults=
98 if test -r $conf
99 then
100 subpat='^[^=]*basedir[^=]*=\(.*\)$'
101 dirs=`sed -e "/$subpat/!d" -e 's//\1/' $conf`
102 for d in $dirs
103 do
104 d=`echo $d | sed -e 's/[ ]//g'`
105 if test -x "$d/bin/my_print_defaults"
106 then
107 print_defaults="$d/bin/my_print_defaults"
108 break
109 fi
110 if test -x "$d/bin/mysql_print_defaults"
111 then
112 print_defaults="$d/bin/mysql_print_defaults"
113 break
114 fi
115 done
116 fi
117
118 # Hope it's in the PATH ... but I doubt it
119 test -z "$print_defaults" && print_defaults="my_print_defaults"
120fi
121
122#
123# Set pid file if not given
124#
125if test -z "$pid_file"
126then
127 pid_file=$datadir/`/bin/hostname`.pid
128else
129 case "$pid_file" in
130 /* ) ;;
131 * ) pid_file="$datadir/$pid_file" ;;
132 esac
133fi
134
135#
136# Test if someone changed datadir; In this case we should also read the
137# default arguments from this directory
138#
139
140extra_args=""
141if test "$datadir" != "$GSDL3HOME/mysql/var"
142then
143 extra_args="-e $datadir/my.cnf"
144fi
145
146parse_arguments `$print_defaults $extra_args mysqld mysql_server mysql.server`
147
148# Safeguard (relative paths, core dumps..)
149cd $basedir
150
151case "$mode" in
152 'start')
153 # Start daemon
154
155 if test -x $bindir/mysqld_safe
156 then
157 # Give extra arguments to mysqld with the my.cnf file. This script may
158 # be overwritten at next upgrade.
159 $bindir/mysqld_safe --datadir=$datadir --pid-file=$pid_file &
160 # Make lock for RedHat / SuSE
161 if test -w /var/lock/subsys
162 then
163 touch /var/lock/subsys/mysql
164 fi
165 else
166 echo "Can't execute $bindir/mysqld_safe from dir $basedir"
167 fi
168 ;;
169
170 'stop')
171 # Stop daemon. We use a signal here to avoid having to know the
172 # root password.
173 if test -s "$pid_file"
174 then
175 mysqld_pid=`cat $pid_file`
176 echo "Killing mysqld with pid $mysqld_pid"
177 kill $mysqld_pid
178 # mysqld should remove the pid_file when it exits, so wait for it.
179
180 sleep 1
181 while [ -s $pid_file -a "$flags" != aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa ]
182 do
183 [ -z "$flags" ] && echo "Wait for mysqld to exit\c" || echo ".\c"
184 flags=a$flags
185 sleep 1
186 done
187 if [ -s $pid_file ]
188 then echo " gave up waiting!"
189 elif [ -n "$flags" ]
190 then echo " done"
191 fi
192 # delete lock for RedHat / SuSE
193 if test -f /var/lock/subsys/mysql
194 then
195 rm -f /var/lock/subsys/mysql
196 fi
197 else
198 echo "No mysqld pid file found. Looked for $pid_file."
199 fi
200 ;;
201
202 'restart')
203 # Stop the service and regardless of whether it was
204 # running or not, start it again.
205 $0 stop
206 $0 start
207 ;;
208
209 *)
210 # usage
211 echo "Usage: $0 start|stop|restart"
212 exit 1
213 ;;
214esac
Note: See TracBrowser for help on using the repository browser.