-
Notifications
You must be signed in to change notification settings - Fork 122
/
admin.sh
executable file
·152 lines (138 loc) · 5.63 KB
/
admin.sh
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
#!/bin/bash
function isDefined {
local VAR="$1"; shift
local VAL="${!VAR}"
if [ "${VAL}" == '' ]
then
echo "variable ${VAR} is undefined or empty. Exit 12"
exit 12
fi
}
# a safe method, but doesn't distinguish between wsl2 and docker
# if [[ -f /proc/1/sched && $(cat /proc/1/sched | head -n 1 | grep init) ]]
# the folowing line distinguishes between wsl2 and docker, but uses a deprecated feature
if [ -f /.dockerenv ]
then
echo 'running in a docker container - exit 12 to avoid problems :-)'
exit 12
fi
DB_MODE='embedded'
DB_NAME='openroberta-db'
DB_PARENTDIR='db-embedded'
JAVA_LIB_DIR='./lib'
ADMIN_DIR='./admin'
STATIC_RESOURCES='./staticResources'
XMX=''
RDBG=''
QUIET='no'
while true
do
case "$1" in
-git-mode) DB_MODE='embedded'
DB_NAME='openroberta-db'
DB_PARENTDIR='./OpenRobertaServer/db-embedded'
JAVA_LIB_DIR='./OpenRobertaServer/target/resources'
ADMIN_DIR='./admin' # this directory is .gitignore-d
STATIC_RESOURCES='./OpenRobertaServer/staticResources'
shift ;;
-db-mode) DB_MODE=$2
shift; shift ;;
-db-name) DB_NAME=$2
shift; shift ;;
-db-parentdir) DB_PARENTDIR=$2
shift; shift ;;
-java-lib-dir) JAVA_LIB_DIR=$2
shift; shift ;;
-admin-dir) ADMIN_DIR=$2
shift; shift ;;
-static-resources) STATIC_RESOURCES=$2
shift; shift ;;
-Xmx*) XMX=$1
shift ;;
-rdbg) RDBG='-agentlib:jdwp=transport=dt_socket,server=y,address=0.0.0.0:2000,suspend=y'
shift ;;
-q) QUIET='yes'
shift ;;
-h|-help|--help) cat admin-help.txt
exit 0 ;;
*) break ;;
esac
done
isDefined DB_MODE
isDefined DB_NAME
isDefined DB_PARENTDIR
isDefined JAVA_LIB_DIR
isDefined ADMIN_DIR
DB_URI_HSQL="jdbc:hsqldb:hsql://localhost/$DB_NAME"
DB_URI_FILE="jdbc:hsqldb:file:$DB_PARENTDIR/$DB_NAME"
case "$DB_MODE" in
embedded) DB_URI="$DB_URI_FILE" ;;
server) DB_URI="$DB_URI_HSQL" ;;
*) echo 'invalid db-mode. Exit 12'
exit 12;;
esac
if [ "$QUIET" = 'no' ]
then
cat admin-help.txt
fi
mkdir -p "$ADMIN_DIR/logs"
mkdir -p "$ADMIN_DIR/tutorial"
mkdir -p "$ADMIN_DIR/dbBackup"
ADMIN_LOG_FILE="$ADMIN_DIR/logs/admin.log"
SERVER_LOG_FILE="$ADMIN_DIR/logs/server.log"
# get the command
CMD="$1"; shift
# show the database URI for commands, which need them
case "$CMD" in
version) : ;;
start*) : ;;
*) echo ''
echo "operating in $DB_MODE data base mode"
echo "the database URI in server mode is: $DB_URI_HSQL"
echo "the database URI in embedded mode is: $DB_URI_FILE"
echo '' ;;
esac
# process the command
RC=0
case "$CMD" in
sql-client) echo 'command line sql client. Type commands, exit with an empty line'
java $RDBG $XMX -cp $JAVA_LIB_DIR/\* de.fhg.iais.roberta.main.Administration sql-client "$DB_URI"
RC=$? ;;
sql-gui) hsqldbJar="$JAVA_LIB_DIR/hsqldb.jar"
java $RDBG $XMX -jar "${hsqldbJar}" --driver org.hsqldb.jdbc.JDBCDriver --url "$DB_URI" --user orA --password Pid
RC=$? ;;
sql-exec) SQL="$1";
echo "execute the sql statement '$SQL'"
java $RDBG $XMX -cp $JAVA_LIB_DIR/\* de.fhg.iais.roberta.main.Administration sql-exec "$DB_URI" "$SQL"
RC=$? ;;
create-empty-db) java -cp $JAVA_LIB_DIR/\* de.fhg.iais.roberta.main.Administration create-empty-db "$DB_URI_FILE" >>$ADMIN_LOG_FILE 2>&1
RC=$? ;;
version) java -cp $JAVA_LIB_DIR/\* de.fhg.iais.roberta.main.Administration version
RC=$? ;;
'') echo 'no command. Script terminates with exit 0'
exit 0 ;;
# ----------------------------------------------------------------------------------------------------------------------------------------------
start-server) case "$DB_MODE" in
server) echo 'starting the jetty server with a data base in server mode. Server must be running' ;;
embedded) if [[ ! -d $DB_PARENTDIR ]]; then
echo 'No database found. An empty database will be created.'
java -cp lib/\* de.fhg.iais.roberta.main.Administration create-empty-db "$DB_URI_FILE" >>$ADMIN_LOG_FILE 2>&1
fi
echo 'starting the jetty server with a data base in embedded mode' ;;
esac
java $RDBG $XMX -cp ${JAVA_LIB_DIR}/\* de.fhg.iais.roberta.main.ServerStarter \
-d database.mode="$DB_MODE" \
-d database.parentdir=$DB_PARENTDIR \
-d database.name=$DB_NAME \
-d server.staticresources.dir="$STATIC_RESOURCES" \
-d server.admin.dir=$ADMIN_DIR \
$* >>$SERVER_LOG_FILE 2>&1
;;
# ----------------------------------------------------------------------------------------------------------------------------------------------
*) echo "*** invalid command ignored: '$CMD' ***"
RC=0 ;;
esac
if [ $RC -ne 0 ]
then
echo '*** the command did NOT succeed. Look into console output and logfiles ***'
fi