summaryrefslogtreecommitdiff
path: root/salt/openbook/ci/files/openbookctl
diff options
context:
space:
mode:
authorCarlos Konstanski <ckonstanski@pippiandcarlos.com>2017-08-30 13:09:56 -0600
committerCarlos Konstanski <ckonstanski@pippiandcarlos.com>2017-08-30 13:09:56 -0600
commit649f0dd9c5ca586d8b637400dd19c0c4059447d6 (patch)
tree5ccc992a3aa5de1bcb510911dfdb21e6a54bd197 /salt/openbook/ci/files/openbookctl
initial commit
Diffstat (limited to 'salt/openbook/ci/files/openbookctl')
-rw-r--r--salt/openbook/ci/files/openbookctl85
1 files changed, 85 insertions, 0 deletions
diff --git a/salt/openbook/ci/files/openbookctl b/salt/openbook/ci/files/openbookctl
new file mode 100644
index 0000000..894368d
--- /dev/null
+++ b/salt/openbook/ci/files/openbookctl
@@ -0,0 +1,85 @@
+#!/bin/bash
+
+echo 'mysql root password: {% raw %}{{ openbook_database_password }}{% endraw %}'
+echo 'wsrep_node_address: {% raw %}{{ ansible_default_ipv4.address }}{% endraw %}'
+echo 'wsrep_cluster_address: gcomm://{% raw %}{{ openbook_gcomm_addresses }}{% endraw %}'
+
+wait_for_database() {
+ echo "Waiting for database to start..."
+ started=1
+ for i in {120..0}; do
+ if echo 'SELECT 1' | mysql -h 127.0.0.1 -u root --password='{% raw %}{{ openbook_database_password }}{% endraw %}' &>/dev/null; then
+ started=0
+ break
+ fi
+ sleep 1
+ done
+ if [ $started -eq 1 ]; then
+ echo "Error: database did not start."
+ exit 1
+ fi
+}
+
+ensure_openbook_databases_created() {
+ if ! echo "SHOW DATABASES;" | mysql -h 127.0.0.1 -u root --password='{% raw %}{{ openbook_database_password }}{% endraw %}' 2>/dev/null | fgrep 'openbook'; then
+ echo "Creating Openbook schema..."
+ mysql -h 127.0.0.1 -u root --password='{% raw %}{{ openbook_database_password }}{% endraw %}' &>/dev/null < {{ pillar["database"]["files"]["create_openbook_schemas"]["path"] }}/{{ pillar["database"]["files"]["create_openbook_schemas"]["name"] }}
+ fi
+}
+
+do_start() {
+ chmod 777 {{ pillar["database"]["dirs"]["var_lib_mysql"]["name"] }}
+ chmod 777 {{ pillar["database"]["dirs"]["var_log_mysql"]["name"] }}
+ {{ pillar["ansible"]["dirs"]["output"]["name"] }}/database/run.sh
+ wait_for_database
+ ensure_openbook_databases_created
+ {{ pillar["ansible"]["dirs"]["output"]["name"] }}/api_server/run.sh
+ {{ pillar["ansible"]["dirs"]["output"]["name"] }}/admin_web_ui/run.sh
+ {{ pillar["ansible"]["dirs"]["output"]["name"] }}/customer_web_ui/run.sh
+ echo
+ echo "Openbook started. All components may not be fully initialized and available."
+ echo "It is highly recommended to wait until initialization is complete before"
+ echo "starting the next node in the cluster. To monitor the state, run:"
+ echo
+ echo "watch -n 5 \"lsof -i -n -P 2>/dev/null | fgrep '*:808'\""
+ echo
+ echo "When the output looks like the following, the node is fully initialized:"
+ echo "(Your PIDs will vary)"
+ echo
+ echo "java 27424 root 73u IPv6 65463 0t0 TCP *:8080 (LISTEN)"
+ echo "java 27264 root 73u IPv6 65430 0t0 TCP *:8081 (LISTEN)"
+ echo "java 27349 root 73u IPv6 65430 0t0 TCP *:8082 (LISTEN)"
+}
+
+do_stop() {
+ docker stop {{ pillar["customer_web_ui"]["container_name"] }}
+ docker stop {{ pillar["admin_web_ui"]["container_name"] }}
+ docker stop {{ pillar["api_server"]["container_name"] }}
+ docker stop {{ pillar["database"]["container_name"] }}
+ docker container prune -f
+}
+
+do_help() {
+ echo "Usage:"
+ echo " $0 start"
+ echo " $0 stop"
+ echo " $0 test_database"
+}
+
+case $1 in
+ start*)
+ do_start
+ ;;
+ stop*)
+ do_stop
+ ;;
+ test_database*)
+ wait_for_database
+ echo "Database is up."
+ ;;
+ *)
+ do_help
+ ;;
+esac
+
+exit 0