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
|
|
|
|
|
2024-05-20 01:04:44 +02:00
|
|
|
command -v which >/dev/null 2>&1
|
|
|
|
if [ $? -ne 0 ]; then
|
2019-11-26 12:24:44 +01:00
|
|
|
echo "Error: sake requires the 'which' command to operate." >&2
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2017-10-17 02:52:39 +02:00
|
|
|
# find the silverstripe installation, looking first at sake
|
|
|
|
# bin location, but falling back to current directory
|
2013-09-17 04:45:15 +02:00
|
|
|
sakedir=`dirname $0`
|
2017-10-17 02:52:39 +02:00
|
|
|
directory="$PWD"
|
2013-09-17 04:45:15 +02:00
|
|
|
if [ -f "$sakedir/cli-script.php" ]; then
|
2017-10-17 02:52:39 +02:00
|
|
|
# Calling sake from vendor/silverstripe/framework/sake
|
2013-09-17 04:45:15 +02:00
|
|
|
framework="$sakedir"
|
2017-10-17 02:52:39 +02:00
|
|
|
base="$sakedir/../../.."
|
|
|
|
elif [ -f "$sakedir/../silverstripe/framework/cli-script.php" ]; then
|
|
|
|
# Calling sake from vendor/bin/sake
|
|
|
|
framework="$sakedir/../silverstripe/framework"
|
|
|
|
base="$sakedir/../.."
|
|
|
|
elif [ -f "$directory/vendor/silverstripe/framework/cli-script.php" ]; then
|
|
|
|
# Vendor framework (from base) if sake installed globally
|
|
|
|
framework="$directory/vendor/silverstripe/framework"
|
|
|
|
base=.
|
|
|
|
elif [ -f "$directory/framework/cli-script.php" ]; then
|
|
|
|
# Legacy directory (from base) if sake installed globally
|
|
|
|
framework="$directory/framework"
|
|
|
|
base=.
|
2008-08-26 06:10:37 +02:00
|
|
|
else
|
2017-10-17 02:52:39 +02:00
|
|
|
echo "Can't find cli-script.php in $sakedir"
|
|
|
|
exit 1
|
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
|
2024-06-22 18:15:33 +02:00
|
|
|
if [ "`which $candidatephp 2>/dev/null`" -a -f "`which $candidatephp 2>/dev/null`" ]; then
|
2011-08-26 19:59:15 +02:00
|
|
|
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
|
2017-10-12 04:45:43 +02: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`
|
2017-10-12 04:45:43 +02:00
|
|
|
|
2008-08-26 06:10:37 +02:00
|
|
|
outlog=$base/$2.log
|
|
|
|
errlog=$base/$2.err
|
|
|
|
|
|
|
|
echo "Logging to $outlog"
|
2017-10-12 04:45:43 +02:00
|
|
|
|
2008-08-26 06:10:37 +02:00
|
|
|
sake=`realpath $0`
|
|
|
|
base=`realpath $base`
|
2017-10-12 04:45:43 +02:00
|
|
|
|
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
|
|
|
|
|
|
|
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"
|
2017-10-12 04:45:43 +02:00
|
|
|
|
2008-08-26 06:10:37 +02:00
|
|
|
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
|
|
|
|
|
2024-06-22 18:15:33 +02:00
|
|
|
"$php" "$framework/cli-script.php" "${@}"
|