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

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

now these scripts need to be run from gsdl3 home dir, and source setup.sh will be run if gsdl3home not defined

  • 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
50 exit;
51fi
52
53basedir=
54
55# The following variables are only set for letting mysql.server find things.
56
57
58# Set some defaults
59datadir=$GSDL3HOME/packages/mysql/var
60pid_file=
61if test -z "$basedir"
62then
63 basedir=$GSDL3HOME/packages/mysql
64 bindir=$GSDL3HOME/packages/mysql/bin
65else
66 bindir="$basedir/bin"
67fi
68
69PATH=/sbin:/usr/sbin:/bin:/usr/bin:$basedir/bin
70export PATH
71
72mode=$1 # start or stop
73
74parse_arguments() {
75 for arg do
76 case "$arg" in
77 --basedir=*) basedir=`echo "$arg" | sed -e 's/^[^=]*=//'` ;;
78 --datadir=*) datadir=`echo "$arg" | sed -e 's/^[^=]*=//'` ;;
79 --pid-file=*) pid_file=`echo "$arg" | sed -e 's/^[^=]*=//'` ;;
80 esac
81 done
82}
83
84# Get arguments from the my.cnf file,
85# groups [mysqld] [mysql_server] and [mysql.server]
86if test -x ./bin/my_print_defaults
87then
88 print_defaults="./bin/my_print_defaults"
89elif test -x $bindir/my_print_defaults
90then
91 print_defaults="$bindir/my_print_defaults"
92elif test -x $bindir/mysql_print_defaults
93then
94 print_defaults="$bindir/mysql_print_defaults"
95else
96 # Try to find basedir in /etc/my.cnf
97 conf=/etc/my.cnf
98 print_defaults=
99 if test -r $conf
100 then
101 subpat='^[^=]*basedir[^=]*=\(.*\)$'
102 dirs=`sed -e "/$subpat/!d" -e 's//\1/' $conf`
103 for d in $dirs
104 do
105 d=`echo $d | sed -e 's/[ ]//g'`
106 if test -x "$d/bin/my_print_defaults"
107 then
108 print_defaults="$d/bin/my_print_defaults"
109 break
110 fi
111 if test -x "$d/bin/mysql_print_defaults"
112 then
113 print_defaults="$d/bin/mysql_print_defaults"
114 break
115 fi
116 done
117 fi
118
119 # Hope it's in the PATH ... but I doubt it
120 test -z "$print_defaults" && print_defaults="my_print_defaults"
121fi
122
123#
124# Set pid file if not given
125#
126if test -z "$pid_file"
127then
128 pid_file=$datadir/`/bin/hostname`.pid
129else
130 case "$pid_file" in
131 /* ) ;;
132 * ) pid_file="$datadir/$pid_file" ;;
133 esac
134fi
135
136#
137# Test if someone changed datadir; In this case we should also read the
138# default arguments from this directory
139#
140
141extra_args=""
142if test "$datadir" != "$GSDL3HOME/mysql/var"
143then
144 extra_args="-e $datadir/my.cnf"
145fi
146
147parse_arguments `$print_defaults $extra_args mysqld mysql_server mysql.server`
148
149# Safeguard (relative paths, core dumps..)
150cd $basedir
151
152case "$mode" in
153 'start')
154 # Start daemon
155
156 if test -x $bindir/mysqld_safe
157 then
158 # Give extra arguments to mysqld with the my.cnf file. This script may
159 # be overwritten at next upgrade.
160 $bindir/mysqld_safe --datadir=$datadir --pid-file=$pid_file &
161 # Make lock for RedHat / SuSE
162 if test -w /var/lock/subsys
163 then
164 touch /var/lock/subsys/mysql
165 fi
166 else
167 echo "Can't execute $bindir/mysqld_safe from dir $basedir"
168 fi
169 ;;
170
171 'stop')
172 # Stop daemon. We use a signal here to avoid having to know the
173 # root password.
174 if test -s "$pid_file"
175 then
176 mysqld_pid=`cat $pid_file`
177 echo "Killing mysqld with pid $mysqld_pid"
178 kill $mysqld_pid
179 # mysqld should remove the pid_file when it exits, so wait for it.
180
181 sleep 1
182 while [ -s $pid_file -a "$flags" != aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa ]
183 do
184 [ -z "$flags" ] && echo "Wait for mysqld to exit\c" || echo ".\c"
185 flags=a$flags
186 sleep 1
187 done
188 if [ -s $pid_file ]
189 then echo " gave up waiting!"
190 elif [ -n "$flags" ]
191 then echo " done"
192 fi
193 # delete lock for RedHat / SuSE
194 if test -f /var/lock/subsys/mysql
195 then
196 rm -f /var/lock/subsys/mysql
197 fi
198 else
199 echo "No mysqld pid file found. Looked for $pid_file."
200 fi
201 ;;
202
203 'restart')
204 # Stop the service and regardless of whether it was
205 # running or not, start it again.
206 $0 stop
207 $0 start
208 ;;
209
210 *)
211 # usage
212 echo "Usage: $0 start|stop|restart"
213 exit 1
214 ;;
215esac
Note: See TracBrowser for help on using the repository browser.