/
startscripts.xml
337 lines (319 loc) · 9.54 KB
/
startscripts.xml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
<project name="startscripts" basedir="./" xmlns:antcontrib="antlib:net.sf.antcontrib">
<property name="startscripts.create" value="true" />
<target name="startscripts.create">
<antcontrib:if>
<equals arg1="${startscripts.create}" arg2="true" />
<then>
<antcontrib:runtarget target="cfdistro.executable" />
<!-- the sane context path always ends with /, which isn't right but makes links to it standard
so we correct the correction and then recorrect it -->
<sanitizeContextPath />
<antcontrib:propertyregex property="war.contextpath" input="${war.contextpath}" regexp="^/?([^/]+)" select="/\1" global="false" override="yes" />
<echo file="${basedir}/start.sh"><![CDATA[#start script
if test -n "${JAVA_HOME}"; then
if test -z "${JAVA_EXE}"; then
JAVA_EXE=$JAVA_HOME/bin/java
fi
fi
if test -z "${JAVA_EXE}"; then
JAVA_EXE=java
fi
cd $(dirname $0)
#exec $JAVA_EXE -jar ./lib/jetty-runner-7.0.0.RC5.jar $* > /dev/null 2>&1 &
exec $JAVA_EXE -Xmx200m -jar ${cfdistro.lib.dir}/${jetty-runner.jar} --port ${server.port.http} --path ${war.contextpath} $* ${war.target.dir}]]>
</echo>
<chmod file="${basedir}/start.sh" perm="ugo+rx"/>
<echo file="${basedir}/start.bat"><![CDATA[java -Xmx200m -jar "${cfdistro.lib.dir}/${jetty-runner.jar}" --port ${server.port.http} --path ${war.contextpath} %1 "${war.target.dir}"]]></echo>
<property name="osxappbundle.dir" location="${dist.root.dir}/${distro.name}.app"/>
<startscript script-path="${dist.dir}/${distro.name}/${distro.name}" />
<!-- make OS X app bundle -->
<copy toDir="${osxappbundle.dir}" overwrite="yes">
<filterchain>
<expandproperties />
</filterchain>
<fileset dir="${cfdistro.basedir}/skeleton/osxappbundle" />
</copy>
<move file="${osxappbundle.dir}/Contents/Resources/icon.icns"
toFile="${osxappbundle.dir}/Contents/Resources/${distro.name}.icns" />
<move file="${osxappbundle.dir}/Contents/MacOS/start"
toFile="${osxappbundle.dir}/Contents/MacOS/${distro.name}" />
<chmod file="${osxappbundle.dir}/Contents/MacOS/${distro.name}" perm="ugo+rx"/>
<chmod file="${osxappbundle.dir}/Contents/MacOS/run.command" perm="ugo+rx"/>
</then>
</antcontrib:if>
<!--
<add-system-path path="${user.home}/cfdistro/bin" keyword="cfdistro" />
-->
</target>
<target name="cfdistro.executable">
<echo file="${basedir}/bin/cfdistro"><![CDATA[#! /bin/sh
reldir=`dirname $0`
export ANT_HOME="$reldir/../ant/"
props=""
target=$1
shift
for var in "$@"
do
props="$props -D$var"
done
#echo $reldir/../ant/bin/ant -nouserlib -f $reldir/build.xml $target $props
/bin/sh $reldir/../ant/bin/ant -nouserlib -f build/build.xml $target -Dcfdistro.build.file=$reldir/../build.xml $props]]>
</echo>
<chmod file="${basedir}/bin/cfdistro" perm="ugo+rx"/>
<echo file="${basedir}/bin/cfdistro.bat"><![CDATA[@echo off
if "%1" == "" goto error
set CFDISTRO_HOME=%~dp0%\..\
set ANT_HOME=%CFDISTRO_HOME%\ant
set buildfile=build/build.xml
set args=%1
SHIFT
:Loop
IF "%1"=="" GOTO Continue
SET args=%args% -D%1%
SHIFT
IF "%1"=="" GOTO Continue
SET args=%args%=%1%
SHIFT
GOTO Loop
:Continue
if not exist %buildfile% (
set buildfile="%CFDISTRO_HOME%\..\build.xml"
)
call %ANT_HOME%\bin\ant.bat -nouserlib -f %buildfile% %args%
goto end
:error
echo usage:
echo cfdistro.bat start
echo cfdistro.bat stop
:end]]></echo>
</target>
<target name="centos.onboot">
<echo file="/etc/init.d/${distro.name}"><![CDATA[#!/bin/sh
# chkconfig: 345 99 01
# description: ${distro.name} startup script
#
runcommand=${basedir}/../${distro.name}.sh
runuser=$(/usr/bin/whoami)
echo Running as $runuser
if [ $runuser != "cfml" ]; then
#su - cfml --session-command="/home/cfml/myapp/myapp.sh $1"
runcommand="sudo -u cfml -i -H $runcommand"
echo Switching to cfml user
fi
case "$1" in
start)
echo "starting ${distro.name}"
shift
$runcommand server.start @*
;;
stop)
echo "stopping ${distro.name}"
shift
$runcommand server.stop @*
;;
restart)
echo "restarting ${distro.name}"
shift
$runcommand server.restart @*
;;
*)
echo "*** Usage: ${distro.name} {start | stop | restart}"
exit 1
esac]]></echo>
<chmod file="/etc/init.d/${distro.name}" perm="ugo+rx"/>
<exec executable="/sbin/chkconfig">
<arg value="--level"/>
<arg value="345"/>
<arg value="${distro.name}"/>
<arg value="on"/>
</exec>
</target>
<macrodef name="startscript">
<attribute name="script-path" />
<attribute name="cfdistro-path" default="$${user.home}/cfdistro" />
<sequential>
<property name="dist.script.sh" value="@{script-path}" />
<property name="dist.script.bat" value="@{script-path}.bat" />
<echo file="${dist.script.sh}"><![CDATA[#! /bin/bash
reldir=`dirname $0`
cd $reldir/build
ANTCMD="/bin/sh $HOME/cfdistro/ant/bin/ant -nouserlib -f build.xml"
export ANT_HOME=$HOME/cfdistro/ant
CFDISTRO_ZIP=$HOME/cfdistro/cfdistro.zip
if [ "$HTTP_CLIENT" = "" ]; then
if type -p curl >/dev/null 2>&1; then
if [ "$https_proxy" != "" ]; then
CURL_PROXY="-x $https_proxy"
fi
HTTP_CLIENT="curl $CURL_PROXY -f -L -o"
else
HTTP_CLIENT="wget -O"
fi
fi
if [ ! -d "$ANT_HOME" ]; then
export ANT_HOME=/opt/cfdistro/ant
ANTCMD="/bin/sh /opt/cfdistro/ant/bin/ant -nouserlib -f build.xml"
fi
if [ ! -d "$ANT_HOME" ]; then
if [ -r "$CFDISTRO_ZIP" ]; then
echo "The zip was already saved to $CFDISTRO_ZIP."
echo "If you wish to re-download, delete it."
exit 1
fi
echo "Downloading cfdistro now..."
CFDISTRO_DIR=`dirname "$CFDISTRO_ZIP"`
mkdir -p "$CFDISTRO_DIR"
CFDISTRO_URL="http://cfmlprojects.org/artifacts/cfdistro/latest/cfdistro.zip"
$HTTP_CLIENT "$CFDISTRO_ZIP" "$CFDISTRO_URL"
if [ $? != 0 ]; then
echo "Failed to download $CFDISTRO_URL"
echo "If you have an old version of libssl you may not have the correct"
echo "certificate authority. Either upgrade or set HTTP_CLIENT to insecure:"
echo " export HTTP_CLIENT=\"wget --no-check-certificate -O\" # or"
echo " export HTTP_CLIENT=\"curl --insecure -f -L -o"
rm $CFDISTRO_ZIP 2> /dev/null
exit 1
fi
unzip "$CFDISTRO_ZIP" -d "$CFDISTRO_DIR"
fi
if [ -z "$1" ]; then
echo "${distro.name} control script"
OPTIONS="start stop help list-targets update exit"
select opt in $OPTIONS; do
if [ "$opt" = "start" ]; then
$ANTCMD build.start.launch
exit
elif [ "$opt" = "stop" ]; then
$ANTCMD server.stop
exit
elif [ "$opt" = "help" ]; then
echo "usage (skips this prompt): ${distro.name} [start|stop|{target}]"
elif [ "$opt" = "list-targets" ]; then
$ANTCMD help
elif [ "$opt" = "update" ]; then
$ANTCMD project.update
elif [ "$opt" = "exit" ]; then
exit
else
#clear
echo bad option
fi
done
fi
target=$1
parameters=""
shift
for var in "$@"
do
parameters="$parameters -D$var"
done
$ANTCMD $target -Dbasedir=. $parameters
]]>
</echo>
<echo file="${dist.script.bat}"><![CDATA[@echo off
set CFDISTRO_HOME=%userprofile%\cfdistro
set FILE_URL="http://cfmlprojects.org/artifacts/cfdistro/latest/cfdistro.zip"
set FILE_DEST=%CFDISTRO_HOME%\cfdistro.zip
set buildfile=build/build.xml
set ANT_HOME=%CFDISTRO_HOME%\ant
set ANT_CMD=%CFDISTRO_HOME%\ant\bin\ant.bat
if not exist "%CFDISTRO_HOME%" (
mkdir "%CFDISTRO_HOME%"
)
if not exist "%FILE_DEST%" (
echo Downloading with powershell: %FILE_URL% to %FILE_DEST%
powershell.exe -command "$webclient = New-Object System.Net.WebClient; $url = \"%FILE_URL%\"; $file = \"%FILE_DEST%\"; $webclient.DownloadFile($url,$file);"
echo Expanding with powershell to: %CFDISTRO_HOME%
powershell -command "$shell_app=new-object -com shell.application; $zip_file = $shell_app.namespace(\"%FILE_DEST%\"); $destination = $shell_app.namespace(\"%CFDISTRO_HOME%\"); $destination.Copyhere($zip_file.items())"
) else (
echo "cfdistro.zip already downloaded, delete to re-download"
)
if "%1" == "" goto MENU
set args=%1
SHIFT
:Loop
IF "%1" == "" GOTO Continue
SET args=%args% -D%1%
SHIFT
IF "%1" == "" GOTO Continue
SET args=%args%=%1%
SHIFT
GOTO Loop
:Continue
if not exist %buildfile% (
set buildfile="%CFDISTRO_HOME%\build.xml"
)
call "%ANT_CMD%" -nouserlib -f %buildfile% %args%
goto end
:MENU
cls
echo.
echo ${distro.name} menu
REM echo usage: ${distro.name}.bat [start|stop|{target}]
echo.
echo 1. Start server and open browser
echo 2. Stop server
echo 3. List available targets
echo 4. Update project
echo 5. Run Target
echo 6. Quit
echo.
set choice=
set /p choice= Enter option 1, 2, 3, 4, 5 or 6 :
echo.
if not '%choice%'=='' set choice=%choice:~0,1%
if '%choice%'=='1' goto startServer
if '%choice%'=='2' goto stopServer
if '%choice%'=='3' goto listTargets
if '%choice%'=='4' goto updateProject
if '%choice%'=='5' goto runTarget
if '%choice%'=='6' goto end
::
echo.
echo.
echo "%choice%" is not a valid option - try again
echo.
pause
goto MENU
::
:startServer
cls
call "%ANT_CMD%" -nouserlib -f %buildfile% build.start.launch
echo to stop the server, run this again or run: ${distro.name}.bat stop
goto end
::
:stopServer
call "%ANT_CMD%" -nouserlib -f %buildfile% server.stop
goto end
::
:listTargets
call "%ANT_CMD%" -nouserlib -f %buildfile% help
echo press any key ...
pause > nul
goto MENU
::
:updateProject
call "%ANT_CMD%" -nouserlib -f %buildfile% project.update
echo press any key ...
pause > nul
goto MENU
::
:runTarget
set target=
set /p target= Enter target name:
if not "%target%"=="" call %0 %target%
echo press any key ...
pause > nul
goto MENU
::
:end
set choice=
echo press any key ...
pause
REM EXIT]]>
</echo>
<fixcrlf file="${dist.script.bat}" eol="crlf" />
<chmod file="${dist.script.sh}" perm="ugo+rx"/>
</sequential>
</macrodef>
</project>