Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100755 207 lines (185 sloc) 5.876 kb
b963502 @dscape first working version
authored
1 #!/bin/bash
2 #
3 # Copyright 2010 Mark Logic Corporation. All Rights Reserved.
4 #
5 # Licensed under the Apache License, Version 2.0 (the "License");
6 # you may not use this file except in compliance with the License.
7 # You may obtain a copy of the License at
8 #
9 # http://www.apache.org/licenses/LICENSE-2.0
10 #
11 # Unless required by applicable law or agreed to in writing, software
12 # distributed under the License is distributed on an "AS IS" BASIS,
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
16 #
17 # The use of the Apache License does not indicate that this project is
18 # affiliated with the Apache Software Foundation.
19 . /lib/lsb/init-functions
20 . /etc/sysconfig/MarkLogic
21 usage="Usage: $0 [OPTION]...
22 This script can be used to easen regular deployment tasks in Mark Logic Server.
23 Includes hooks that you can use to extend the normal install
24
25 Options:
26 -u Set the user
27 -p Set the password
28 -N Set the application name
29 -P Set the application port
30
31 -d The directory where the app to be installed currently resides
32 Will be ignored if you supply -i
33
34 -b Script (.xqy) to be run before the installer is invoked
35 -m Script (.xqy) to be run after database artifacts are created, but before
36 deployment of the appserver.
37 -a Script (.xqy) to be run after the installer is invoked.
38 Note: Only this script is actually deployed with the app,
39 so to do things like loading content you have to use this
40 trigger. Will be ignored if you supply -i, as that means no app
41 was deployed (you simply installed a database)
42
43 -i Create database artifacts, but NO Application Server.
44 -j Create an Application Server, but NO database artifacts
45
46 -D Turns debug on
47 -l Base path for the installer libraries, case they aren't in ./lib-installer"
48
49 function debug_echo () {
50 if [ ! -z "$debug" ]; then
51 for line in "$@"
52 do
53 echo "$(date) - [MarkLogic] $line"
54 done
55 fi }
56
57 function debug_exec () {
58 if [ ! -z "$debug" ]; then
59 debug_echo "$1"
60 inst=&$1
61 else
62 inst=&$1 > /dev/null 2>&1
63 fi }
64
65 user=""
66 pass=""
67 appname=""
68 appport=""
69 appdir=""
70 bxqy=""
71 mxqy=""
72 axqy=""
73 debug=""
74 appserver="1"
75 db="1"
76
77 scriptpath=`cd $(dirname $0);pwd`
78 libname="lib-installer"
79 libfolder="$scriptpath/$libname"
80
81 while getopts "hu:p:N:P:b:m:a:d:l:Dij" opts
82 do case "$opts" in
83 l) libfolder="$OPTARG";;
84 u) user="$OPTARG";;
85 p) pass="$OPTARG";;
86 P) appport="$OPTARG";;
87 N) appname="$OPTARG";;
88 b) bxqy="$OPTARG";;
89 m) mxqy="$OPTARG";;
90 a) axqy="$OPTARG";;
91 d) appdir="$OPTARG";;
92 D) debug="1";;
93 i) appserver="";;
94 j) db="";;
95 h) echo >&2 "$usage"
96 exit 1;;
97 ?) echo >&2 "$usage"
98 exit 1;;
99 esac
100 done
101
102 shift $(($OPTIND - 1))
103
104 debug_echo "From opts:" \
105 " Lib Folder: $libfolder" \
106 " Lib Name: $libname" \
107 " Where is: $scriptpath" \
108 " User: $user" \
109 " Application Name: $appname" \
110 " Application Port: $appport" \
111 " Application Dir: $appdir" \
112 " Before Commit: $bxqy" \
113 " In Commit: $mxqy" \
114 " After Commit: $axqy"
115
116 if [ "$#" -ne 0 ]; then
117 echo "Wrong number of arguments"
118 echo $usage
119 exit 1
120 fi
121
122 if [ -z "$appname" ]; then
123 echo -n "[MarkLogic] Application Name: "
124 read appname > /dev/null 2>&1
125 fi
126 if [ -z "$appport" ]; then
127 echo -n "[MarkLogic] Application Port: "
128 read appport > /dev/null 2>&1
129 fi
130
131 params="app=$appname:$appport"
132 if [ ! -z "$appserver" ]; then
133 if [ -z "$appdir" ]; then
134 echo -n "[MarkLogic] Directory to install: "
135 read appdir > /dev/null 2>&1
136 fi
137 else
138 params=$params"&noappserver=yes"
139 fi
140 if [ -z "$db" ]; then
141 params=$params"&nodb=yes"
142 fi
143
144 debug_echo "Params => $params"
145
146 if [ -z "$user" ]; then
147 echo -n "[MarkLogic] Username: "
148 read user > /dev/null 2>&1
149 fi
150 if [ -z "$pass" ]; then
151 echo -n "[MarkLogic] Password for $user: "
152 read -s pass > /dev/null 2>&1
153 echo
154 fi
155
156 instsysdir="$MARKLOGIC_INSTALL_DIR/Docs/$libname"
157 instappdir="$MARKLOGIC_INSTALL_DIR/Apps/usr"
158
159 debug_echo "Lib Folder: $libfolder" \
160 "Lib Name: $libname" \
161 "Where is: $scriptpath" \
162 "User: $user" \
163 "Application Name: $appname" \
164 "Application Port: $appport" \
165 "Application Dir: $appdir" \
166 "Before Commit: $bxqy" \
167 "In Commit: $mxqy" \
168 "After Commit: $axqy"
169
170 #sudo just to avoid sudo box appearing in the middle on flow
171 sudo echo "Lazy Panda is now installing app $appname:$appport from '$appdir'"
172 echo " . Registering the Installer with MarkLogic Server"
173 debug_exec "sudo rm -rf $instsysdir"
174 debug_exec "sudo cp -r $libfolder/ $instsysdir"
175 if [ ! -z "$bxqy" ]; then
176 echo " . Installing Pre-commit triggers ($bxqy)"
177 debug_exec "sudo cp $bxqy $instsysdir/hooks/install/precommit.xqy"
178 fi
179 if [ ! -z "$mxqy" ]; then
180 echo " . Installing In-commit triggers ($mxqy)"
181 debug_exec "sudo cp $mxqy $instsysdir/hooks/install/incommit.xqy"
182 fi
183 echo " . Registering the application with MarkLogic Server"
184
185 debug_exec "curl --anyauth http://$user:$pass@localhost:8000/$libname/install.xqy?$params"
186 echo " . Taking a nap"
187 sleep 5
188 if [ ! -z "$appserver" ]; then
189 echo " . Deploying the application to '$instappdir/$appname'"
190 debug_exec "sudo rm -r $instappdir/$appname"
191 debug_exec "sudo mkdir $instappdir"
192 debug_exec "sudo cp -r $appdir/ $instappdir/$appname"
193 if [ ! -z "$axqy" ]; then
194 echo " . Installing Pos-commit triggers ($axqy)"
195 debug_exec "sudo cp $axqy $instappdir/$appname/_poscommit.xqy"
196 debug_exec "curl --anyauth http://$user:$pass@localhost:$appport/_poscommit.xqy?app=$appname"
197 sleep 5
198 echo " . Give me a break, sleeping"
199 debug_exec "sudo rm $instappdir/$appname/_poscommit.xqy"
200 fi
201 fi
202 echo " . Removing the installer from disk"
203 debug_exec "sudo rm -rf $instsysdir"
204 echo " . Installation Complete @ http://localhost:$appport"
205 debug_exec "firefox http://localhost:$appport"
206 echo "The End! Happy Panda!"
Something went wrong with that request. Please try again.