summaryrefslogtreecommitdiffstats
path: root/wrappers
diff options
context:
space:
mode:
authorRich Megginson <rmeggins@redhat.com>2007-03-16 20:29:57 +0000
committerRich Megginson <rmeggins@redhat.com>2007-03-16 20:29:57 +0000
commit91f0db2c73c5f207fa9a68a3282a4ab5c422643a (patch)
treec472de5b0a4b1e801917c81482c0f03512e80044 /wrappers
parent30ef36de95df4bedcd41a0470cccb45a553ba2c4 (diff)
downloadds-91f0db2c73c5f207fa9a68a3282a4ab5c422643a.tar.gz
ds-91f0db2c73c5f207fa9a68a3282a4ab5c422643a.tar.xz
ds-91f0db2c73c5f207fa9a68a3282a4ab5c422643a.zip
Resolves: bug 232684
Description: need initscripts for Solaris Reviewed by: nhosoi (Thanks!) Fix Description: I was able to mostly use the linux initscript. The biggest issue was that Solaris does not support bash for init scripts, so I had to convert all of the bash-isms to just use plain old Bourne shell syntax. I removed the grep for the pids and just used kill -0, so I don't need the pids list or pidof anymore. Solaris mounts /var/run in tmpfs (i.e. memory disk) which is removed upon reboot, so we have to create and set permission on /var/run if it doesn't exist. Solaris also doesn't provide a library of useful shell functions, so I had to define success() and failure() if they don't exist. Platforms tested: Solaris 9 Flag day: no Doc: Yes - we will need to document the init scripts.
Diffstat (limited to 'wrappers')
-rw-r--r--wrappers/initscript.in105
1 files changed, 74 insertions, 31 deletions
diff --git a/wrappers/initscript.in b/wrappers/initscript.in
index d1ffbf29..6b0cdb12 100644
--- a/wrappers/initscript.in
+++ b/wrappers/initscript.in
@@ -1,4 +1,4 @@
-#!/bin/bash
+#!/bin/sh
#
# @package_name@ This starts and stops @package_name@
#
@@ -11,24 +11,66 @@
#
# Source function library.
+if [ -f /etc/rc.d/init.d/functions ] ; then
. /etc/rc.d/init.d/functions
+fi
# Source networking configuration.
+if [ -f /etc/sysconfig/network ] ; then
. /etc/sysconfig/network
+fi
# Check that networking is up.
-if [ ${NETWORKING} = "no" ]
+if [ "${NETWORKING}" = "no" ]
then
echo "Networking is down"
exit 0
fi
+# failure and success are not defined on some platforms
+type failure > /dev/null 2>&1 || {
+failure()
+{
+ echo " FAILED\c"
+}
+}
+
+type success > /dev/null 2>&1 || {
+success()
+{
+ echo " SUCCESS\c"
+}
+}
-exec="@sbindir@/ns-slapd"
+# On Solaris /var/run is in tmpfs and gets wiped out upon reboot
+# we have to recreate the /var/run/@package_name@ directory
+# We also have to make sure that the directory is writable
+# by the directory server process
+# the argument to this function is the server instance directory,
+# which must have a dse.ldif file in it
+fix_pid_dir_ownership()
+{
+ if [ ! -d $piddir ] ; then
+ mkdir -p $piddir
+ owner=`grep \^nsslapd-localuser $1/dse.ldif | awk '{print $2}'`
+ if [ -n "$owner" ] ; then
+ chown $owner $piddir
+ chmod 700 $piddir
+ fi
+ fi
+}
+
+baseexec="ns-slapd"
+exec="@sbindir@/$baseexec"
prog="@package_name@"
# Lockfile
-lockfile="@localstatedir@/lock/subsys/@package_name@"
+if [ -d "@localstatedir@/lock/subsys" ] ; then
+ lockfile="@localstatedir@/lock/subsys/@package_name@"
+else
+ lockfile="@localstatedir@/lock/@package_name@/lock"
+fi
# PID directory
piddir="@localstatedir@/run/@package_name@"
+
# Instance basedir
instbase="@instconfigdir@"
@@ -38,13 +80,11 @@ instbase="@instconfigdir@"
umask 077
-pids=$(pidof $exec)
-
INSTANCES=""
for FILE in `/bin/ls -d $instbase/slapd-* 2>/dev/null`; do
if [ -d "$FILE" ] ; then
- inst=$(echo "$FILE" | sed -e "s|$instbase/slapd-||")
+ inst=`echo "$FILE" | sed -e "s|$instbase/slapd-||"`
INSTANCES="$INSTANCES $inst"
fi
done
@@ -56,7 +96,7 @@ if [ -n "$2" ]; then
fi
done
if [ "$2" != "$INSTANCES" ]; then
- echo -n "$2 is an invalid @package_name@ instance"
+ echo "$2 is an invalid @package_name@ instance\c"
failure; echo
exit 1
fi
@@ -64,13 +104,14 @@ fi
start() {
if [ -n "$INSTANCES" ]; then
- export LD_LIBRARY_PATH=@libdir@/@package_name@:@nss_libdir@
+ LD_LIBRARY_PATH=@libdir@/@package_name@:@nss_libdir@
+ export LD_LIBRARY_PATH
echo "Starting $prog: "
# Start every slapd instance that isn't already running
errors=0
successes=0
for instance in $INSTANCES; do
- echo -n " $instance..."
+ echo " $instance...\c"
# the server creates pidfile and writes the pid to it when it is fully
# started and available to serve clients
pidfile=$piddir/slapd-$instance.pid
@@ -79,15 +120,15 @@ start() {
# die a horrible death (e.g. shared lib problem, oom, etc.)
startpidfile=$piddir/slapd-$instance.startpid
server_running=0
- if [ -e $pidfile ]; then
- pid=$(cat $pidfile)
- if [ $(echo "$pids" | grep -c $pid) -ge 1 ]; then
- echo -n " already running"
+ if [ -f $pidfile ]; then
+ pid=`cat $pidfile`
+ if kill -0 $pid > /dev/null 2>&1 ; then
+ echo " already running\c"
success; echo
- let successes=successes+1
+ successes=`expr $successes + 1`
server_running=1
else
- echo -n " not running, but pid file exists - attempt to start anyway..."
+ echo " not running, but pid file exists - attempt to start anyway...\c"
rm -f $pidfile
fi
fi
@@ -95,12 +136,13 @@ start() {
if [ $server_running -eq 0 ] ; then
rm -f $pidfile
rm -f $startpidfile
+ fix_pid_dir_ownership $instbase/slapd-$instance
$exec -D $instbase/slapd-$instance -i $pidfile -w $startpidfile
if [ $? -eq 0 ]; then
server_started=1 # well, perhaps not running, but started ok
else
failure; echo
- let errors=errors+1
+ errors=`expr $errors + 1`
fi
fi
# ok, if we started the server successfully, let's see if it is really
@@ -119,7 +161,7 @@ start() {
done
if test ! -f $startpidfile ; then
failure; echo
- let errors=errors+1
+ errors=`expr $errors + 1`
server_started=0
fi
fi
@@ -144,10 +186,10 @@ start() {
done
if kill -0 $pid > /dev/null 2>&1 && test -f $pidfile ; then
success; echo
- let successes=successes+1
+ successes=`expr $successes + 1`
else
failure; echo
- let errors=errors+1
+ errors=`expr $errors + 1`
fi
fi
rm -f $startpidfile
@@ -168,17 +210,17 @@ stop() {
errors=0
for instance in $INSTANCES; do
pidfile=$piddir/slapd-$instance.pid
- if [ -e $pidfile ]; then
- pid=$(cat $pidfile)
- echo -n " $instance..."
+ if [ -f $pidfile ]; then
+ pid=`cat $pidfile`
+ echo " $instance...\c"
server_stopped=0
- if [ $(echo "$pids" | grep -c $pid) -ge 1 ]; then
+ if kill -0 $pid > /dev/null 2>&1 ; then
kill $pid
if [ $? -eq 0 ]; then
server_stopped=1
else
failure; echo
- let errors=errors+1
+ errors=`expr $errors + 1`
fi
fi
if [ $server_stopped -eq 1 ] ; then
@@ -198,7 +240,7 @@ stop() {
done
if test -f $pidfile ; then
failure; echo
- let errors=errors+1
+ errors=`expr $errors + 1`
else
success; echo
rm -f $pidfile
@@ -207,7 +249,7 @@ stop() {
fi
done
if [ $errors -ge 1 ]; then
- echo -n "*** Error: $errors instance(s) unsuccessfully stopped"
+ echo "*** Error: $errors instance(s) unsuccessfully stopped\c"
failure; echo
else
rm -f $lockfile
@@ -222,9 +264,9 @@ restart() {
status() {
for instance in $INSTANCES; do
- if [ -e $piddir/slapd-$instance.pid ]; then
- pid=$(cat $piddir/slapd-$instance.pid)
- if [ $(echo "$pids" | grep -c $pid) -ge 1 ]; then
+ if [ -f $piddir/slapd-$instance.pid ]; then
+ pid=`cat $piddir/slapd-$instance.pid`
+ if kill -0 $pid > /dev/null 2>&1 ; then
echo "$prog $instance (pid $pid) is running..."
else
echo "$prog $instance dead but pid file exists"
@@ -244,6 +286,7 @@ case "$1" in
[ ! -f $lockfile ] || restart
;;
*)
- echo $"Usage: $0 {start|stop|status|restart|condrestart} [instance-name]"
+ echo Unknown command $1
+ echo "Usage: $0 {start|stop|status|restart|condrestart} [instance-name]"
exit 2
esac