]> WPIA git - gigi.git/blob - doc/scripts/gigi
ba3677e04d64c67955c5f716f0b089e5d63d5aec
[gigi.git] / doc / scripts / gigi
1 #!/bin/sh
2
3 : ${GIGI_CONF_DIR:=/etc/wpia/gigi}
4
5 [ -r "$GIGI_CONF_DIR/launcher.conf" ] && . "$GIGI_CONF_DIR/launcher.conf"
6
7 # assign default values
8 : \
9     ${JDBC_DRIVER:=/usr/share/java/postgresql-jdbc4.jar} \
10     ${GIGI_EXEC:=/usr/share/java/gigi.jar} \
11     ${GIGI_DATA_DIR:=/var/lib/wpia-gigi}
12
13 die() {
14     if [ $# -ge 1 ]; then
15         printf >&2 'Could not %s.\n' "$1"
16     fi
17     exit 1
18 }
19
20 cd "$GIGI_DATA_DIR" || die 'move to data directory'
21
22 runGigiClass() {
23     class=$1
24     shift
25     if [ $# -ge 1 ]; then
26         java_opts="$1"
27         shift
28     fi
29     exec java $java_opts -cp "$JDBC_DRIVER:$GIGI_EXEC" club.wpia.gigi.$class "$@"
30 }
31
32 command="$1"
33 shift
34 case "$command" in
35     start) runGigiClass Launcher ;;
36     debug) runGigiClass Launcher "-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=8000" ;;
37     start-daemon)
38         exec 3</etc/cacert/gigi/conf.tar || die 'open config'
39         exec 4>>/var/log/wpia-gigi.log || die 'open log'
40         runGigiClass Launcher <&3 >&4 2>&1 &
41         echo $! > /var/run/wpia-gigi.pid
42         ;;
43     signer) runGigiClass util.SimpleSigner ;;
44     reset-database) runGigiClass util.DatabaseManager ;;
45     fetch-alexa) runGigiClass util.HighFinancialValueFetcher "" "$@" ;;
46     fetch-locales) runGigiClass util.FetchLocales "" "$@" ;;
47     signer-conf)
48         mkdir -p "$GIGI_DATA_DIR/config" || die 'create config directory'
49         cd "$GIGI_DATA_DIR/config" || die 'move to config directory'
50         tar x gigi.properties
51         ;;
52     *)
53         cat >&2 << 'EOF'
54 Usage: gigi COMMAND [ARGUMENT...]
55
56 Commands:
57     start - start gigi
58     debug - start gigi in debug mode (on port 8000, with config from stdin)
59     start-daemon - start gigi in background (using config from /etc/cacert/gig/config.tar)
60     signer - start the simple signer
61     signer-conf - extract config for simple signer (and reset-database) from the tar from stdin
62     reset-database - reset the database
63     fetch-alexa - fetch domains with high financial value from Alexa top 1 million list; required argument: target file, optional argument: number of domains to save
64     fetch-locales - fetch the localisation; optional argument: URL pattern to indicate download location
65 EOF
66 esac