blob: 3dc8c08b37020c62479008ce432459394f7b8db3 [file] [log] [blame]
demx8as627fb2d02018-07-10 18:07:44 +02001#!/bin/bash
2# (c) 2016 highstreet technologies
3# History
4# 2.1 Modify to use config/active directory
5# 2.2 Correct problems
6# 2.3 Shift config/active to code/apps/persistentDatabase/activConfig
7# 2.4 Update to Boron
8# 2.5 One feature to start apps
9# 2.6 New variant of install.sh
10# 2.12 CMDBIN, switch of DLUX for prepare
11# 2.13 Adapt ODLBIN to odl.sh and buildv2.sh,
12# Fix "yes" answer for cluster distremove
13# introduce cluster push
14# kill command
15# 2.14 add compile command
16# 2.15 move im install script to odl.cmd
17# 2.16 Add $ODL_KARAF_STARTUP_SCRIPT_CLUSTER for cluster command
18# cp for filecopy
19# 2.17 odl.cmd moved back into bin/odl.sh
20# Added prepare with copy of etc/preload.cache.schema to cache/schema into startup
21# status command delivers version information
22# 2.18 Add loop for cluster commands
23# 2.19 Change startup feature
24# Add parent version variable ODLPARENT
25# 2.20 Added parameter KARAFSLEEPFORSTART
26# 2.21 Typos fixed
27Version=2.21
28
29# ----- Constants not depending on variables specified by $CONFIG
30ODLPARENT="0.5.1-SNAPSHOT"
31STARTFEATURE="odl-dev-all"
32KARAFSLEEPFORSTART=30
33ODLBIN=../bin
34
35CONFIG=dist.conf
36
37# ----- Functions to startup Vanilla ODL
38
39karaf_prepare() {
40 echo "Prepare"
41 echo $ODL_KARAF_HOME
42 ODLCACHESCHEMADIR="$ODL_KARAF_HOME/cache/schema"
43 ETCCACHESCHEMADIR="$ODL_KARAF_HOME/etc/preload.cache.schema"
44
45 if [ -d "$ETCCACHESCHEMADIR" ] ; then
46 echo "Handle YANG preload"
47 if [ -d "$ODLCACHESCHEMADIR" ] ; then
48 echo "Remove all files in YANG cache/schema directory"
49 rm $ODLCACHESCHEMADIR/*
50 else
51 echo "YANG cache/schema directory created"
52 mkdir -p $ODLCACHESCHEMADIR
53 fi
54 cp $ETCCACHESCHEMADIR/* $ODLCACHESCHEMADIR
55 fi
56}
57
58# Startup of single node (no clustering)
59karaf_startup_all() {
60 # Prepare
61 karaf_prepare
62 # Base
63 karafcmd "feature:install odl-netconf-topology"
64 karafcmd "feature:install odl-netconf-connector"
65 karafcmd "feature:install odl-restconf-all"
66 karafcmd "feature:install odl-mdsal-apidocs"
67
68 # Logs and apps
69 karaf_enable_logs
70 karaf_startup_apps
71}
72
73# Startup of clustered nodes (no clustering)
74karaf_startup_cluster_all() {
75 # Prepare
76 karaf_prepare
77 # Base
78 karafcmd "feature:repo-add mvn:org.opendaylight.mwtn/mwtn-parent/$ODLPARENT/xml/features"
79 karafcmd "feature:install odl-mwtn-cluster-preparation"
80
81 # Logs and apps
82 karaf_enable_logs DEBUG
83 karaf_startup_apps
84}
85
86# Sub functions
87
88karaf_startup_apps() {
89 # Wireless (mwtn: microwave transport network)
90 karafcmd "feature:repo-add mvn:org.opendaylight.mwtn/mwtn-parent/$ODLPARENT/xml/features"
91 karafcmd "feature:install $STARTFEATURE"
92
93 #If restart is required set RESTART to true
94 # RESTART="true"
95}
96
97karaf_enable_logs() {
98 if [ -z "$1" ] ; then
99 LOGLEVEL="INFO"
100 else
101 LOGLEVEL="$1"
102 fi
103 karafcmd "log:set $LOGLEVEL com.highstreet.technologies"
104 karafcmd "log:set $LOGLEVEL org.opendaylight.mwtn"
105 karafcmd "log:set $LOGLEVEL org.opendaylight.netconf"
106}
107
108karafcmd() {
109 echo "$@"
110 $ODL_KARAF_HOME/bin/client -u karaf "$@" 2> /dev/null
111 if [ ! -z "$ODL_KARAF_AFTERCMD_DELAY_SECONDS" ] ; then
112 echo "Pause $ODL_KARAF_AFTERCMD_DELAY_SECONDS seconds"
113 sleep "$ODL_KARAF_AFTERCMD_DELAY_SECONDS"
114 fi
115}
116
117install_originM2() {
118 #Network apps
119 cp -r ~/.m2/repository/org/opendaylight/mwtn $ODL_KARAF_HOME/system/org/opendaylight
120 cp -r ~/.m2/repository/com/highstreet $ODL_KARAF_HOME/system/com
121 #Additional package for feature odl-ht-info
122 mkdir -p $ODL_KARAF_HOME/system/org/apache/commons/commons-compress
123 cp -r ~/.m2/repository/org/apache/commons/commons-compress/1.14 $ODL_KARAF_HOME/system/org/apache/commons/commons-compress
124}
125
126# ----- Functions of script to implement commands
127
128#check if tool is installed as prereq
129
130tool_check_installed() {
131 hash $1 2>/dev/null || { echo >&2 "I require $1 but it's not installed. Please install. Aborting."; exit 1; }
132}
133
134#check if karaf instance is running
135karaf_checkrunning() {
136 NETSTATRESULT=$(netstat -ant | grep 8101)
137 if [ -n "$NETSTATRESULT" ] ; then
138 reason="$NETSTATRESULT"
139 running="true"
140 else
141 running1=$(ps -ef | grep -c karaf.jar)
142 sleep 1
143 running2=$(ps -ef | grep -c karaf.jar)
144
145 reason="psResults: $running1 $running2"
146 if [ "$running1" = "2" -o "$running2" = "2" ] ; then
147 running="true"
148 else
149 running="false"
150 fi
151 fi
152 #echo "Test running: $running indication:$reason"
153}
154
155karaf_status() {
156 echo "Version information"
157 cat $ODL_KARAF_HOME/networkAppVersion.txt
158 karaf_checkrunning
159 echo "Karaf is running: $running"
160}
161
162karaf_waittillstopped() {
163 KARAF_WAITFORSTOP="5"
164 anzahl=0
165
166 echo -n "Wait for stop "
167
168 karaf_checkrunning
169 while [ "$running" = "true" -a "$anzahl" -lt 30 ]
170 do
171 (( anzahl++ ))
172 # echo "Wait ($anzahl) for karaf stop. Wait $KARAF_WAITFORSTOP seconds"
173 echo -n "."
174 sleep $KARAF_WAITFORSTOP
175 karaf_checkrunning
176 done
177 echo
178
179 if [ "$running" = "true" ]
180 then
181 echo "Exceeded wait counter. Waited $anzahl * $KARAF_WITFORSTOP seconds. Karaf still running. Reason is $reason"
182 else
183 echo "Karaf reached stop status with $reason"
184 fi
185}
186
187karaf_startifnotrunning() {
188
189 karaf_checkrunning
190 if [ "$running" = "true" ]
191 then
192 echo "Can not start, karaf is already running. Reason: $reason"
193 else
194 if [ "$1" = "clean" ] ; then
195 $ODL_KARAF_HOME/bin/start clean
196 echo "Started with clean"
197 else
198 $ODL_KARAF_HOME/bin/start
199 echo "Started"
200 fi
201 fi
202}
203
204
205# Start all servies
206# see beginning of this script
207
208#Param1 Optional Param2 Optional
209karaf_cleanstart() {
210 echo "start karaf clean with parameters $1 $2"
211 if [ -f "$ODL_KARAF_HOME/etc/opendaylight" ]
212 then
213 echo "Remove old ODL configuration"
214 rm -r $ODL_KARAF_HOME/etc/opendaylight
215 fi
216 echo "Start karaf"
217 $ODL_KARAF_HOME/bin/start clean
218 echo "Wait $KARAFSLEEPFORSTART s till karaf and ssh is in a working level"
219 sleep $KARAFSLEEPFORSTART
220 netstat -ant | grep 8101
221 echo "Provisioning $1"
222 if [ -z "$ODL_KARAF_STARTUP_SCRIPT" ] ; then #Old scripting names
223 if [ "$1" = "1b" ] ; then
224 karaf_startup_1b
225 else
226 karaf_startup_all
227 fi
228 else #Use startup script according to configuration
229 if [ "$1"="cluster" ] ; then
230 echo "Cluster start command"
231 if [ -z "$ODL_KARAF_STARTUP_SCRIPT_CLUSTER" ] ; then
232 echo "Using normal startup script"
233 $ODL_KARAF_STARTUP_SCRIPT
234 else
235 echo "Using cluster startup script"
236 $ODL_KARAF_STARTUP_SCRIPT_CLUSTER
237 fi
238 else
239 $ODL_KARAF_STARTUP_SCRIPT
240 fi
241 fi
242 if [ "$1" = "x" -o "$2" = "x" -o "$RESTART" = "true" ] ; then
243 echo "Executed with restart option .."
244 sleep 5
245 $ODL_KARAF_HOME/bin/stop
246 echo "Re-starting Karaf to finish setup"
247 karaf_waittillstopped
248 if [ "$1" = "d" -o "$2" = "d" ] ; then
249 rp=$ODL_KARAF_HOME/data/log
250 echo "Remove all logs from $rp"
251 rm "$rp"/*
252 fi
253 karaf_startifnotrunning
254 fi
255 echo "Ready"
256}
257
258# Install from dir $1 all subs with mask $2.
259# Example: install_originM2Range "com/highstreet/technologies/solutions" "sdn4*"
260install_originM2Range() {
261 mkdir -p $ODL_KARAF_HOME/system/$1
262 cp -R $HOME/.m2/repository/$1/$2 $ODL_KARAF_HOME/system/$1
263}
264
265install_tarFile() {
266 if [ ! -e "$1" ] ; then
267 echo "No tar file $1"
268 exit 4
269 else
270 echo "Do install file $1 to karaf container"
271 tar -xf "$1" -C "$ODL_KARAF_HOME"
272 echo "Done"
273 fi
274}
275
276install_originBuild() {
277
278 if [ -z "$ODL_BUILD_HOME" ] ; then
279 echo "No ODL_BUILD_HOME defined. Terminate" ; exit 2
280 fi
281 echo "Build home at $ODL_BUILD_HOME"
282 if [ ! -e $ODL_BUILD_HOME/builds/version.txt ] ; then
283 echo "No builds available Terminate." ; exit 2
284 fi
285
286 source $ODL_BUILD_HOME/builds/version.txt
287 echo "Install Version $LASTBUILDTAR"
288 tar -xf "$ODL_BUILD_HOME/builds/$LASTBUILDTAR" -C "$ODL_KARAF_HOME"
289 echo "Version info"
290 cat $ODL_KARAF_HOME/networkAppVersion.txt
291}
292
293clean_repository() {
294 echo Clean repository .m2 and karaf/system
295 rm -r ~/.m2/repository/org/opendaylight/mwtn
296 rm -r ~/.m2/repository/org/opendaylight/apigateway
297 rm -r ~/.m2/repository/cn/com/zte
298 rm -r ~/.m2/repository/com/hcl
299 rm -r ~/.m2/repository/com/highstreet
300 rm -r $ODL_KARAF_HOME/system/com/highstreet
301 rm -r $ODL_KARAF_HOME/system/com/hcl
302 rm -r $ODL_KARAF_HOME/system/cn/com/zte
303 rm -r $ODL_KARAF_HOME/system/org/opendaylight/mwtn
304 rm -r $ODL_KARAF_HOME/system/org/opendaylight/apigateway
305}
306
307# Parameter1 nodlux
308prepare() {
309 #tool_check_installed unzip
310 #tool_check_installed sshpass
311 KARAFDISTBASENAME=$ODL_KARAF_DIST
312 KARAFGZ=$ODL_KARAF_DISTGZ
313 NODLUX="nodlux"
314
315 if [ ! -f "$KARAFGZ" ] ; then
316 echo "ERROR: Could not find tar file with karaf distribution: $KARAFGZ"
317 else
318 if [ "$1" != "$NODLUX" -a ! -f "$TARFILE_DLUXLOADER" ] ; then
319 echo "WARN: Could not find tar with DLUX patch $TARFILE_DLUXLOADER. .. proceeding without Patching"
320 fi
321 if [ -d "$ODL_KARAF_HOME" ] ; then
322 echo "Found existing Karaf distribution at $ODL_KARAF_HOME. Can not proceed. Please remove or rename."
323 else
324 echo "Start installation $KARAFDISTBASENAME"
325 echo "Unpack karaf distribution"
326 cd $HOME
327 cd Downloads
328 tar -xzf $KARAFDISTBASENAME".tar.gz"
329 mv "$KARAFDISTBASENAME" "$ODL_KARAF_HOME"
330 cd "$here"
331
332 if ! [ -d "$ODL_KARAF_HOME" ] ; then
333 echo "ERROR: Could not find ODL_KARAF_HOME. Can not proceed if not existing."
334 else
335 echo "READY, create link dist"
336 ln -s $ODL_KARAF_HOME dist
337 if [ "$1" != "$NODLUX" ] ; then
338 echo "Install DLUX patch"
339 installDluxPatch tar
340 fi
341 fi
342 fi
343 fi
344}
345
346show_env() {
347 echo "ENV settings:"
348 echo " ODL_KARAF_DIST: $ODL_KARAF_DIST"
349 echo " ODL_KARAF_HOME: $ODL_KARAF_HOME"
350 echo " JAVA_HOME: $JAVA_HOME"
351}
352
353#Param1: Mandatory Param2:optional Param3:optional
354do_install() {
355
356 echo "Install from $1 to Karaf"
357 if [ ! -d "$ODL_KARAF_HOME" ] ; then
358 echo "ERROR: Karaf not installed at $ODL_KARAF_HOME. Stop execution."
359 exit 2
360 fi
361 sleep 2
362 karaf_checkrunning
363 if [ "$running" = "true" ]
364 then
365 echo "karaf instance is running. Stop first. Indication '$reason'"
366 else
367 echo "Start install to karaf"
368 case "$1" in
369 build)
370 install_originBuild
371 karaf_cleanstart $2 $3
372 ;;
373 m2)
374 if [ "$(type -t install_originM2)" == "function" ] ; then
375 install_originM2
376 karaf_cleanstart $2 $3
377 else
378 echo "Error: Install function not defined. Exit."
379 fi
380 ;;
381 tar)
382 install_tarFile $2
383 shift
384 karaf_cleanstart $3 $4
385 ;;
386 *)
387 echo "Script error: missing installation command"
388 ;;
389 esac
390 fi
391}
392
393karaf_distremove() {
394 echo "Remove karaf installation"
395 karaf_checkrunning
396 if [ "$running" = "true" ]
397 then
398 echo "karaf instance is running. Stop first"
399 else
400 if [ "$1" = "force" ] ; then
401 answer=yes
402 else
403 read -p "Delete karaf installation. if you are sure type yes<enter> " answer
404 fi
405 if [ "$answer" == "yes" ] ; then
406 echo "Remove ..."
407 rm -r $ODL_KARAF_HOME
408 echo "Remove link"
409 rm dist
410 echo "removed"
411 else
412 echo "Did nothing"
413 fi
414 fi
415}
416
417# Par1 Install command
418installDluxPatch() {
419 #Default is the tar file
420 DLUXAPPHOME="apps/dlux"
421 TARGETDIR="$DLUXAPPHOME/loader/impl/target"
422 LOADERREPO="org/opendaylight/dlux"
423 LOADERNAME="loader.implementation"
424
425 case "$1" in
426 m2)
427 if [ -d $TARGETDIR ] ; then
428 echo "Copy DLUX Patch from repository"
429 cp -r "$HOME/.m2/repository/$LOADERREPO/loader.implementation" "$ODL_KARAF_HOME/system/$LOADERREPO"
430 else
431 echo "ERROR No compiled DLUX Version or tarfile for repositiory found. "
432 echo " - Please compile dlux."
433 echo " - Install DLUX Patch with $ODL/odl.sh dlux m2"
434 fi
435 ;;
436 tar)
437 if [ -f "$TARFILE_DLUXLOADER" ] ; then
438 echo "Install DLUX Patch from existing tar"
439 tar -xzf "$TARFILE_DLUXLOADER" -C "$ODL_KARAF_HOME/system"
440 echo "Done"
441 else
442 echo "DLUX tar file not found: $TARFILE_DLUXLOADER"
443 fi
444 ;;
445 create)
446 echo "Create tar file"
447 if [ -d $TARGETDIR ] ; then
448 HERE=$(pwd)
449
450 stringa=($(cd $TARGETDIR ; ls $LOADERNAME*jar))
451 if [[ ${stringa[0]} =~ $LOADERNAME-(.*).jar ]] ; then
452 version="${BASH_REMATCH[1]}"
453 echo $version
454 M2INPUTNAME="$LOADERREPO/$LOADERNAME/$version"
455 TAROUTPUTNAME="$HERE/$DLUXAPPHOME/$ODL_KARAF_DIST.dluxloader.tar.gz"
456 echo "Creating file: $TAROUTPUTNAME"
457 echo "Reading from: $M2INPUTNAME"
458 cd "$HOME/.m2/repository"
459 tar -czf "$TAROUTPUTNAME" "$M2INPUTNAME"
460 echo Done
461 fi
462 cd $HERE
463 else
464 echo "ERROR No compiled DLUX Version for repositiory found. "
465 echo " - Please compile dlux."
466 fi
467 ;;
468 *)
469 echo "use $ODLBIN/odl.sh dlux [m2|tar|create] to install from m2-repository or install tar file or create tar file"
470 ;;
471 esac
472}
473
474# -----------------------------------------------------
475# ----- Cluster commands
476
477# P1: Passwd P2: Username P3:ServerIP P4, P5: Remote commands
478karafclustercmd() {
479 rcmd="cd $here ; $ODLBIN/odl.sh $4 $5"
480 cmd="sshpass -p$1 ssh -o StrictHostKeyChecking=no $2@$3 $rcmd"
481 echo "--------- Begin at node: $3 -----------"
482 $cmd
483 echo "--------- Ende at node: $3 ------------"
484}
485
486# P1: Passwd P2: Username P3:ServerIP P4, P5: Remote commands
487karafclustercmdnohup() {
488 #Template: nohup myprogram > foo.out 2> foo.err < /dev/null &
489 echo " Start install for node $3"
490 rcmd="cd $here ; nohup $ODLBIN/odl.sh $4 $5 &> odl.log < /dev/null &"
491 cmd="sshpass -p$1 ssh -o StrictHostKeyChecking=no $2@$3 $rcmd"
492 $cmd
493 echo "Command executed in background. Result see odl.log."
494}
495
496karafclustercreate() {
497
498 if [ -z "$1" ] ; then
499 read -p "Please enter password for user $USER: " -r -s USERPWD
500 echo
501 fi
502
503 for i in ${!ODL_CLUSTER_ARRAY[@]} ; do
504 rcmd="cd $here ; $ODL_KARAF_HOME/bin/configure_cluster.sh $((i+1)) ${ODL_CLUSTER_ARRAY[@]}"
505 cmd="sshpass -p$USERPWD ssh -o StrictHostKeyChecking=no $USER@${ODL_CLUSTER_ARRAY[$i]} $rcmd"
506 echo "--------- Start Node: ${ODL_CLUSTER_ARRAY[$i]} ----------- CMD: $rcmd"
507 $cmd
508 echo "--------- Ende Node: ${ODL_CLUSTER_ARRAY[$i]}------------"
509 done
510
511}
512
513pause() {
514 read -p "($1) Hit enter ..." -r -s TMP
515 echo
516}
517
518#Destination is $ODL_BUILD_HOME
519#Source is $ODL_CLUSTER_REPO
520pushbuildinfo() {
521 if [ -z $ODL_CLUSTER_REPO ] ; then
522 echo "No cluster repository specified by ODL_CLUSTER_REPO. Can not proceed."
523 else
524 if [ -z "$ODL_BUILD_HOME" ] ; then
525 echo "No ODL_BUILD_HOME defined. Terminate" ; exit 2
526 fi
527 echo "Build home at $ODL_CLUSTER_REPO"
528 ODL_VERSION_FILE="$ODL_CLUSTER_REPO/builds/version.txt"
529 if [ ! -e $ODL_VERSION_FILE ] ; then
530 echo "No builds available Terminate." ; exit 2
531 fi
532
533 #Read version information
534 source $ODL_VERSION_FILE
535 echo "Prepare cluster with $BUILDTAG and prepare configuration files."
536 echo "Destination repository: $ODL_BUILD_HOME Source repository: $ODL_CLUSTER_REPO"
537 if [ -z "$1" ] ; then
538 read -p "Please enter password for user $USER: " -r -s USERPWD
539 echo
540 fi
541 for i in ${ODL_CLUSTER_ARRAY[@]} ; do
542 echo "Copy to $i:$ODL_BUILD_HOME"
543 sshpass -p$USERPWD ssh -o StrictHostKeyChecking=no $USER@$i "mkdir -p $ODL_BUILD_HOME/builds"
544 sshpass -p$USERPWD scp "$ODL_CLUSTER_REPO/builds/$LASTBUILDTAR" "$i:$ODL_BUILD_HOME/builds"
545 sshpass -p$USERPWD scp "$ODL_VERSION_FILE" "$i:$ODL_BUILD_HOME/builds"
546 sshpass -p$USERPWD scp -r "$ODL_CLUSTER_REPO/bin" "$i:$ODL_BUILD_HOME"
547 sshpass -p$USERPWD ssh -o StrictHostKeyChecking=no $USER@$i "mkdir -p $here"
548 sshpass -p$USERPWD scp "$here/$CONFIG" "$i:$here"
549 # sshpass -p$USERPWD scp "$here/$ODLCMD" "$i:$here"
550 sshpass -p$USERPWD ssh -o StrictHostKeyChecking=no $USER@$i "cd $here ; chmod 755 $ODL_BUILD_HOME/bin/odl.sh ; if [ ! -e odl ] ; then ln -s $ODL_BUILD_HOME/bin/odl.sh odl ; fi"
551 done
552 fi
553}
554
555#Destination is $here/dist
556#Parameter $1 is sourcedirectory
557clusterfilecopy() {
558 if [ -z "$1" ] ; then
559 echo "ERROR: Need a path as parameter"
560 else
561 echo "Copy all files from directory $1/* to $here/dist/$1 on each node."
562 read -p "Please enter password for user $USER: " -r -s USERPWD
563 echo
564 for i in ${ODL_CLUSTER_ARRAY[@]} ; do
565 destpath="$i:$here/dist"
566 echo "Copy $here/$1 to $destpath"
567 sshpass -p$USERPWD scp -r "$1" "$destpath"
568 done
569 fi
570}
571
572karafclusterinfo() {
573 echo "Using user $USER"
574 echo "Cluster: ${ODL_CLUSTER_ARRAY[@]}"
575}
576
577karafcluster() {
578
579 CLUSTERCLI="TRUE"
580
581 while [ $CLUSTERCLI = "TRUE" ] ; do
582
583 if [ -z "$ODL_CLUSTER_ARRAY" ] ; then
584 echo "No cluster in '$ODL_CLUSTER_ARRAY' specified"
585 else
586 tool_check_installed sshpass
587 echo "Cluster: ${ODL_CLUSTER_ARRAY[@]}"
588
589 if [ -z "$1" ] ; then
590 read -p "cluster cmd> " answer
591 set -- $answer
592 else
593 CLUSTERCLI="FALSE"
594 fi
595
596 case "$1" in
597 cp)
598 clusterfilecopy $2
599 ;;
600 create)
601 karafclustercreate
602 ;;
603 distremove)
604 read -p "Confirm karaf cluster installation deletion. If you are sure type yes<enter> " answer
605 if [ "$answer" = "yes" ] ; then
606 echo "Change to forced mode."
607 set -- distremove force
608 function="karafclustercmd"
609 else
610 echo "Terminated by user"
611 fi
612 ;;
613 "" | exit)
614 CLUSTERCLI="FALSE"
615 function=""
616 ;;
617 info)
618 karafclusterinfo
619 ;;
620 im* | ib*)
621 echo "Started on each node in background. See odl.log"
622 function="karafclustercmdnohup"
623 set -- $1 cluster
624 ;;
625 push)
626 pushbuildinfo
627 ;;
628 *)
629 function="karafclustercmd"
630 ;;
631 esac
632
633 if [ ! -z "$function" ] ; then
634 read -p "Please enter password for user $USER: " -r -s USERPWD
635 echo
636 for i in "${ODL_CLUSTER_ARRAY[@]}" ; do
637 $function $USERPWD $USER $i $1 $2
638 done
639 if [ "$1" = "prepare" ] ; then
640 read -p "Proceed with create (y/n): " answer
641 case "$answer" in
642 y*) karafclustercreate $USERPWD
643 ;;
644 esac
645 fi
646 fi
647 fi
648 if [ $CLUSTERCLI = "TRUE" ] ; then
649 set -- ""
650 fi
651
652done
653}
654
655# -----------------------------------------------------
656# ----- Script body
657
658echo "AppToODL installer $Version"
659
660if [ -f $CONFIG ] ; then
661 echo "Load configuration"
662 source "$CONFIG"
663else
664 script_command="Error: No $CONFIG file .. can not proceed. Create this file and specify the right versions:"
665 echo $script_command
666 echo 'ODL_KARAF_DIST="distribution-karaf-0.6.1-Carbon"'
667 echo 'ODL_KARAF_HOME=$HOME/odl/$ODL_KARAF_DIST'
668 echo 'ODL_KARAF_DISTGZ="$HOME/Downloads/"$ODL_KARAF_DIST".tar.gz"'
669 echo 'ODL_BUILD_HOME="$HOME/build/acme"'
670 echo 'ODL_KARAF_STARTUP_SCRIPT="karaf_startup_all"'
671 echo 'export JAVA_HOME="/usr/lib/jvm/java-8-openjdk-amd64"'
672 echo
673 echo "Example for downloading the distribution:"
674 echo 'wget https://nexus.opendaylight.org/content/repositories/opendaylight.release/org/opendaylight/integration/distribution-karaf/0.6.1-Carbon/distribution-karaf-0.6.1-Carbon.tar.gz'
675
676 exit 1
677fi
678#Since 2.17 moved back to script
679#if [ -f $ODLCMD ] ; then
680# source $ODLCMD
681#else
682# script_command="Error: No $ODLCMD file .. can not proceed"
683# echo $script_command
684# exit 1
685#fi
686
687TARFILE_DLUXLOADER="apps/dlux/$ODL_KARAF_DIST.dluxloader.tar.gz"
688echo "Karaf home: $ODL_KARAF_HOME"
689
690here=$(pwd)
691echo "Executed here: $here"
692echo ""
693
694if [ -z "$ODL_KARAF_HOME" -o -z "$ODL_KARAF_DIST" ]
695then
696 echo "Missing ENV setting ODL_KARAF_HOME or ODL_KARAF_DIST. Can not execute."
697 show_env
698 script_command="Error Incomplete ENV"
699else
700 script_command="ok"
701fi
702
703#echo "Command: $script_command"
704
705if [ "$script_command" = "ok" ] ; then
706
707case "$1" in
708
709 build)
710 if [ -z "$ODL_BUILD_HOME" ] ; then
711 echo "No build configuration found. Specify '$ODL_BUILD_HOME'."
712 else
713 echo "Enter build subsystem at location $ODL_BUILD_HOME"
714 shift
715 $ODLBIN/buildv2.sh $@
716 fi
717 ;;
718
719 cli)
720 shift
721 karafcmd $@
722 ;;
723
724 clu*)
725 shift
726 karafcluster $@
727 ;;
728
729 dlux)
730 echo "Install DLUX Patch"
731 shift
732 installDluxPatch $@
733 ;;
734
735 env)
736 show_env
737 ;;
738 kill)
739 echo "Kill ODL instance"
740 pkill -e -f "Dkaraf.home=.home.herbert.odl.$ODL_KARAF_DIST"
741 ;;
742 test)
743 echo "Test a little bit"
744 here=$(pwd)
745 echo "Path: $here"
746 cd $HOME
747 echo "List1"
748 ls
749 cd $here
750 echo "List2"
751 ls
752
753 karaf_prepare
754 ;;
755 v)
756 echo "List app versions"
757 mvn --version
758 git --version
759 echo "node: " ; node --version
760 echo "npm: " ; npm --version
761 echo "jq: " ; jq --version
762 echo "bower" ; bower --version
763 ;;
764 restart)
765 echo "restart command"
766 karaf_checkrunning
767 if [ "$running" = "true" ] ; then
768 $ODL_KARAF_HOME/bin/stop
769 karaf_waittillstopped
770 karaf_startifnotrunning $2
771 else
772 echo "Already stopped .. do start"
773 karaf_startifnotrunning $2
774 fi
775 ;;
776
777 stop)
778 echo "stop command"
779 karaf_checkrunning
780 if [ "$running" = "true" ] ; then
781 $ODL_KARAF_HOME/bin/stop
782 karaf_waittillstopped
783 else
784 echo "Already stopped"
785 fi
786 ;;
787 start)
788 echo "start command"
789 karaf_startifnotrunning $2
790 ;;
791 bower)
792 echo "Install bower"
793 cd ./ux/mwtnCommons/mwtnCommons-module/src/main/resources/mwtnCommons/
794 ./bowerInstall.sh
795 cd $here
796 ;;
797
798 dbclean)
799 database_cleansetup
800 ;;
801
802 untar)
803 echo "Extract karaf"
804 prepare nodlux
805 ;;
806
807 prepare)
808 echo "Prepare prepare"
809 prepare $2
810 ;;
811
812 a)
813 echo "Compile all"
814 mvn clean install -DskipTests
815 if [[ $? -ne 0 ]] ; then
816 echo "could not complete"
817 else
818 do_install m2
819 fi
820 ;;
821
822 d)
823 app="devicemanager"
824 echo "Compile $app"
825 cd apps/$app
826 mvn clean install -DskipTests
827 rc=$?
828 cd $here
829 if [[ $rc -ne 0 ]] ; then
830 echo "could not complete"
831 else
832 do_install m2 d
833 fi
834 ;;
835
836 distremove)
837 karaf_distremove $2
838 ;;
839
840 ib)
841 do_install build $2
842 ;;
843
844 imd)
845 do_install m2 d $2
846 ;;
847
848 im)
849 do_install m2 $2
850 ;;
851
852 it)
853 do_install tar $2
854 ;;
855
856 karafclean)
857 karaf_cleanstart
858 ;;
859
860 log)
861 vi dist/data/log/karaf.log
862 ;;
863
864 migrate)
865 echo "Migrate index$2 to index$3"
866 elasticdump --input=http://localhost:9200/sdnevents_$2 --output=http://localhost:9200/sdnevents_$3 --type=data --limit=100000
867 ;;
868 mvn)
869 echo "try to compile $2"
870 here=`pwd`
871 cd "$2"
872 mvn clean install -DskipTests
873 cd "$here"
874 ;;
875 status)
876 karaf_status
877 ;;
878
879 debug)
880 karaf_enable_logs $2
881 ;;
882
883 *)
884 if [ ! "$1" == "help" ] ; then
885 echo "ERROR Unknown command $1"
886 fi
887 echo "Commands:"
888 echo " a for build all and install from M2"
889 echo " build enter build subsystem"
890 echo " build, deliver"
891 echo " bower for install bower"
892 echo " cli start karaf command line"
893 echo " cluster xx cluster commands and all other commands"
894 echo " status, ib, im, stop, push, distremove, cp"
895 echo " env List environment variables"
896 echo " d for devicemanager and install from M2"
897 echo " dbclean clean db and load with initial data"
898 echo " debug activate debug for netconf and mwtn"
899 echo " distremove remove existing karaf distribution"
900 echo " dlux install DLUX patch. Use dlux [m2|tar|create] to install from m2-repository or install tar file or create tar file"
901 echo " help List this help"
902 echo " ib for install from Build-directory"
903 echo " im for install from M2-directory"
904 echo " imd for install from M2-directory. Delete logs before start command"
905 echo " it fn install tar file to container"
906 echo " karafclean start clean and install apps on karaf"
907 echo " kill hard termination of ODL instance"
908 echo " log vi karaf.log"
909 echo " migrate migrate Param1 Param2 Migrate on localhost"
910 echo " mvn [folder] compile folder with maven with parameter -DskipTests"
911 echo " prepare [nodlux] to install and prepare a karaf. tar version expected in Downloads."
912 echo " untar to extract karaf."
913 echo " test do some testing"
914 echo " start start karaf"
915 echo " status display karaf status"
916 echo " stop stop and wait karaf"
917 echo " restart stop and start karaf"
918 echo " repoclean clean the repositories"
919 echo " v get Versions"
920 ;;
921esac
922fi
923
924unset install_err
925