Skip to content
This repository
Newer
Older
100755 109 lines (89 sloc) 2.436 kb
d542ddbb »
2010-10-19 ENHANCEMENT Making "sake" script more portable by using "/usr/bin/env…
1 #!/usr/bin/env bash
2
016cff20 »
2008-08-09 (merged from branches/roa. use "svn log -c <changeset> -g <module-svn…
3 # Check for an argument
d26f08b4 »
2008-12-04 MINOR merged branches/2.3 into trunk
4 if [ ${1:-""} = "" ]; then
3a6341a2 »
2012-03-24 API-CHANGE sapphire folder can now be renamed.
5 echo "SilverStripe Sake
016cff20 »
2008-08-09 (merged from branches/roa. use "svn log -c <changeset> -g <module-svn…
6
7 Usage: $0 (command-url) (params)
3a6341a2 »
2012-03-24 API-CHANGE sapphire folder can now be renamed.
8 Executes a SilverStripe command"
016cff20 »
2008-08-09 (merged from branches/roa. use "svn log -c <changeset> -g <module-svn…
9 exit 1
10 fi
11
3a6341a2 »
2012-03-24 API-CHANGE sapphire folder can now be renamed.
12 # Set $framework and $base
8db398a4 »
2009-10-15 ENHANCEMENT: Fixed sapphire execution if you run the uninstalled sake…
13 sakedir=`dirname $0`
14 if [ -f $sakedir/cli-script.php ]; then
3a6341a2 »
2012-03-24 API-CHANGE sapphire folder can now be renamed.
15 framework=$sakedir
8db398a4 »
2009-10-15 ENHANCEMENT: Fixed sapphire execution if you run the uninstalled sake…
16 base=`dirname $sakedir`
3a6341a2 »
2012-03-24 API-CHANGE sapphire folder can now be renamed.
17 elif [ -d ./framework ]; then
18 framework=./framework
19 base=.
8db398a4 »
2009-10-15 ENHANCEMENT: Fixed sapphire execution if you run the uninstalled sake…
20 elif [ -d ./sapphire ]; then
3a6341a2 »
2012-03-24 API-CHANGE sapphire folder can now be renamed.
21 framework=./sapphire
9157113d »
2008-08-26 Added EPMU's process control sake
22 base=.
23 elif [ -f ./cli-script.php ]; then
3a6341a2 »
2012-03-24 API-CHANGE sapphire folder can now be renamed.
24 framework=.
9157113d »
2008-08-26 Added EPMU's process control sake
25 base=..
26 else
3a6341a2 »
2012-03-24 API-CHANGE sapphire folder can now be renamed.
27 echo "Can't find ./framework/cli-script.php or ./cli-script.php"
9157113d »
2008-08-26 Added EPMU's process control sake
28 exit 1
016cff20 »
2008-08-09 (merged from branches/roa. use "svn log -c <changeset> -g <module-svn…
29 fi
30
31 # Find the PHP binary
7164c91d »
2010-10-15 Sake fix: look for php binary before php5, to prevent errors on CentO…
32 for candidatephp in php php5; do
74030563 »
2011-08-26 BUGFIX Don't show CLI warnings from 'which' command in sake bash scri…
33 if [ `which $candidatephp 2>/dev/null` -a -f `which $candidatephp 2>/dev/null` ]; then
34 php=`which $candidatephp 2>/dev/null`
016cff20 »
2008-08-09 (merged from branches/roa. use "svn log -c <changeset> -g <module-svn…
35 break
36 fi
37 done
38 if [ "$php" = "" ]; then
39 echo "Can't find any php binary"
40 exit 2
41 fi
42
9157113d »
2008-08-26 Added EPMU's process control sake
43 ################################################################################################
44 ## Installation to /usr/bin
45
46 if [ "$1" = "installsake" ]; then
47 echo "Installing sake to /usr/bin..."
48 cp $0 /usr/bin
49 exit 0
016cff20 »
2008-08-09 (merged from branches/roa. use "svn log -c <changeset> -g <module-svn…
50 fi
51
9157113d »
2008-08-26 Added EPMU's process control sake
52 ################################################################################################
53 ## Process control
54
55 if [ "$1" = "-start" ]; then
56 if [ "`which daemon`" = "" ]; then
57 echo "You need to install the 'daemon' tool. In debian, go 'sudo apt-get install daemon'"
58 exit 1
59 fi
60f75c5c »
2009-02-01 Merged changes from 2.3 branch
60
9157113d »
2008-08-26 Added EPMU's process control sake
61 if [ ! -f $base/$2.pid ]; then
62 echo "Starting service $2 $3"
63 touch $base/$2.pid
64 pidfile=`realpath $base/$2.pid`
65
66 outlog=$base/$2.log
67 errlog=$base/$2.err
68
69 echo "Logging to $outlog"
70
71 sake=`realpath $0`
72 base=`realpath $base`
60f75c5c »
2009-02-01 Merged changes from 2.3 branch
73
74 # if third argument is not explicitly given, copy from second argument
75 if [ "$3" = "" ]; then
76 url=$2
77 else
78 url=$3
79 fi
9157113d »
2008-08-26 Added EPMU's process control sake
80
81 # TODO: Give a globally unique processname by including the projectname as well
82 processname=$2
83
60f75c5c »
2009-02-01 Merged changes from 2.3 branch
84 daemon -n $processname -r -D $base --pidfile=$pidfile --stdout=$outlog --stderr=$errlog $sake $url
9157113d »
2008-08-26 Added EPMU's process control sake
85 else
86 echo "Service $2 seems to already be running"
87 fi
88 exit 0
89 fi
90
91 if [ "$1" = "-stop" ]; then
92 pidfile=$base/$2.pid
93 if [ -f $pidfile ]; then
94 echo "Stopping service $2"
95
96 # TODO: This is a bad way of killing the process
97 kill -KILL `cat $pidfile`
98 unlink $pidfile
99 else
100 echo "Service $2 doesn't seem to be running."
101 fi
102 exit 0
016cff20 »
2008-08-09 (merged from branches/roa. use "svn log -c <changeset> -g <module-svn…
103 fi
104
9157113d »
2008-08-26 Added EPMU's process control sake
105 ################################################################################################
106 ## Basic execution
107
3a6341a2 »
2012-03-24 API-CHANGE sapphire folder can now be renamed.
108 $php $framework/cli-script.php ${*}
Something went wrong with that request. Please try again.