Skip to content

Instantly share code, notes, and snippets.

@cyb3rd4d
Created October 29, 2014 10:25
Show Gist options
  • Save cyb3rd4d/fc9cc33d41a414c16677 to your computer and use it in GitHub Desktop.
Save cyb3rd4d/fc9cc33d41a414c16677 to your computer and use it in GitHub Desktop.
Init script for Jackrabbit in a Vagrant box (tested on Ubuntu).

JackRabbit Init Script

Init script for Jackrabbit in a Vagrant box (tested on Ubuntu trusty only). I am not an advanced bash developer, so don't hesitate to contribute!

Installation

Copy this script in your /etc/init.d directory:

sudo cp [ script ] /etc/init.d/jackrabbit

Adapt the content of the header (the first variables) to fit your needs. Test your script:

sudo service jackrabbit start
sudo service jackrabbit status
sudo service jackrabbit stop

Then activate the service at startup

sudo update-rc.d jackrabbit defaults

Enjoy ;)

#! /bin/sh -e
DAEMON="/vagrant/app/console"
DAEMON_OPT="doctrine:phpcr:jackrabbit"
DAEMONUSER="vagrant"
DAEMON_NAME="jackrabbit-standalone"
PIDFILE="/home/vagrant/var/run/jackrabbit.pid"
PATH="/sbin:/bin:/usr/sbin:/usr/bin"
test -x $DAEMON || exit 0
. /lib/lsb/init-functions
d_start () {
log_daemon_msg "Starting system $DAEMON_NAME Daemon"
start-stop-daemon --pidfile $PIDFILE --start --chuid $DAEMONUSER --exec $DAEMON -- $DAEMON_OPT start
log_end_msg $?
d_pid
echo $PID > $PIDFILE
}
d_stop () {
log_daemon_msg "Stopping system $DAEMON_NAME Daemon"
pid_in_file=0
if [ -f $PIDFILE ]; then
pid_in_file=$(cat $PIDFILE)
fi
if [ $pid_in_file -eq 0 ]; then
echo "No pid found in file $PIDFILE"
d_pid
if [ ! $PID ]; then
echo "Service $DAEMON_NAME is not running"
log_end_msg 0
return 0
fi
fi
$DAEMON $DAEMON_OPT stop
sleep 2
status=0
if [ $pid_in_file -eq 0 ]; then
d_pid
if [ $PID ]; then
rm -f $PIDFILE
echo "Service $DAEMON_NAME successfully stopped"
else
echo "Service $DAEMON_NAME could not be stopped"
status=1
fi
else
psoutput=`ps aux | grep $pid_in_file | grep -v grep`
if [ $? -eq 1 ]; then
rm -f $PIDFILE
echo "Service $DAEMON_NAME successfully stopped"
else
echo "Service $DAEMON_NAME could not be stopped"
status=1
fi
fi
log_end_msg $status
return $status
}
d_pid () {
PID=`ps aux | grep ${DAEMON_NAME} | grep -v grep | awk '{print $2}'`
}
case "$1" in
start|stop)
d_${1}
;;
restart|reload|force-reload)
d_stop
d_start
;;
force-stop)
d_stop
killall -q $DAEMON_NAME || true
sleep 2
killall -q -9 $DAEMON_NAME || true
;;
status)
d_pid
if [ $PID ]; then
echo "Service $DAEMON_NAME is running"
return 0
else
echo "Service $DAEMON_NAME is not running"
return 1
fi
;;
*)
echo "Usage: /etc/init.d/$DAEMON_NAME {start|stop|force-stop|restart|reload|force-reload|status}"
exit 1
;;
esac
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment