2010-10-19 06:50:34 +02:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
2008-08-09 06:38:44 +02:00
|
|
|
# Check for an argument
|
2008-12-04 23:38:32 +01:00
|
|
|
if [ ${1:-""} = "" ]; then
|
2012-03-24 04:38:57 +01:00
|
|
|
echo "SilverStripe Sake
|
2008-08-09 06:38:44 +02:00
|
|
|
|
|
|
|
Usage: $0 (command-url) (params)
|
2012-03-24 04:38:57 +01:00
|
|
|
Executes a SilverStripe command"
|
2008-08-09 06:38:44 +02:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2013-02-20 08:03:59 +01:00
|
|
|
# find the silverstripe installation
|
2013-09-17 04:45:15 +02:00
|
|
|
sakedir=`dirname $0`
|
|
|
|
if [ -f "$sakedir/cli-script.php" ]; then
|
|
|
|
framework="$sakedir"
|
|
|
|
base=`dirname $sakedir`
|
|
|
|
elif [ -f ./cli-script.php ]; then
|
2012-03-24 04:38:57 +01:00
|
|
|
framework=.
|
2008-08-26 06:10:37 +02:00
|
|
|
base=..
|
|
|
|
else
|
2013-02-20 08:03:59 +01:00
|
|
|
# look up the tree for the first parent folder that has a framework
|
|
|
|
# installation
|
|
|
|
slashes=${PWD//[^\/]/}
|
|
|
|
directory="$PWD"
|
|
|
|
base=.
|
|
|
|
for (( n=${#slashes}; n>0; --n )) do
|
|
|
|
if [ -d "$directory/framework" ]; then
|
|
|
|
framework="$directory/framework"
|
|
|
|
|
|
|
|
break
|
|
|
|
elif [ -d "$directory/sapphire" ]; then
|
|
|
|
framework="$directory/sapphire"
|
|
|
|
|
|
|
|
break
|
|
|
|
fi
|
|
|
|
|
|
|
|
directory=`dirname $directory`
|
|
|
|
base="$base."
|
|
|
|
done
|
|
|
|
|
|
|
|
if [ ! -f "$framework/cli-script.php" ]; then
|
|
|
|
echo "Can't find cli-script.php in $framework"
|
|
|
|
exit 1
|
|
|
|
fi
|
2008-08-09 06:38:44 +02:00
|
|
|
fi
|
|
|
|
|
|
|
|
# Find the PHP binary
|
2010-10-15 02:33:12 +02:00
|
|
|
for candidatephp in php php5; do
|
2011-08-26 19:59:15 +02:00
|
|
|
if [ `which $candidatephp 2>/dev/null` -a -f `which $candidatephp 2>/dev/null` ]; then
|
|
|
|
php=`which $candidatephp 2>/dev/null`
|
2008-08-09 06:38:44 +02:00
|
|
|
break
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
if [ "$php" = "" ]; then
|
|
|
|
echo "Can't find any php binary"
|
|
|
|
exit 2
|
|
|
|
fi
|
|
|
|
|
2008-08-26 06:10:37 +02:00
|
|
|
################################################################################################
|
|
|
|
## Installation to /usr/bin
|
|
|
|
|
|
|
|
if [ "$1" = "installsake" ]; then
|
2016-01-20 02:34:03 +01:00
|
|
|
echo "Installing sake to /usr/local/bin..."
|
|
|
|
rm -rf /usr/local/bin/sake
|
|
|
|
cp $0 /usr/local/bin
|
2008-08-26 06:10:37 +02:00
|
|
|
exit 0
|
2008-08-09 06:38:44 +02:00
|
|
|
fi
|
|
|
|
|
2008-08-26 06:10:37 +02:00
|
|
|
################################################################################################
|
|
|
|
## Process control
|
|
|
|
|
|
|
|
if [ "$1" = "-start" ]; then
|
|
|
|
if [ "`which daemon`" = "" ]; then
|
|
|
|
echo "You need to install the 'daemon' tool. In debian, go 'sudo apt-get install daemon'"
|
|
|
|
exit 1
|
|
|
|
fi
|
2009-02-02 00:49:53 +01:00
|
|
|
|
2008-08-26 06:10:37 +02:00
|
|
|
if [ ! -f $base/$2.pid ]; then
|
|
|
|
echo "Starting service $2 $3"
|
|
|
|
touch $base/$2.pid
|
|
|
|
pidfile=`realpath $base/$2.pid`
|
|
|
|
|
|
|
|
outlog=$base/$2.log
|
|
|
|
errlog=$base/$2.err
|
|
|
|
|
|
|
|
echo "Logging to $outlog"
|
|
|
|
|
|
|
|
sake=`realpath $0`
|
|
|
|
base=`realpath $base`
|
2009-02-02 00:49:53 +01:00
|
|
|
|
|
|
|
# if third argument is not explicitly given, copy from second argument
|
|
|
|
if [ "$3" = "" ]; then
|
|
|
|
url=$2
|
|
|
|
else
|
|
|
|
url=$3
|
|
|
|
fi
|
2008-08-26 06:10:37 +02:00
|
|
|
|
|
|
|
# TODO: Give a globally unique processname by including the projectname as well
|
|
|
|
processname=$2
|
|
|
|
|
2009-02-02 00:49:53 +01:00
|
|
|
daemon -n $processname -r -D $base --pidfile=$pidfile --stdout=$outlog --stderr=$errlog $sake $url
|
2008-08-26 06:10:37 +02:00
|
|
|
else
|
|
|
|
echo "Service $2 seems to already be running"
|
|
|
|
fi
|
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ "$1" = "-stop" ]; then
|
|
|
|
pidfile=$base/$2.pid
|
|
|
|
if [ -f $pidfile ]; then
|
|
|
|
echo "Stopping service $2"
|
|
|
|
|
|
|
|
# TODO: This is a bad way of killing the process
|
|
|
|
kill -KILL `cat $pidfile`
|
|
|
|
unlink $pidfile
|
|
|
|
else
|
|
|
|
echo "Service $2 doesn't seem to be running."
|
|
|
|
fi
|
|
|
|
exit 0
|
2008-08-09 06:38:44 +02:00
|
|
|
fi
|
|
|
|
|
2008-08-26 06:10:37 +02:00
|
|
|
################################################################################################
|
|
|
|
## Basic execution
|
|
|
|
|
2012-03-24 04:38:57 +01:00
|
|
|
$php $framework/cli-script.php ${*}
|