From c5e55e7f2e95be0e5d8278df1fb2cb7924530746 Mon Sep 17 00:00:00 2001 From: Disassembler Date: Sun, 29 Apr 2018 20:48:57 +0200 Subject: [PATCH] Rewrite spotter-appmgr (partial squashmerge) --- activemq.sh | 7 +- activemq/etc/init.d/activemq | 3 +- basic.sh | 17 +- basic/etc/init.d/docker | 4 +- basic/etc/periodic/daily/acme-sh | 3 + basic/etc/spotter/apps.json | 1 - basic/srv/config.json | 134 ++++++++ basic/srv/portal/css/style.css | 9 +- basic/srv/portal/error.html | 15 + basic/srv/portal/index.html | 68 ++-- basic/srv/portal/js/script.js | 24 +- basic/usr/bin/spotter-appmgr | 317 ++++++++++++++++++ basic/usr/local/bin/spotter-appmgr | 197 ----------- basic/usr/local/bin/update-acme.sh | 6 - ccleanup.sh | 12 +- ccleanup/etc/init.d/ccleanup | 9 +- ckan.sh | 14 +- ckan/etc/init.d/ckan | 10 +- ckan/srv/ckan/conf/ckan.ini | 2 +- ckandp.sh | 7 +- ckandp/etc/init.d/ckandp | 3 +- cts.sh | 12 +- cts/etc/init.d/cts | 9 +- flsms.sh | 13 +- flsms/etc/init.d/flsms | 9 +- gnuhealth.sh | 14 +- gnuhealth/etc/init.d/gnuhealth | 9 +- kanboard.sh | 13 +- kanboard/etc/init.d/kanboard | 9 +- mariadb.sh | 9 +- mariadb/etc/init.d/mariadb | 7 +- mifosx.sh | 16 +- mifosx/etc/init.d/mifosx | 9 +- mifosx/srv/mifosx/conf/server.xml | 2 +- motech.sh | 13 +- motech/etc/init.d/motech | 9 +- .../conf/config/motech-settings.properties | 2 +- odk.sh | 18 +- odk/etc/init.d/odk | 9 +- odk/srv/odk/conf/server.xml | 2 +- odkbuild.sh | 11 +- odkbuild/etc/init.d/odkbuild | 9 +- omk.sh | 13 +- omk/etc/init.d/omk | 9 +- pandora.sh | 13 +- pandora/etc/init.d/pandora | 9 +- postfix.sh | 7 +- postfix/etc/init.d/postfix | 3 +- postgres.sh | 8 +- postgres/etc/init.d/postgres | 7 +- rabbitmq.sh | 7 +- rabbitmq/etc/init.d/rabbitmq | 3 +- redis.sh | 7 +- redis/etc/init.d/redis | 3 +- sahana-demo.sh | 17 +- sahana-demo/etc/init.d/sahana-demo | 9 +- .../srv/sahana-demo/conf/000_config.py | 2 +- sahana.sh | 12 +- sahana/etc/init.d/sahana | 9 +- sahana/srv/sahana/conf/000_config.py | 2 +- sambro.sh | 17 +- sambro/etc/init.d/sambro | 9 +- sambro/srv/sambro/conf/000_config.py | 2 +- seeddms.sh | 12 +- seeddms/etc/init.d/seeddms | 9 +- sigmah.sh | 12 +- sigmah/etc/init.d/sigmah | 9 +- solr.sh | 7 +- solr/etc/init.d/solr | 3 +- ushahidi.sh | 13 +- ushahidi/adminpwd.sql | 2 +- ushahidi/etc/init.d/ushahidi | 9 +- ushahidi/srv/ushahidi/conf/config.json | 2 +- 73 files changed, 773 insertions(+), 539 deletions(-) create mode 100755 basic/etc/periodic/daily/acme-sh delete mode 100644 basic/etc/spotter/apps.json create mode 100644 basic/srv/config.json create mode 100644 basic/srv/portal/error.html create mode 100755 basic/usr/bin/spotter-appmgr delete mode 100755 basic/usr/local/bin/spotter-appmgr delete mode 100755 basic/usr/local/bin/update-acme.sh diff --git a/activemq.sh b/activemq.sh index d14f265..e9956c7 100755 --- a/activemq.sh +++ b/activemq.sh @@ -7,12 +7,9 @@ docker image ls | grep -q java || $(realpath $(dirname "${0}"))/java.sh # Build Docker container docker build -t activemq ${SOURCE_DIR} +cp ${SOURCE_DIR}/etc/init.d/activemq /etc/init.d/activemq +rc-update -u # Configure ActiveMQ mkdir -p /srv/activemq/data chown -R 61616:61616 /srv/activemq/data - -# Configure Solr service -cp ${SOURCE_DIR}/etc/init.d/activemq /etc/init.d/activemq -rc-update add activemq -service activemq start diff --git a/activemq/etc/init.d/activemq b/activemq/etc/init.d/activemq index 2638975..63f66f7 100755 --- a/activemq/etc/init.d/activemq +++ b/activemq/etc/init.d/activemq @@ -3,8 +3,7 @@ description="ActiveMQ docker container" depend() { - need docker net - use dns logger netmount + need docker } start() { diff --git a/basic.sh b/basic.sh index ca4e4e0..ff3ea59 100755 --- a/basic.sh +++ b/basic.sh @@ -27,20 +27,23 @@ cp ${SOURCE_DIR}/etc/conf.d/ntpd /etc/conf.d/ntpd # Create a self-signed certificate mkdir /etc/ssl/private -openssl req -x509 -new -out /etc/ssl/certs/services.pem -keyout /etc/ssl/private/services.key -nodes -days 3654 -subj "/CN=$(hostname)" +openssl req -x509 -new -out /etc/ssl/certs/services.pem -keyout /etc/ssl/private/services.key -nodes -days 7305 -subj "/CN=$(hostname)" chmod 640 /etc/ssl/private/services.key -# Configure acme.sh -cp ${SOURCE_DIR}/usr/local/bin/update-acme.sh /usr/local/bin/update-acme.sh -/usr/local/bin/update-acme.sh - # Configure nginx cp ${SOURCE_DIR}/etc/nginx/nginx.conf /etc/nginx/nginx.conf +# Download and configure acme.sh +mkdir /etc/acme.sh.d +wget https://raw.githubusercontent.com/Neilpang/acme.sh/master/acme.sh -O /usr/bin/acme.sh +sed -i 's|$HOME/.$PROJECT_NAME|/etc/acme.sh.d|' /usr/bin/acme.sh +cp ${SOURCE_DIR}/etc/periodic/daily/acme-sh /etc/periodic/daily/acme-sh +chmod +x /usr/bin/acme.sh + # Copy Spotter resources mkdir /etc/spotter -cp ${SOURCE_DIR}/etc/spotter/apps.json /etc/spotter/apps.json -cp ${SOURCE_DIR}/usr/local/bin/spotter-appmgr /usr/local/bin/spotter-appmgr +cp ${SOURCE_DIR}/srv/config.json /srv/config.json +cp ${SOURCE_DIR}/usr/bin/spotter-appmgr /usr/bin/spotter-appmgr cp -r ${SOURCE_DIR}/srv/portal /srv/portal # Configure services diff --git a/basic/etc/init.d/docker b/basic/etc/init.d/docker index 72a5cbc..cbd9a86 100755 --- a/basic/etc/init.d/docker +++ b/basic/etc/init.d/docker @@ -36,7 +36,5 @@ start_pre() { } start_post() { - until [ -e /var/run/docker.sock ]; do - usleep 100000 - done + ewaitfile 1 /var/run/docker.sock } diff --git a/basic/etc/periodic/daily/acme-sh b/basic/etc/periodic/daily/acme-sh new file mode 100755 index 0000000..5b3d5e3 --- /dev/null +++ b/basic/etc/periodic/daily/acme-sh @@ -0,0 +1,3 @@ +#!/bin/sh + +[ -x /usr/bin/acme.sh ] && /usr/bin/acme.sh --cron >/dev/null diff --git a/basic/etc/spotter/apps.json b/basic/etc/spotter/apps.json deleted file mode 100644 index 7cfd9a6..0000000 --- a/basic/etc/spotter/apps.json +++ /dev/null @@ -1 +0,0 @@ -{"_": {"domain": "spotter.vm", "port": "443"}, "cluster-spotter": {}} diff --git a/basic/srv/config.json b/basic/srv/config.json new file mode 100644 index 0000000..4b7670a --- /dev/null +++ b/basic/srv/config.json @@ -0,0 +1,134 @@ +{ + "apps":{ + "ckan":{ + "host":"ckan", + "login":"N/A", + "password":"N/A", + "tiles":[], + "tiles-shown":false + }, + "crisiscleanup":{ + "host":"cc", + "login":"N/A", + "password":"N/A", + "tiles":[], + "tiles-shown":false + }, + "cts":{ + "host":"cts", + "login":"N/A", + "password":"N/A", + "tiles":[], + "tiles-shown":false + }, + "frontlinesms":{ + "host":"sms", + "login":"N/A", + "password":"N/A", + "tiles":[], + "tiles-shown":false + }, + "gnuhealth":{ + "host":"gh", + "login":"N/A", + "password":"N/A", + "tiles":["gnuhealth-clients"], + "tiles-shown":false + }, + "kanboard":{ + "host":"kb", + "login":"N/A", + "password":"N/A", + "tiles":["kanboard-mobile"], + "tiles-shown":false + }, + "mifosx":{ + "host":"mifosx", + "login":"N/A", + "password":"N/A", + "tiles":["mifosx-mobile"], + "tiles-shown":false + }, + "motech":{ + "host":"motech", + "login":"N/A", + "password":"N/A", + "tiles":[], + "tiles-shown":false + }, + "opendatakit":{ + "host":"odk", + "login":"N/A", + "password":"N/A", + "tiles":["opendatakit-clients"], + "tiles-shown":false + }, + "opendatakit-build":{ + "host":"odkbuild", + "login":"N/A", + "password":"N/A", + "tiles":[], + "tiles-shown":false + }, + "openmapkit":{ + "host":"omk", + "login":"N/A", + "password":"N/A", + "tiles":["geoodk-clients", "openmapkit-clients"], + "tiles-shown":false + }, + "pandora":{ + "host":"pandora", + "login":"N/A", + "password":"N/A", + "tiles":[], + "tiles-shown":false + }, + "sahana":{ + "host":"sahana", + "login":"N/A", + "password":"N/A", + "tiles":[], + "tiles-shown":false + }, + "sahana-demo":{ + "host":"sahana-demo", + "login":"N/A", + "password":"N/A", + "tiles":[], + "tiles-shown":false + }, + "sambro":{ + "host":"sambro", + "login":"N/A", + "password":"N/A", + "tiles":["sambro-mobile"], + "tiles-shown":false + }, + "seeddms":{ + "host":"dms", + "login":"N/A", + "password":"N/A", + "tiles":[], + "tiles-shown":false + }, + "sigmah":{ + "host":"sigmah", + "login":"N/A", + "password":"N/A", + "tiles":[], + "tiles-shown":false + }, + "ushahidi":{ + "host":"ush", + "login":"N/A", + "password":"N/A", + "tiles":["ushahidi-mobile"], + "tiles-shown":false + } + }, + "host":{ + "domain":"spotter.vm", + "port": "443" + } +} diff --git a/basic/srv/portal/css/style.css b/basic/srv/portal/css/style.css index 7bcc3a5..9790c24 100644 --- a/basic/srv/portal/css/style.css +++ b/basic/srv/portal/css/style.css @@ -50,7 +50,7 @@ header p { margin: 0px; } -.c, .c2 { +.c { background-color: white; position: relative; min-width: 365px; @@ -62,9 +62,6 @@ header p { margin-right: 13px; border: solid 1px black; padding: 10px; -} - -.c { display: none; } @@ -73,6 +70,10 @@ header p { width: 95%; } +.visible { + display: initial; +} + .ico { margin-right: 5px; width: 20px; diff --git a/basic/srv/portal/error.html b/basic/srv/portal/error.html new file mode 100644 index 0000000..41a855f --- /dev/null +++ b/basic/srv/portal/error.html @@ -0,0 +1,15 @@ + + + + + + + + + Chyba + + +

Chyba spojení

+

Aplikace, ke které se pokoušíte připojit, není dostupná. Nejspíše byla vypnuta správcem serveru.

+ + diff --git a/basic/srv/portal/index.html b/basic/srv/portal/index.html index c055f63..f2c7284 100644 --- a/basic/srv/portal/index.html +++ b/basic/srv/portal/index.html @@ -19,7 +19,7 @@
-

Sahana EDENSahana EDEN

+

Sahana EDENSahana EDEN

Registr kontaktů asociací, organizací, jednotek zaměstnanců, dobrovolníků, Registr prostředků, materiálních zdrojů určených pro činnost v krizových situacích, logistika krizového zboží ve skladištích, úkrytech, organizace lidských zdrojů, diobrovolníků, mapová vizualizace pro lokalizaci a popis krizové události a mnoho dalších funkcí.

-

Sahana EDEN DEMOSahana EDEN DEMO

+

Sahana EDEN DEMOSahana EDEN DEMO

Přístup určený k bezpečnému vyzkoušení aplikace. Zde můžete přidávat i mazat testovací data.

-

Sahana EDEN SAMBROSahana EDEN SAMBRO

+

Sahana EDEN SAMBROSahana EDEN SAMBRO

Samostatná instance Sahana EDEN s šablonou SAMBRO.

-
-

Crisis CleanupCrisis Cleanup

+
+

Crisis CleanupCrisis Cleanup

Mapování krizové pomoci při odstraňování následků katastrof a koordinaci práce. Jde o majetek, ne o lidi.

  • Login:
  • @@ -66,7 +66,7 @@
-

CKANCKAN

+

CKANCKAN

Repository management a datová analýza pro vytváření otevřených dat.

  • Login:
  • @@ -74,27 +74,27 @@
-
-

Open Data KitODK Build

+
+

Open Data KitODK Build

Sběr dat s pomocí smartphone.
Aplikace pro návrh formulářů

XLSForm - online konverter XLS.
ODK Form UploaderODK Form Uploader
ODK ValidateODK Validate

-
+

Open Data KitODK Collect

Mobilní aplikace
ODK CollectODK Collect pro Android
ODK BriefcaseODK Briefcase

    -
  • URL:
  • +
  • URL: https://odk.{host}/aggregate
-
-

Open Data KitODK Aggregate

+
+

Open Data KitODK Aggregate

Sběr dat s pomocí smartphone.
GeoODK Collect - náhrada papírových dotazníků smartphonem.

@@ -104,8 +104,8 @@
-
-

Open Map KitOpenMapKit Server

+
+

Open Map KitOpenMapKit Server

Sběr dat s pomocí smartphone.

-
+

Open Map KitOpenMapKit

Mobilní aplikace
ODK CollectODK Collect pro Android
AndroidOpenMapKit pro Android 4.1 a vyšší

    -
  • URL:
  • +
  • URL: https://omk.{host}
-
-

FrontlineSMSFrontlineSMS

+
+

FrontlineSMSFrontlineSMS

SMS messaging přes veřejné datové brány

  • Login:
  • @@ -144,7 +144,7 @@
-

SeedDMSSeedDMS

+

SeedDMSSeedDMS

Dokument management na dokumentaci a projektovou dokumentaci

  • Login:
  • @@ -153,7 +153,7 @@
-

Pan.do/raPan.do/ra

+

Pan.do/raPan.do/ra

Media management na foto a video z krizové události. Tvorba metadat, komentářů, lokalizace v čase a na mapě.

  • Login:
  • @@ -162,7 +162,7 @@
-

UshahidiUshahidi

+

UshahidiUshahidi

Reakce na krizovou událost. Shromažďujte zprávy od obětí a pracovníků v terénu prostřednictvím SMS, e-mailu, webu, Twitteru.

@@ -189,7 +189,7 @@
-

KanboardKanboard

+

KanboardKanboard

Usnadňuje tvorbu a řízení projektů s pomocí Kanban metodiky.

-

CTSCTS

+

CTSCTS

Logistika hmotné pomoci pro humanitární potřeby.

  • Login:
  • @@ -218,7 +218,7 @@
-

GNU HealthGNU Health

+

GNU HealthGNU Health

Zdravotní a nemocniční informační systém.

  • Login:
  • @@ -235,12 +235,12 @@ LinuxLinux

      -
    • URL:
    • +
    • URL: gh.{host}
-

SigmahSigmah

+

SigmahSigmah

Rozpočtování získávání finančních prostředků.

  • Login:
  • @@ -249,7 +249,7 @@
-

MotechMotech

+

MotechMotech

Integrace zdravotnických a komunikačních služeb.

  • Login:
  • @@ -258,7 +258,7 @@
-

Mifos XMifos X

+

Mifos XMifos X

Nástroj na rozvojovou, humanitární pomoc a mikrofinancování.

@@ -296,7 +296,7 @@

Portable Open Street Map - softwarový balík na offline používání OpenStreet Map v samostatné virtuální image.

-
+

Cluster SpotterCluster Spotter

Info o Misi a Vizi projektu, včetně kontaktu. Zachovejte data bezpečná a neposkytujte je nepovolaným osobám.
CC 4.0 CZ by TS. Content is based on PD, CC, GNU/GPL. Brand names, trademarks belong to their respective holders. diff --git a/basic/srv/portal/js/script.js b/basic/srv/portal/js/script.js index 7a9558e..b51eeb3 100644 --- a/basic/srv/portal/js/script.js +++ b/basic/srv/portal/js/script.js @@ -1,13 +1,21 @@ $(function() { - $.getJSON('apps.json', function(data) { - var host = data._.domain + (data._.port != '443' ? ':'+data._.port : '') - $.each(data, function(id, props) { - var div = $('#'+id).show(); - if (props.hasOwnProperty('url')) - div.find('h2 a').attr('href', props.url.replace('{host}', host)); - $.each(props, function(key, value) { - div.find('.'+key).text(value.replace('{host}', host)); + $.getJSON('config.json', function(data) { + $.each(data.apps, function(app, appdata) { + if (!appdata['tiles-shown']) + return true; + var div = $('#'+app).show(); + div.find('.login').text(appdata.login); + div.find('.password').text(appdata.password); + $.each(appdata.tiles, function(tile) { + $('#'+tile).show(); }); }); + var host = data.host.domain + (data.host.port != '443' ? ':'+data.host.port : '') + $('a').each(function(){ + $(this).attr('href', $(this).attr('href').replace('{host}', host)); + }); + $('span').each(function(){ + $(this).text($(this).text().replace('{host}', host)); + }); }); }); diff --git a/basic/usr/bin/spotter-appmgr b/basic/usr/bin/spotter-appmgr new file mode 100755 index 0000000..ec7baed --- /dev/null +++ b/basic/usr/bin/spotter-appmgr @@ -0,0 +1,317 @@ +#!/usr/bin/python +# -*- coding: utf-8 -*- + +import argparse +import json +import os +import subprocess + +CONF_FILE = '/srv/config.json' +ISSUE_FILE = '/etc/issue' +NGINX_DIR = '/etc/nginx/conf.d' + +NGINX_TEMPLATE = '''server {{ + listen [::]:{port} ssl http2; + server_name {host}.{domain}; + + access_log /var/log/nginx/{app}.access.log; + error_log /var/log/nginx/{app}.error.log; + + location / {{ + proxy_pass http://{ip}:8080; + }} + + error_page 502 /errror.html; + location /error.html {{ + root /srv/portal; + }} +}} +''' + +NGINX_DEFAULT_TEMPLATE = '''server {{ + listen [::]:80 default_server ipv6only=off; + + location / {{ + return 301 https://$host:{port}$request_uri; + }} + location /.well-known/acme-challenge/ {{ + root /etc/acme.sh.d; + }} +}} + +server {{ + listen [::]:{port} ssl http2 default_server ipv6only=off; + root /srv/portal; + index index.html; + + location / {{ + try_files $uri $uri/ =404; + }} + location /config.json {{ + alias /srv/config.json; + }} + + error_page 404 /error.html; +}} +''' + +ISSUE_TEMPLATE = ''' +\x1b[1;32m _____ _ _ __ ____ __ + / ____| | | | | \\\\ \\\\ / / \\\\/ | + | (___ _ __ ___ | |_| |_ ___ _ _\\\\ \\\\ / /| \\\\ / | + \\\\___ \\\\| '_ \\\\ / _ \\\\| __| __/ _ \\\\ '__\\\\ \\\\/ / | |\\\\/| | + ____) | |_) | (_) | |_| || __/ | \\\\ / | | | | + |_____/| .__/ \\\\___/ \\\\__|\\\\__\\\\___|_| \\\\/ |_| |_| + | | + |_|\x1b[0m + + + + + \x1b[1;33mUPOZORNĚNÍ:\x1b[0m Neoprávněný přístup k tomuto zařízení je zakázán. + Musíte mít výslovné oprávnění k přístupu nebo konfiguraci tohoto zařízení. + Neoprávněné pokusy a kroky k přístupu nebo používání tohoto systému mohou mít + za následek občanské nebo trestní sankce. + + + \x1b[1;33mCAUTION:\x1b[0m Unauthozired access to this device is prohibited. + You must have explicit, authorized permission to access or configure this + device. Unauthorized attempts and actions to access or use this system may + result in civil or criminal penalties. + + + + + Pro přístup k aplikacím otevřete URL \x1b[1mhttps://{host}\x1b[0m ve Vašem + internetovém prohlížeči. + + + + + + +\x1b[0;30m +''' + +class SpotterManager: + def __init__(self): + # Load JSON configuration + with open(CONF_FILE, 'r') as f: + self.conf = json.load(f) + self.domain = self.conf['host']['domain'] + self.port = self.conf['host']['port'] + + def save_conf(self): + # Save a sorted JSON configuration object with indentation + with open(CONF_FILE, 'w') as f: + json.dump(self.conf, f, sort_keys=True, indent=4) + + def update_login(self, app, login, password): + # Update login and password for an app in the configuration + if login is not None: + self.conf['apps'][app]['login'] = login + if password is not None: + self.conf['apps'][app]['password'] = password + self.save_conf() + + def show_tiles(self, app): + # Update tiles-shown for the app in the configuration + self.conf['apps'][app]['tiles-shown'] = True + self.save_conf() + + def hide_tiles(self, app): + # Update tiles-shown for the app in the configuration + self.conf['apps'][app]['tiles-shown'] = False + self.save_conf() + + def start_app(self, app): + # Start the actual app service + subprocess.call(['/sbin/service', app, 'start']) + + def stop_app(self, app): + # Stop the actual app service + subprocess.call(['/sbin/service', app, 'stop']) + # Stop the app service's dependencies if they are not used by any other running app + deps = self.build_deps_tree() + for dep in self.get_app_deps(app): + if False not in [self.is_app_started(d) for d in deps[dep]]: + subprocess.call(['/sbin/service', dep, 'stop']) + + def build_deps_tree(self): + # Fisrt, build a dictionary of {app: [needs]} + needs = {} + for app in self.conf['apps']: + needs[app] = self.get_app_deps(app) + # Then reverse it to {need: [apps]} + deps = {} + for app, need in needs.iteritems(): + for n in need: + deps.setdefault(n, []).append(app) + return deps + + def get_app_deps(self, app): + # Get "needs" line from init script and split it to list, skipping first two elements (docker, net) + try: + with open(os.path.join('/etc/init.d', app), 'r') as f: + return [l.split()[2:] for l in f.readlines() if l.startswith('\tneed')][0] + except: + return [] + + def is_app_started(self, app): + # Check OpenRC service status without calling any binary + return os.path.exists(os.path.join('/run/openrc/started', app)) + + def enable_autostart(self, app): + # Add the app to OpenRC default runlevel + subprocess.call(['/sbin/rc-update', 'add', app]) + + def disable_autostart(self, app): + # Remove the app from OpenRC default runlevel + subprocess.call(['/sbin/rc-update', 'del', app]) + + def register_proxy(self, app): + # Rebuild nginx configuration using an actual IP of referenced app container + with open(os.path.join(NGINX_DIR, '{}.conf'.format(app)), 'w') as f: + f.write(NGINX_TEMPLATE.format(app=app, host=self.conf['apps'][app]['host'], ip=self.get_container_ip(app), domain=self.domain, port=self.port)) + subprocess.call(['/sbin/service', 'nginx', 'reload']) + + def unregister_proxy(self, app): + # Remove nginx configuration to prevent proxy mismatch when the container IP is reassigned to another container + nginx_conf = os.path.join(NGINX_DIR, '{}.conf'.format(app)) + if os.path.exists(nginx_conf): + os.unlink(nginx_conf) + subprocess.call(['/sbin/service', 'nginx', 'reload']) + + def get_container_ip(self, app): + # Return an IP address of a container. If the container is not running, return localhost address instead + try: + return subprocess.check_output(['/usr/bin/docker', 'inspect', '-f', '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}', app]).strip() + except: + return '127.0.0.1' + + def update_domain(self, domain, port): + self.domain = self.conf['host']['domain'] = domain + self.port = self.conf['host']['port'] = port + self.save_conf() + self.rebuild_nginx() + self.rebuild_issue() + self.restart_apps() + + def rebuild_nginx(self): + # Remove all nginx config files to prevent errors during reloads invoked by app restarts + for f in os.listdir(NGINX_DIR): + os.unlink(os.path.join(NGINX_DIR, f)) + # Rebuild nginx config for the portal app and restart nginx to properly bind the new listen port + with open(os.path.join(NGINX_DIR, 'default.conf'), 'w') as f: + f.write(NGINX_DEFAULT_TEMPLATE.format(port=self.port)) + subprocess.call(['/sbin/service', 'nginx', 'restart']) + + def rebuild_issue(self): + # Compile the HTTPS host displayed in terminal banner + host = self.domain + # If the dummy host is used, take an IP address of a primary interface instead + if self.domain == 'spotter.vm': + host = subprocess.check_output(['ip', 'route', 'get', '1']).split()[-1] + # Show port number only when using the non-default HTTPS port + if self.port != '443': + host = ':{}'.format(self.port) + # Rebuild the terminal banner + with open(ISSUE_FILE, 'w') as f: + f.write(ISSUE_TEMPLATE.format(host=host)) + + def restart_apps(self): + for app in self.conf['apps']: + # Check if a script for internal update of URL in the app exists and is executable and run it + script_path = os.path.join('/srv', app, 'update-url.sh') + if os.path.exists(script_path) and os.access(script_path, os.X_OK): + subprocess.call([script_path, '{}.{}'.format(self.conf['apps'][app]['host'], self.domain), self.port]) + # If the app is currently running, restart the app service + if self.is_app_started(app): + subprocess.call(['/sbin/service', app, 'restart']) + + def request_cert(self, email): + # Compile an acme.sh command for certificate requisition + cmd = ['/usr/bin/acme.sh', '--issue', '-d', self.domain] + for app in self.conf['apps']: + cmd += ['-d', '{}.{}'.format(self.conf['apps'][app]['host'], self.domain)] + cmd += ['-w', '/etc/acme.sh.d', '--accountemail', email] + # Request the certificate. If the requisition command fails, CalledProcessError will be raised + subprocess.check_output(cmd, stderr=subprocess.STDOUT) + # Install the issued certificate + subprocess.call(['/usr/bin/acme.sh', '--installcert', '-d', self.domain, '--keypath', '/etc/ssl/private/services.key', '--fullchainpath', '/etc/ssl/certs/services.pem', '--reloadcmd', 'service nginx reload']) + +if __name__ == '__main__': + parser = argparse.ArgumentParser(description='Spotter VM application manager') + subparsers = parser.add_subparsers() + + parser_update_login = subparsers.add_parser('update-login', help='Updates application login') + parser_update_login.set_defaults(action='update-login') + parser_update_login.add_argument('app', help='Application name') + parser_update_login.add_argument('login', help='Administrative login') + parser_update_login.add_argument('password', help='Administrative password') + + parser_show_tiles = subparsers.add_parser('show-tiles', help='Shows application tiles in Portal') + parser_show_tiles.set_defaults(action='show-tiles') + parser_show_tiles.add_argument('app', help='Application name') + + parser_hide_tiles = subparsers.add_parser('hide-tiles', help='Hides application tiles in Portal') + parser_hide_tiles.set_defaults(action='hide-tiles') + parser_hide_tiles.add_argument('app', help='Application name') + + parser_start_app = subparsers.add_parser('start-app', help='Start application including it\'s dependencies') + parser_start_app.set_defaults(action='start-app') + parser_start_app.add_argument('app', help='Application name') + + parser_stop_app = subparsers.add_parser('stop-app', help='Stops application including it\'s dependencies if they are not used by another running application') + parser_stop_app.set_defaults(action='stop-app') + parser_stop_app.add_argument('app', help='Application name') + + parser_enable_autostart = subparsers.add_parser('enable-autostart', help='Enables application autostart') + parser_enable_autostart.set_defaults(action='enable-autostart') + parser_enable_autostart.add_argument('app', help='Application name') + + parser_disable_autostart = subparsers.add_parser('disable-autostart', help='Disables application autostart') + parser_disable_autostart.set_defaults(action='disable-autostart') + parser_disable_autostart.add_argument('app', help='Application name') + + parser_register_proxy = subparsers.add_parser('register-proxy', help='Rebuilds nginx proxy target for an application container') + parser_register_proxy.set_defaults(action='register-proxy') + parser_register_proxy.add_argument('app', help='Application name') + + parser_unregister_proxy = subparsers.add_parser('unregister-proxy', help='Removes nginx proxy target for an application container') + parser_unregister_proxy.set_defaults(action='unregister-proxy') + parser_unregister_proxy.add_argument('app', help='Application name') + + parser_update_domain = subparsers.add_parser('update-domain', help='Rebuilds domain structure of VM with new domain name and new HTTPS port') + parser_update_domain.set_defaults(action='update-domain') + parser_update_domain.add_argument('domain', help='Domain name') + parser_update_domain.add_argument('port', help='HTTPS port') + + parser_request_cert = subparsers.add_parser('request-cert', help='Requests and installs Let\'s Encrypt certificate for currently set domain') + parser_request_cert.set_defaults(action='request-cert') + parser_request_cert.add_argument('email', help='Email address to receive certificate notifications') + + args = parser.parse_args() + sm = SpotterManager() + if args.action == 'update-login': + sm.update_login(args.app, args.login, args.password) + elif args.action == 'show-tiles': + sm.show_tiles(args.app) + elif args.action == 'hide-tiles': + sm.hide_tiles(args.app) + elif args.action == 'start-app': + sm.start_app(args.app) + elif args.action == 'stop-app': + sm.stop_app(args.app) + elif args.action == 'enable-autostart': + sm.enable_autostart(args.app) + elif args.action == 'disable-autostart': + sm.disable_autostart(args.app) + elif args.action == 'register-proxy': + sm.register_proxy(args.app) + elif args.action == 'unregister-proxy': + sm.unregister_proxy(args.app) + elif args.action == 'update-domain': + sm.update_domain(args.domain, args.port) + elif args.action == 'request-cert': + sm.request_cert(args.email) diff --git a/basic/usr/local/bin/spotter-appmgr b/basic/usr/local/bin/spotter-appmgr deleted file mode 100755 index 0c6779b..0000000 --- a/basic/usr/local/bin/spotter-appmgr +++ /dev/null @@ -1,197 +0,0 @@ -#!/usr/bin/python -# -*- coding: utf-8 -*- - -import argparse -import json -import os -import subprocess - -CONF_FILE = '/etc/spotter/apps.json' -ISSUE_FILE = '/etc/issue' -NGINX_DIR = '/etc/nginx/conf.d' - -NGINX_TEMPLATE = '''server {{ - listen [::]:{port} ssl http2; - server_name {app}.{domain}; - - access_log /var/log/nginx/{app}.access.log; - error_log /var/log/nginx/{app}.error.log; - - location / {{ - proxy_pass http://{ip}:8080; - }} -}} -''' - -NGINX_DEFAULT_TEMPLATE = '''server {{ - listen [::]:80 default_server ipv6only=off; - - location / {{ - return 301 https://$host:{port}$request_uri; - }} - location /.well-known/acme-challenge/ {{ - root /etc/acme.sh.d; - }} -}} - -server {{ - listen [::]:{port} ssl http2 default_server ipv6only=off; - root /srv/portal; - index index.html; - - location / {{ - try_files $uri $uri/ =404; - }} - location /apps.json {{ - alias /etc/spotter/apps.json; - }} -}} -''' - -ISSUE_TEMPLATE = ''' -\x1b[1;32m _____ _ _ __ ____ __ - / ____| | | | | \\\\ \\\\ / / \\\\/ | - | (___ _ __ ___ | |_| |_ ___ _ _\\\\ \\\\ / /| \\\\ / | - \\\\___ \\\\| '_ \\\\ / _ \\\\| __| __/ _ \\\\ '__\\\\ \\\\/ / | |\\\\/| | - ____) | |_) | (_) | |_| || __/ | \\\\ / | | | | - |_____/| .__/ \\\\___/ \\\\__|\\\\__\\\\___|_| \\\\/ |_| |_| - | | - |_|\x1b[0m - - - - - \x1b[1;33mUPOZORNĚNÍ:\x1b[0m Neoprávněný přístup k tomuto zařízení je zakázán. - Musíte mít výslovné oprávnění k přístupu nebo konfiguraci tohoto zařízení. - Neoprávněné pokusy a kroky k přístupu nebo používání tohoto systému mohou mít - za následek občanské nebo trestní sankce. - - - \x1b[1;33mCAUTION:\x1b[0m Unauthozired access to this device is prohibited. - You must have explicit, authorized permission to access or configure this - device. Unauthorized attempts and actions to access or use this system may - result in civil or criminal penalties. - - - - - Pro přístup k aplikacím otevřete URL \x1b[1mhttps://{host}/\x1b[0m ve Vašem - internetovém prohlížeči. - - - - - - -\x1b[0;30m -''' - -class SpotterManager: - def __init__(self): - self.conf = {} - with open(CONF_FILE, 'r') as f: - self.conf = json.load(f) - self.domain = self.conf["_"]["domain"] - self.port = self.conf["_"]["port"] - - def save_conf(self): - with open(CONF_FILE, 'w') as f: - json.dump(self.conf, f) - - def add_app(self, app, args): - self.add_app_to_conf(app, args) - if args.url: - self.update_app_conf(app) - - def add_app_to_conf(self, app, args): - self.conf[app] = {} - for key in ('url', 'login', 'password'): - value = getattr(args, key) - if value: - self.conf[app][key] = value - if args.property: - for key, value in args.property: - self.conf[app][key] = value - self.save_conf() - - def update_app_conf(self, app): - script_path = os.path.join('/srv', app, 'update-url.sh') - if os.path.exists(script_path) and os.access(script_path, os.X_OK): - host = '{}.{}'.format(app, self.domain) - subprocess.call([script_path, host, self.port]) - subprocess.call(['service', app, 'restart']) - - def update_proxy(self, app): - self.add_app_to_nginx(app) - subprocess.call(['service', 'nginx', 'reload']) - - def add_app_to_nginx(self, app): - ip = get_container_ip(app) - with open(os.path.join(NGINX_DIR, '{}.conf'.format(app)), 'w') as f: - f.write(NGINX_TEMPLATE.format(app=app, ip=ip, domain=self.domain, port=self.port)) - - def update_domain(self, domain, port): - self.domain = self.conf["_"]["domain"] = domain - self.port = self.conf["_"]["port"] = port - self.save_conf() - self.update_app_confs() - self.rebuild_nginx() - self.rebuild_issue() - subprocess.call(['service', 'nginx', 'restart']) - - def update_app_confs(self): - for app in self.conf.iteritems(): - if 'url' in app[1]: - self.update_app_conf(app[0]) - - def rebuild_nginx(self): - for f in os.listdir(NGINX_DIR): - os.unlink(os.path.join(NGINX_DIR, f)) - with open(os.path.join(NGINX_DIR, 'default.conf'), 'w') as f: - f.write(NGINX_DEFAULT_TEMPLATE.format(port=self.port)) - for app in self.conf.iteritems(): - if 'url' in app[1]: - self.add_app_to_nginx(app[0]) - - def rebuild_issue(self): - host = self.domain - if self.port != '443': - host = '{}:{}'.format(host, self.port) - with open(ISSUE_FILE, 'w') as f: - f.write(ISSUE_TEMPLATE.format(host=host)) - -def get_container_ip(app): - try: - return subprocess.check_output(['docker', 'inspect', '-f', '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}', app]).strip() - except: - return '127.0.0.1' - -if __name__ == '__main__': - parser = argparse.ArgumentParser(description='Spotter VM application manager') - subparsers = parser.add_subparsers() - - parser_add_app = subparsers.add_parser('add-app', help='Registers a new application') - parser_add_app.set_defaults(action='add-app') - parser_add_app.add_argument('app', help='Application name') - parser_add_app.add_argument('url', nargs='?', help='URL to the application. Use "{host}" as a host placeholder') - parser_add_app.add_argument('login', nargs='?', help='Administrative login') - parser_add_app.add_argument('password', nargs='?', help='Administrative password') - parser_add_app.add_argument('-p', '--property', nargs=2, action='append', help='Add arbitrary key-value to the application properties') - - parser_update_proxy = subparsers.add_parser('update-proxy', help='Updates nginx proxy target for an application container') - parser_update_proxy.set_defaults(action='update-proxy') - parser_update_proxy.add_argument('app', help='Application name') - - parser_update_domain = subparsers.add_parser('update-domain', help='Rebuilds domain structure of VM with new domain name and new HTTPS port') - parser_update_domain.set_defaults(action='update-domain') - parser_update_domain.add_argument('domain', help='Domain name') - parser_update_domain.add_argument('port', help='HTTPS port') - - args = parser.parse_args() - sm = SpotterManager() - if args.action == 'add-app': - sm.add_app(args.app, args) - elif args.action == 'update-proxy': - sm.update_proxy(args.app) - elif args.action == 'update-domain': - sm.update_domain(args.domain, args.port) diff --git a/basic/usr/local/bin/update-acme.sh b/basic/usr/local/bin/update-acme.sh deleted file mode 100755 index 3f22c71..0000000 --- a/basic/usr/local/bin/update-acme.sh +++ /dev/null @@ -1,6 +0,0 @@ -#!/bin/sh - -mkdir -p /etc/acme.sh.d -wget https://raw.githubusercontent.com/Neilpang/acme.sh/master/acme.sh -O /usr/local/bin/acme.sh -sed -i 's/\$HOME\/.\$PROJECT_NAME/\/etc\/acme.sh.d/' /usr/local/bin/acme.sh -chmod +x /usr/local/bin/acme.sh diff --git a/ccleanup.sh b/ccleanup.sh index 3874722..3184e6b 100755 --- a/ccleanup.sh +++ b/ccleanup.sh @@ -6,9 +6,12 @@ SOURCE_DIR=$(realpath $(dirname "${0}"))/ccleanup docker image ls | grep -q postfix || $(realpath $(dirname "${0}"))/postfix.sh docker image ls | grep -q postgres || $(realpath $(dirname "${0}"))/postgres.sh docker image ls | grep -q ruby || $(realpath $(dirname "${0}"))/ruby.sh +service postgres start # Build Docker container docker build -t ccleanup ${SOURCE_DIR} +cp ${SOURCE_DIR}/etc/init.d/ccleanup /etc/init.d/ccleanup +rc-update -u # Create database export CCLEANUP_PWD=$(head -c 18 /dev/urandom | base64) @@ -28,17 +31,10 @@ envsubst <${SOURCE_DIR}/srv/ccleanup/conf/database.yml >/srv/ccleanup/conf/datab cp ${SOURCE_DIR}/srv/ccleanup/conf/boot.rb /srv/ccleanup/conf/boot.rb cp ${SOURCE_DIR}/srv/ccleanup/conf/initializers/devise.rb /srv/ccleanup/conf/initializers/devise.rb cp ${SOURCE_DIR}/srv/ccleanup/conf/environments/production.rb /srv/ccleanup/conf/environments/production.rb +spotter-appmgr update-login ccleanup "${CCLEANUP_ADMIN_EMAIL}" "${CCLEANUP_ADMIN_PWD}" # Populate database envsubst <${SOURCE_DIR}/srv/ccleanup/db/seeds.rb >/tmp/seeds.rb docker run --rm -h ccleanup --link postgres -v /srv/ccleanup/conf:/srv/ccleanup/config ccleanup rake db:schema:load docker run --rm -h ccleanup --link postgres -v /srv/ccleanup/conf:/srv/ccleanup/config -v /tmp/seeds.rb:/srv/ccleanup/db/seeds.rb ccleanup rake db:seed rm /tmp/seeds.rb - -# Create CrisisCleanup service -cp ${SOURCE_DIR}/etc/init.d/ccleanup /etc/init.d/ccleanup -rc-update add ccleanup -service ccleanup start - -# Add application definition -spotter-appmgr add-app ccleanup "https://ccleanup.{host}/" "${CCLEANUP_ADMIN_EMAIL}" "${CCLEANUP_ADMIN_PWD}" diff --git a/ccleanup/etc/init.d/ccleanup b/ccleanup/etc/init.d/ccleanup index 19f733d..16ce925 100755 --- a/ccleanup/etc/init.d/ccleanup +++ b/ccleanup/etc/init.d/ccleanup @@ -3,8 +3,7 @@ description="Crisis Cleanup docker container" depend() { - need docker net postgres - use dns logger netmount postfix + need docker postfix postgres } start() { @@ -18,7 +17,11 @@ start() { } start_post() { - /usr/local/bin/spotter-appmgr update-proxy ccleanup + /usr/bin/spotter-appmgr register-proxy ccleanup +} + +stop_pre() { + /usr/bin/spotter-appmgr unregister-proxy ccleanup } stop() { diff --git a/ckan.sh b/ckan.sh index 3b74f05..2035846 100755 --- a/ckan.sh +++ b/ckan.sh @@ -8,9 +8,14 @@ docker image ls | grep -q postfix || $(realpath $(dirname "${0}"))/postfix.sh docker image ls | grep -q postgres || $(realpath $(dirname "${0}"))/postgres.sh docker image ls | grep -q redis || $(realpath $(dirname "${0}"))/redis.sh docker image ls | grep -q solr || $(realpath $(dirname "${0}"))/solr.sh +service postgres start +service redis start +service solr start # Build Docker container docker build -t ckan ${SOURCE_DIR} +cp ${SOURCE_DIR}/etc/init.d/ckan /etc/init.d/ckan +rc-update -u # Create database export CKAN_PWD=$(head -c 18 /dev/urandom | base64) @@ -51,14 +56,7 @@ export CKAN_ADMIN_PWD=$(head -c 12 /dev/urandom | base64) export CKAN_ADMIN_HASH=$(docker run --rm ckan python -c "from passlib.hash import pbkdf2_sha512;print pbkdf2_sha512.encrypt('${CKAN_ADMIN_PWD}')") export CKAN_ADMIN_EMAIL="admin@example.com" envsubst <${SOURCE_DIR}/adminpwd.sql | docker exec -i postgres psql ckan - -# Configure CKAN service -cp ${SOURCE_DIR}/etc/init.d/ckan /etc/init.d/ckan -rc-update add ckan -service ckan start +spotter-appmgr update-login ckan "${CKAN_ADMIN_USER}" "${CKAN_ADMIN_PWD}" # Install cron job cp ${SOURCE_DIR}/etc/periodic/hourly/ckan /etc/periodic/hourly/ckan - -# Add application definition -spotter-appmgr add-app ckan "https://ckan.{host}/" "${CKAN_ADMIN_USER}" "${CKAN_ADMIN_PWD}" diff --git a/ckan/etc/init.d/ckan b/ckan/etc/init.d/ckan index c1a88d6..b07e216 100755 --- a/ckan/etc/init.d/ckan +++ b/ckan/etc/init.d/ckan @@ -3,9 +3,7 @@ description="CKAN docker container" depend() { - need docker net postgres - use dns logger netmount postfix - after ckandp redis solr + need docker ckandp postfix postgres redis solr } start() { @@ -23,7 +21,11 @@ start() { } start_post() { - /usr/local/bin/spotter-appmgr update-proxy ckan + /usr/bin/spotter-appmgr register-proxy ckan +} + +stop_pre() { + /usr/bin/spotter-appmgr unregister-proxy ckan } stop() { diff --git a/ckan/srv/ckan/conf/ckan.ini b/ckan/srv/ckan/conf/ckan.ini index 39818c6..e5c67d9 100644 --- a/ckan/srv/ckan/conf/ckan.ini +++ b/ckan/srv/ckan/conf/ckan.ini @@ -56,7 +56,7 @@ ckan.datastore.default_fts_index_method = gist ## Site Settings -ckan.site_url = http://127.0.0.1 +ckan.site_url = https://ckan.spotter.vm #ckan.use_pylons_response_cleanup_middleware = true ## Authorization Settings diff --git a/ckandp.sh b/ckandp.sh index 5619449..c1b7dc5 100755 --- a/ckandp.sh +++ b/ckandp.sh @@ -4,14 +4,11 @@ SOURCE_DIR=$(realpath $(dirname "${0}"))/ckandp # Build Docker container docker build -t ckandp ${SOURCE_DIR} +cp ${SOURCE_DIR}/etc/init.d/ckandp /etc/init.d/ckandp +rc-update -u # Configure CKAN DataPusher mkdir -p /srv/ckandp/conf /srv/ckandp/data cp ${SOURCE_DIR}/srv/ckandp/conf/datapusher.wsgi /srv/ckandp/conf/datapusher.wsgi cp ${SOURCE_DIR}/srv/ckandp/conf/datapusher_settings.py /srv/ckandp/conf/datapusher_settings.py chown -R 8004:8004 /srv/ckandp/data - -# Configure CKAN DataPusher service -cp ${SOURCE_DIR}/etc/init.d/ckandp /etc/init.d/ckandp -rc-update add ckandp -service ckandp start diff --git a/ckandp/etc/init.d/ckandp b/ckandp/etc/init.d/ckandp index a41cfcc..080211c 100755 --- a/ckandp/etc/init.d/ckandp +++ b/ckandp/etc/init.d/ckandp @@ -3,8 +3,7 @@ description="CKAN DataPusher docker container" depend() { - need docker net - use dns logger netmount + need docker } start() { diff --git a/cts.sh b/cts.sh index ab714de..6e0fc67 100755 --- a/cts.sh +++ b/cts.sh @@ -4,9 +4,12 @@ SOURCE_DIR=$(realpath $(dirname "${0}"))/cts # Check prerequisites docker image ls | grep -q postgres || $(realpath $(dirname "${0}"))/postgres.sh +service postgres start # Build Docker container docker build -t cts ${SOURCE_DIR} +cp ${SOURCE_DIR}/etc/init.d/cts /etc/init.d/cts +rc-update -u # Create database export CTS_PWD=$(head -c 18 /dev/urandom | base64) @@ -35,11 +38,4 @@ export CTS_ADMIN_PWD=$(head -c 12 /dev/urandom | base64) export CTS_ADMIN_HASH=$(docker run --rm -h cts -v /srv/cts/conf:/srv/cts/cts/settings cts python -c "from django.contrib.auth.hashers import make_password; print make_password('${CTS_ADMIN_PWD}')") export CTS_ADMIN_SECRET=$(head -c 12 /dev/urandom | sha256sum | cut -c1-13) envsubst <${SOURCE_DIR}/adminpwd.sql | docker exec -i postgres psql cts - -# Create CTS service -cp ${SOURCE_DIR}/etc/init.d/cts /etc/init.d/cts -rc-update add cts -service cts start - -# Add application definition -spotter-appmgr add-app cts "https://cts.{host}/" "${CTS_ADMIN_EMAIL}" "${CTS_ADMIN_PWD}" +spotter-appmgr update-login cts "${CTS_ADMIN_EMAIL}" "${CTS_ADMIN_PWD}" diff --git a/cts/etc/init.d/cts b/cts/etc/init.d/cts index c87bb4d..028b1d8 100755 --- a/cts/etc/init.d/cts +++ b/cts/etc/init.d/cts @@ -3,8 +3,7 @@ description="CTS docker container" depend() { - need docker net postgres - use dns logger netmount + need docker postgres } start() { @@ -17,7 +16,11 @@ start() { } start_post() { - /usr/local/bin/spotter-appmgr update-proxy cts + /usr/bin/spotter-appmgr register-proxy cts +} + +stop_pre() { + /usr/bin/spotter-appmgr unregister-proxy cts } stop() { diff --git a/flsms.sh b/flsms.sh index 0f8828b..771608d 100755 --- a/flsms.sh +++ b/flsms.sh @@ -7,20 +7,15 @@ docker image ls | grep -q java || $(realpath $(dirname "${0}"))/java.sh # Build Docker container docker build -t flsms ${SOURCE_DIR} +cp ${SOURCE_DIR}/etc/init.d/flsms /etc/init.d/flsms +rc-update -u # Configure FrontlineSMS mkdir -p /srv/flsms/data -export FLSMS_ADMIN_USER=admin +export FLSMS_ADMIN_USER="admin" export FLSMS_ADMIN_PWD=$(head -c 12 /dev/urandom | base64) export FLSMS_ADMIN_USER_HASH=$(echo -n "${FLSMS_ADMIN_USER}" | base64) export FLSMS_ADMIN_PWD_HASH=$(echo -n "${FLSMS_ADMIN_PWD}" | base64) envsubst <${SOURCE_DIR}/srv/flsms/data/app-settings.properties >/srv/flsms/data/app-settings.properties chown -R 8018:8018 /srv/flsms/data - -# Create FrontlineSMS service -cp ${SOURCE_DIR}/etc/init.d/flsms /etc/init.d/flsms -rc-update add flsms -service flsms start - -# Add application definition -spotter-appmgr add-app flsms "https://flsms.{host}/" "${FLSMS_ADMIN_USER}" "${FLSMS_ADMIN_PWD}" +spotter-appmgr update-login flsms "${FLSMS_ADMIN_USER}" "${FLSMS_ADMIN_PWD}" diff --git a/flsms/etc/init.d/flsms b/flsms/etc/init.d/flsms index 78be8fb..93c2185 100755 --- a/flsms/etc/init.d/flsms +++ b/flsms/etc/init.d/flsms @@ -3,8 +3,7 @@ description="FrontlineSMS docker container" depend() { - need docker net - use dns logger netmount + need docker } start() { @@ -16,7 +15,11 @@ start() { } start_post() { - /usr/local/bin/spotter-appmgr update-proxy flsms + /usr/bin/spotter-appmgr register-proxy flsms +} + +stop_pre() { + /usr/bin/spotter-appmgr unregister-proxy flsms } stop() { diff --git a/gnuhealth.sh b/gnuhealth.sh index 1882938..8d448cb 100755 --- a/gnuhealth.sh +++ b/gnuhealth.sh @@ -5,9 +5,12 @@ SOURCE_DIR=$(realpath $(dirname "${0}"))/gnuhealth # Check prerequisites docker image ls | grep -q postfix || $(realpath $(dirname "${0}"))/postfix.sh docker image ls | grep -q postgres || $(realpath $(dirname "${0}"))/postgres.sh +service postgres start # Build Docker container docker build -t gnuhealth ${SOURCE_DIR} +cp ${SOURCE_DIR}/etc/init.d/gnuhealth /etc/init.d/gnuhealth +rc-update -u # Create databases export GNUHEALTH_PWD=$(head -c 18 /dev/urandom | base64 | tr -d '/+=') @@ -18,21 +21,14 @@ mkdir -p /srv/gnuhealth/conf/ envsubst <${SOURCE_DIR}/srv/gnuhealth/conf/trytond.conf >/srv/gnuhealth/conf/trytond.conf # Populate database +export GNUHEALTH_ADMIN_USER="admin" export GNUHEALTH_ADMIN_PWD=$(head -c 12 /dev/urandom | base64) echo ${GNUHEALTH_ADMIN_PWD} >/tmp/.adminpwd docker run --rm -h gnuhealth --link postgres -v /srv/gnuhealth/conf:/srv/gnuhealth/gnuhealth/tryton/server/config -v /tmp/.adminpwd:/tmp/.adminpwd -e TRYTONPASSFILE=/tmp/.adminpwd gnuhealth /srv/gnuhealth/gnuhealth/tryton/server/trytond-4.2.10/bin/trytond-admin -d gnuhealth --all -v rm -f /tmp/.adminpwd +spotter-appmgr update-login gnuhealth "${GNUHEALTH_ADMIN_USER}" "${GNUHEALTH_ADMIN_PWD}" # Populate demo database wget http://health.gnu.org/downloads/postgres_dumps/gnuhealth-32-demo.sql.gz -O /tmp/gnuhealth_demo.sql.gz zcat /tmp/gnuhealth_demo.sql.gz | docker exec -i -e PGPASSWORD=${GNUHEALTH_PWD} postgres psql gnuhealth_demo gnuhealth rm -f /tmp/gnuhealth_demo.sql.gz - -# Create GNU Health service -cp ${SOURCE_DIR}/etc/init.d/gnuhealth /etc/init.d/gnuhealth -rc-update add gnuhealth -service gnuhealth start - -# Add application definition -spotter-appmgr add-app gnuhealth "https://gnuhealth.{host}/index.html" admin "${GNUHEALTH_ADMIN_PWD}" -spotter-appmgr add-app gnuhealth-clients -p clienturl "gnuhealth.{host}" diff --git a/gnuhealth/etc/init.d/gnuhealth b/gnuhealth/etc/init.d/gnuhealth index 5c1f59c..bc1c9ee 100755 --- a/gnuhealth/etc/init.d/gnuhealth +++ b/gnuhealth/etc/init.d/gnuhealth @@ -3,8 +3,7 @@ description="GNU Health docker container" depend() { - need docker net postgres - use dns logger netmount postfix + need docker postgres } start() { @@ -18,7 +17,11 @@ start() { } start_post() { - /usr/local/bin/spotter-appmgr update-proxy gnuhealth + /usr/bin/spotter-appmgr register-proxy gnuhealth +} + +stop_pre() { + /usr/bin/spotter-appmgr unregister-proxy gnuhealth } stop() { diff --git a/kanboard.sh b/kanboard.sh index 18437fb..3530738 100755 --- a/kanboard.sh +++ b/kanboard.sh @@ -5,9 +5,12 @@ SOURCE_DIR=$(realpath $(dirname "${0}"))/kanboard # Check prerequisites docker image ls | grep -q postfix || $(realpath $(dirname "${0}"))/postfix.sh docker image ls | grep -q postgres || $(realpath $(dirname "${0}"))/postgres.sh +service postgres start # Build Docker container docker build -t kanboard ${SOURCE_DIR} +cp ${SOURCE_DIR}/etc/init.d/kanboard /etc/init.d/kanboard +rc-update -u # Populate database export KANBOARD_PWD=$(head -c 18 /dev/urandom | base64) @@ -22,15 +25,7 @@ export KANBOARD_ADMIN_USER=admin export KANBOARD_ADMIN_PWD=$(head -c 12 /dev/urandom | base64) export KANBOARD_ADMIN_HASH=$(docker run --rm kanboard php -r "echo password_hash('${KANBOARD_ADMIN_PWD}', PASSWORD_BCRYPT);") envsubst <${SOURCE_DIR}/adminpwd.sql | docker exec -i postgres psql kanboard - -# Create KanBoard service -cp ${SOURCE_DIR}/etc/init.d/kanboard /etc/init.d/kanboard -rc-update add kanboard -service kanboard start +spotter-appmgr update-login kanboard "${KANBOARD_ADMIN_USER}" "${KANBOARD_ADMIN_PWD}" # Install cron job cp ${SOURCE_DIR}/etc/periodic/daily/kanboard /etc/periodic/daily/kanboard - -# Add application definition -spotter-appmgr add-app kanboard "https://kanboard.{host}/" "${KANBOARD_ADMIN_USER}" "${KANBOARD_ADMIN_PWD}" -spotter-appmgr add-app kanboard-mobile -p clienturl "https://kanboard.{host}" diff --git a/kanboard/etc/init.d/kanboard b/kanboard/etc/init.d/kanboard index d959c4f..0d13268 100755 --- a/kanboard/etc/init.d/kanboard +++ b/kanboard/etc/init.d/kanboard @@ -3,8 +3,7 @@ description="KanBoard docker container" depend() { - need docker net postgres - use dns logger netmount postfix + need docker postfix postgres } start() { @@ -19,7 +18,11 @@ start() { } start_post() { - /usr/local/bin/spotter-appmgr update-proxy kanboard + /usr/bin/spotter-appmgr register-proxy kanboard +} + +stop_pre() { + /usr/bin/spotter-appmgr unregister-proxy kanboard } stop() { diff --git a/mariadb.sh b/mariadb.sh index 9e46bce..0f852a2 100755 --- a/mariadb.sh +++ b/mariadb.sh @@ -4,6 +4,8 @@ SOURCE_DIR=$(realpath $(dirname "${0}"))/mariadb # Build Docker container docker build -t mariadb ${SOURCE_DIR} +cp ${SOURCE_DIR}/etc/init.d/mariadb /etc/init.d/mariadb +rc-update -u # Create MariaDB instance mkdir -p /srv/mariadb/conf /srv/mariadb/data @@ -18,11 +20,6 @@ if [ ${DEBUG:-0} -eq 1 ]; then sed -i 's/#general_log/general_log/g' /srv/mariadb/conf/my.cnf fi -# Configure MariaDB service -cp ${SOURCE_DIR}/etc/init.d/mariadb /etc/init.d/mariadb -rc-update add mariadb -service mariadb start - # Configure MariaDB admin -docker exec -i mariadb sh -c 'until [ -x /run/mysqld/mysqld.sock ]; do usleep 100000; done' +service mariadb start cat ${SOURCE_DIR}/adminpwd.sql | docker exec -i mariadb mysql diff --git a/mariadb/etc/init.d/mariadb b/mariadb/etc/init.d/mariadb index d02bf09..f3d58d9 100755 --- a/mariadb/etc/init.d/mariadb +++ b/mariadb/etc/init.d/mariadb @@ -3,8 +3,7 @@ description="MariaDB docker container" depend() { - need docker net - use dns logger netmount + need docker } start() { @@ -16,6 +15,10 @@ start() { mariadb } +start_post() { + timeout -t 3 docker exec mariadb sh -c 'until [ -e /run/mysqld/mysqld.sock ]; do usleep 50000; done' +} + stop() { /usr/bin/docker stop mariadb } diff --git a/mifosx.sh b/mifosx.sh index ff4a33c..1e14810 100755 --- a/mifosx.sh +++ b/mifosx.sh @@ -6,9 +6,12 @@ SOURCE_DIR=$(realpath $(dirname "${0}"))/mifosx docker image ls | grep -q mariadb || $(realpath $(dirname "${0}"))/mariadb.sh docker image ls | grep -q postfix || $(realpath $(dirname "${0}"))/postfix.sh docker image ls | grep -q tomcat || $(realpath $(dirname "${0}"))/tomcat.sh +service mariadb start # Build Docker container docker build -t mifosx ${SOURCE_DIR} +cp ${SOURCE_DIR}/etc/init.d/mifosx /etc/init.d/mifosx +rc-update -u # Create databases export MIFOSX_PWD=$(head -c 18 /dev/urandom | base64) @@ -24,22 +27,17 @@ envsubst <${SOURCE_DIR}/srv/mifosx/conf/context.xml >/srv/mifosx/conf/context.xm cp ${SOURCE_DIR}/srv/mifosx/conf/server.xml /srv/mifosx/conf/server.xml cp ${SOURCE_DIR}/srv/mifosx/update-url.sh /srv/mifosx/update-url.sh -# Create Mifos X service -cp ${SOURCE_DIR}/etc/init.d/mifosx /etc/init.d/mifosx -rc-update add mifosx +# Populate database service mifosx start - -# Update admin account echo `date` '- Waiting for database to be populated. This should take about a minute.' until docker logs mifosx 2>&1 | grep -q 'Migrating schema `mifostenant-default` to version 5000'; do sleep 1 done + +# Update admin account export MIFOSX_ADMIN_USER=admin export MIFOSX_ADMIN_EMAIL=admin@example.com export MIFOSX_ADMIN_PWD=$(head -c 12 /dev/urandom | base64 | tr -d "+") export MIFOSX_ADMIN_HASH=$(echo -n "${MIFOSX_ADMIN_PWD}{1}" | sha256sum | awk '{print $1}') envsubst <${SOURCE_DIR}/adminpwd.sql | docker exec -i mariadb mysql mifostenant-default - -# Add application definition -spotter-appmgr add-app mifosx "https://mifosx.{host}/community-app/" "${MIFOSX_ADMIN_USER}" "${MIFOSX_ADMIN_PWD}" -spotter-appmgr add-app mifosx-mobile -p clienturl "mifosx.{host}" +spotter-appmgr update-login mifosx "${MIFOSX_ADMIN_USER}" "${MIFOSX_ADMIN_PWD}" diff --git a/mifosx/etc/init.d/mifosx b/mifosx/etc/init.d/mifosx index 58da091..1a7252b 100755 --- a/mifosx/etc/init.d/mifosx +++ b/mifosx/etc/init.d/mifosx @@ -3,8 +3,7 @@ description="Mifos X docker container" depend() { - need docker net mariadb - use dns logger netmount postfix + need docker mariadb postfix } start() { @@ -19,7 +18,11 @@ start() { } start_post() { - /usr/local/bin/spotter-appmgr update-proxy mifosx + /usr/bin/spotter-appmgr register-proxy mifosx +} + +stop_pre() { + /usr/bin/spotter-appmgr unregister-proxy mifosx } stop() { diff --git a/mifosx/srv/mifosx/conf/server.xml b/mifosx/srv/mifosx/conf/server.xml index 2d8e62a..33e851e 100644 --- a/mifosx/srv/mifosx/conf/server.xml +++ b/mifosx/srv/mifosx/conf/server.xml @@ -68,7 +68,7 @@ --> diff --git a/motech.sh b/motech.sh index 5b755e6..44076c2 100755 --- a/motech.sh +++ b/motech.sh @@ -7,9 +7,12 @@ docker image ls | grep -q activemq || $(realpath $(dirname "${0}"))/activemq.sh docker image ls | grep -q postfix || $(realpath $(dirname "${0}"))/postfix.sh docker image ls | grep -q postgres || $(realpath $(dirname "${0}"))/postgres.sh docker image ls | grep -q tomcat || $(realpath $(dirname "${0}"))/tomcat.sh +service postgres start # Build Docker container docker build -t motech ${SOURCE_DIR} +cp ${SOURCE_DIR}/etc/init.d/motech /etc/init.d/motech +rc-update -u # Create database export MOTECH_PWD=$(head -c 18 /dev/urandom | base64) @@ -24,12 +27,8 @@ cp ${SOURCE_DIR}/srv/motech/conf/config/org.motechproject.motech-platform-email/ chown -R 8013:8013 /srv/motech/conf cp ${SOURCE_DIR}/srv/motech/update-url.sh /srv/motech/update-url.sh -# Create Motech service -cp ${SOURCE_DIR}/etc/init.d/motech /etc/init.d/motech -rc-update add motech +# Populate database and create admin account service motech start - -# Configure Motech admin echo `date` '- Waiting for database to be populated. This should take about a minute.' MOTECH_IP=$(docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' motech) until curl -s "http://${MOTECH_IP}:8080/motech/module/server/startup/" | grep -q adminLogin; do @@ -39,6 +38,4 @@ export MOTECH_ADMIN_USER="admin" export MOTECH_ADMIN_EMAIL="admin@example.com" export MOTECH_ADMIN_PWD=$(head -c 12 /dev/urandom | base64) curl -H "Content-Type: application/json" -X POST -d "{\"adminLogin\":\"${MOTECH_ADMIN_USER}\",\"adminEmail\":\"${MOTECH_ADMIN_EMAIL}\",\"adminPassword\":\"${MOTECH_ADMIN_PWD}\",\"adminConfirmPassword\":\"${MOTECH_ADMIN_PWD}\",\"language\":\"cs\",\"providerName\":\"\",\"providerUrl\":\"\",\"schedulerUrl\":\"\"}" http://${MOTECH_IP}:8080/motech/module/server/startup/ - -# Add application definition -spotter-appmgr add-app motech "https://motech.{host}/motech/" "${MOTECH_ADMIN_USER}" "${MOTECH_ADMIN_PWD}" +spotter-appmgr update-login motech "${MOTECH_ADMIN_USER}" "${MOTECH_ADMIN_PWD}" diff --git a/motech/etc/init.d/motech b/motech/etc/init.d/motech index aa9621e..f75c102 100755 --- a/motech/etc/init.d/motech +++ b/motech/etc/init.d/motech @@ -3,8 +3,7 @@ description="Motech docker container" depend() { - need docker net postgres activemq - use dns logger netmount postfix + need docker activemq postfix postgres } start() { @@ -19,7 +18,11 @@ start() { } start_post() { - /usr/local/bin/spotter-appmgr update-proxy motech + /usr/bin/spotter-appmgr register-proxy motech +} + +stop_pre() { + /usr/bin/spotter-appmgr unregister-proxy motech } stop() { diff --git a/motech/srv/motech/conf/config/motech-settings.properties b/motech/srv/motech/conf/config/motech-settings.properties index 838d8dd..4ac52fc 100644 --- a/motech/srv/motech/conf/config/motech-settings.properties +++ b/motech/srv/motech/conf/config/motech-settings.properties @@ -1,3 +1,3 @@ system.language=en login.mode=repository -server.url=http://127.0.0.1 +server.url=https://motech.spotter.vm diff --git a/odk.sh b/odk.sh index daf1864..d6250bd 100755 --- a/odk.sh +++ b/odk.sh @@ -6,9 +6,12 @@ SOURCE_DIR=$(realpath $(dirname "${0}"))/odk docker image ls | grep -q postgres || $(realpath $(dirname "${0}"))/postgres.sh docker image ls | grep -q postfix || $(realpath $(dirname "${0}"))/postfix.sh docker image ls | grep -q tomcat || $(realpath $(dirname "${0}"))/tomcat.sh +service postgres start # Build Docker container docker build -t odk ${SOURCE_DIR} +cp ${SOURCE_DIR}/etc/init.d/odk /etc/init.d/odk +rc-update -u # Create databases export ODK_PWD=$(head -c 18 /dev/urandom | base64) @@ -24,21 +27,16 @@ cp ${SOURCE_DIR}/srv/odk/conf/server.xml /srv/odk/conf/server.xml cp ${SOURCE_DIR}/srv/odk/update-url.sh /srv/odk/update-url.sh chown -R 8015:8015 /srv/odk/conf -# Create OpenDataKit service -cp ${SOURCE_DIR}/etc/init.d/odk /etc/init.d/odk -rc-update add odk +# Populate database service odk start +until docker logs odk 2>&1 | grep -q 'org.apache.catalina.startup.Catalina.start'; do + sleep 1 +done # Update admin account export ODK_ADMIN_PWD=$(head -c 12 /dev/urandom | base64) export ODK_ADMIN_SALT=$(head -c 4 /dev/urandom | hexdump -e '"%x"') # Must be 8 characters export ODK_ADMIN_BASIC_HASH=$(echo -n "${ODK_ADMIN_PWD}{${ODK_ADMIN_SALT}}" | sha1sum | tr -d " -") export ODK_ADMIN_DIGEST_HASH=$(echo -n "${ODK_ADMIN_USER}:${ODK_ADMIN_REALM}:${ODK_ADMIN_PWD}" | md5sum | tr -d " -") -until docker logs odk 2>&1 | grep -q 'org.apache.catalina.startup.Catalina.start'; do - sleep 1 -done envsubst <${SOURCE_DIR}/adminpwd.sql | docker exec -i postgres psql odk - -# Add application definition -spotter-appmgr add-app odk "https://odk.{host}/aggregate/" "${ODK_ADMIN_USER}" "${ODK_ADMIN_PWD}" -spotter-appmgr add-app odk-clients -p clienturl "https://odk.{host}/aggregate" +spotter-appmgr update-login odk "${ODK_ADMIN_USER}" "${ODK_ADMIN_PWD}" diff --git a/odk/etc/init.d/odk b/odk/etc/init.d/odk index 91cdb3c..75fbbb0 100755 --- a/odk/etc/init.d/odk +++ b/odk/etc/init.d/odk @@ -3,8 +3,7 @@ description="OpenDataKit Aggregate docker container" depend() { - need docker net postgres - use dns logger netmount postfix + need docker postfix postgres } start() { @@ -20,7 +19,11 @@ start() { } start_post() { - /usr/local/bin/spotter-appmgr update-proxy odk + /usr/bin/spotter-appmgr register-proxy odk +} + +stop_pre() { + /usr/bin/spotter-appmgr unregister-proxy odk } stop() { diff --git a/odk/srv/odk/conf/server.xml b/odk/srv/odk/conf/server.xml index 2d8e62a..9c464d4 100644 --- a/odk/srv/odk/conf/server.xml +++ b/odk/srv/odk/conf/server.xml @@ -68,7 +68,7 @@ --> diff --git a/odkbuild.sh b/odkbuild.sh index 355a026..58f2b89 100755 --- a/odkbuild.sh +++ b/odkbuild.sh @@ -5,9 +5,12 @@ SOURCE_DIR=$(realpath $(dirname "${0}"))/odkbuild # Check prerequisites docker image ls | grep -q postgres || $(realpath $(dirname "${0}"))/postgres.sh docker image ls | grep -q ruby || $(realpath $(dirname "${0}"))/ruby.sh +service postgres start # Build Docker container docker build -t odkbuild ${SOURCE_DIR} +cp ${SOURCE_DIR}/etc/init.d/odkbuild /etc/init.d/odkbuild +rc-update -u # Create databases export ODKBUILD_PWD=$(head -c 18 /dev/urandom | base64) @@ -18,11 +21,3 @@ export ODKBUILD_COOKIE_SECRET=$(head -c 8 /dev/urandom | hexdump -e '"%x"') mkdir -p /srv/odkbuild/conf envsubst <${SOURCE_DIR}/srv/odkbuild/conf/config.yml >/srv/odkbuild/conf/config.yml docker run --rm -h odkbuild --link postgres -v /srv/odkbuild/conf/config.yml:/srv/odkbuild/config.yml -w /srv/odkbuild odkbuild rake db:migrate - -# Create OpenDataKit service -cp ${SOURCE_DIR}/etc/init.d/odkbuild /etc/init.d/odkbuild -rc-update add odkbuild -service odkbuild start - -# Add application definition -spotter-appmgr add-app odkbuild "https://odkbuild.{host}/" diff --git a/odkbuild/etc/init.d/odkbuild b/odkbuild/etc/init.d/odkbuild index cd62c5b..c42670b 100755 --- a/odkbuild/etc/init.d/odkbuild +++ b/odkbuild/etc/init.d/odkbuild @@ -3,8 +3,7 @@ description="OpenDataKit Build docker container" depend() { - need docker net postgres - use dns logger netmount + need docker postgres } start() { @@ -17,7 +16,11 @@ start() { } start_post() { - /usr/local/bin/spotter-appmgr update-proxy odkbuild + /usr/bin/spotter-appmgr register-proxy odkbuild +} + +stop_pre() { + /usr/bin/spotter-appmgr unregister-proxy odkbuild } stop() { diff --git a/omk.sh b/omk.sh index 3e68e71..e090563 100755 --- a/omk.sh +++ b/omk.sh @@ -7,6 +7,8 @@ docker image ls | grep -q java || $(realpath $(dirname "${0}"))/java.sh # Build Docker container docker build -t omk ${SOURCE_DIR} +cp ${SOURCE_DIR}/etc/init.d/omk /etc/init.d/omk +rc-update -u # Configure OpenMapKit export OMK_ADMIN_USER="admin" @@ -15,13 +17,4 @@ mkdir -p /srv/omk/conf /srv/omk/data chown -R 8007:8007 /srv/omk/data docker run --rm -v /srv/omk/data:/mnt/data omk cp -rp /srv/omk/data/. /mnt/data envsubst <${SOURCE_DIR}/srv/omk/conf/settings.js >/srv/omk/conf/settings.js - -# Configure OpenMapKit service -cp ${SOURCE_DIR}/etc/init.d/omk /etc/init.d/omk -rc-update add omk -service omk start - -# Add application definition -spotter-appmgr add-app omk "https://omk.{host}/" "${OMK_ADMIN_USER}" "${OMK_ADMIN_PWD}" -spotter-appmgr add-app omk-clients -p clienturl "https://omk.{host}" -spotter-appmgr add-app geoodk-clients -p clienturl "https://omk.{host}" +spotter-appmgr update-login omk "${OMK_ADMIN_USER}" "${OMK_ADMIN_PWD}" diff --git a/omk/etc/init.d/omk b/omk/etc/init.d/omk index b1e2b89..98c2a28 100755 --- a/omk/etc/init.d/omk +++ b/omk/etc/init.d/omk @@ -3,8 +3,7 @@ description="OpenMapKit docker container" depend() { - need docker net - use dns logger netmount + need docker } start() { @@ -17,7 +16,11 @@ start() { } start_post() { - /usr/local/bin/spotter-appmgr update-proxy omk + /usr/bin/spotter-appmgr register-proxy omk +} + +stop_pre() { + /usr/bin/spotter-appmgr unregister-proxy omk } stop() { diff --git a/pandora.sh b/pandora.sh index 6c22fc2..158c589 100755 --- a/pandora.sh +++ b/pandora.sh @@ -6,9 +6,13 @@ SOURCE_DIR=$(realpath $(dirname "${0}"))/pandora docker image ls | grep -q postfix || $(realpath $(dirname "${0}"))/postfix.sh docker image ls | grep -q postgres || $(realpath $(dirname "${0}"))/postgres.sh docker image ls | grep -q rabbitmq || $(realpath $(dirname "${0}"))/rabbitmq.sh +service postgres start +service rabbitmq start # Build Docker container docker build -t pandora ${SOURCE_DIR} +cp ${SOURCE_DIR}/etc/init.d/pandora /etc/init.d/pandora +rc-update -u # Create PostgreSQL user and database export PANDORA_PWD=$(head -c 18 /dev/urandom | base64) @@ -50,11 +54,4 @@ export PANDORA_ADMIN_EMAIL=admin@example.com export PANDORA_ADMIN_PWD=$(head -c 12 /dev/urandom | base64) export PANDORA_ADMIN_HASH=$(docker run --rm -h pandora -e DJANGO_SETTINGS_MODULE=pandora.settings -v /srv/pandora/conf:/srv/pandora/conf pandora python3 -c "from django.contrib.auth.hashers import make_password; print(make_password('${PANDORA_ADMIN_PWD}'))") envsubst <${SOURCE_DIR}/adminpwd.sql | docker exec -i postgres psql pandora - -# Configure Pandora service -cp ${SOURCE_DIR}/etc/init.d/pandora /etc/init.d/pandora -rc-update add pandora -service pandora start - -# Add application definition -spotter-appmgr add-app pandora "https://pandora.{host}/" "${PANDORA_ADMIN_USER}" "${PANDORA_ADMIN_PWD}" +spotter-appmgr update-login pandora "${PANDORA_ADMIN_USER}" "${PANDORA_ADMIN_PWD}" diff --git a/pandora/etc/init.d/pandora b/pandora/etc/init.d/pandora index 63b5e40..51b7f8a 100755 --- a/pandora/etc/init.d/pandora +++ b/pandora/etc/init.d/pandora @@ -3,8 +3,7 @@ description="Pan.do/ra docker container" depend() { - need docker net postgres rabbitmq - use dns logger netmount postfix + need docker postfix postgres rabbitmq } start() { @@ -20,7 +19,11 @@ start() { } start_post() { - /usr/local/bin/spotter-appmgr update-proxy pandora + /usr/bin/spotter-appmgr register-proxy pandora +} + +stop_pre() { + /usr/bin/spotter-appmgr unregister-proxy pandora } stop() { diff --git a/postfix.sh b/postfix.sh index 5e8d432..7e8ff88 100755 --- a/postfix.sh +++ b/postfix.sh @@ -4,6 +4,8 @@ SOURCE_DIR=$(realpath $(dirname "${0}"))/postfix # Build Docker container docker build -t postfix ${SOURCE_DIR} +cp ${SOURCE_DIR}/etc/init.d/postfix /etc/init.d/postfix +rc-update -u # Copy existing config files into persistent storage mkdir -p /srv/postfix/conf /srv/postfix/data @@ -11,8 +13,3 @@ docker run --rm -v /srv/postfix/conf:/mnt/conf postfix cp -rp /etc/postfix/. /mn # Configure postfix cp ${SOURCE_DIR}/srv/postfix/conf/main.cf /srv/postfix/conf/main.cf - -# Configure postfix service -cp ${SOURCE_DIR}/etc/init.d/postfix /etc/init.d/postfix -rc-update add postfix -service postfix start diff --git a/postfix/etc/init.d/postfix b/postfix/etc/init.d/postfix index b5fa26b..529733b 100755 --- a/postfix/etc/init.d/postfix +++ b/postfix/etc/init.d/postfix @@ -3,8 +3,7 @@ description="Postfix docker container" depend() { - need docker net - use dns logger netmount + need docker } start() { diff --git a/postgres.sh b/postgres.sh index 542352a..1141014 100755 --- a/postgres.sh +++ b/postgres.sh @@ -4,6 +4,8 @@ SOURCE_DIR=$(realpath $(dirname "${0}"))/postgres # Build Docker container docker build -t postgres ${SOURCE_DIR} +cp ${SOURCE_DIR}/etc/init.d/postgres /etc/init.d/postgres +rc-update -u # Create Postgres instance mkdir -p /srv/postgres/data @@ -14,14 +16,8 @@ docker run --rm --name postgres -h postgres -v /srv/postgres/data:/var/lib/postg # Configure Postgres cp ${SOURCE_DIR}/srv/postgres/data/postgresql.conf /srv/postgres/data/postgresql.conf cp ${SOURCE_DIR}/srv/postgres/data/pg_hba.conf /srv/postgres/data/pg_hba.conf - # Enable query logging. Only if the DEBUG environment variable is set if [ ${DEBUG:-0} -eq 1 ]; then sed -i 's/^#log_destination/log_destination/' /srv/postgres/data/postgresql.conf sed -i 's/^#log_statement/log_statement/' /srv/postgres/data/postgresql.conf fi - -# Configure Postgres service -cp ${SOURCE_DIR}/etc/init.d/postgres /etc/init.d/postgres -rc-update add postgres -service postgres start diff --git a/postgres/etc/init.d/postgres b/postgres/etc/init.d/postgres index e739508..2d8dcc3 100755 --- a/postgres/etc/init.d/postgres +++ b/postgres/etc/init.d/postgres @@ -3,8 +3,7 @@ description="Postgres docker container" depend() { - need docker net - use dns logger netmount + need docker } start() { @@ -15,6 +14,10 @@ start() { postgres } +start_post() { + timeout -t 3 docker exec postgres sh -c 'until [ -e /var/run/postgresql/.s.PGSQL.5432 ]; do usleep 50000; done' +} + stop() { /usr/bin/docker stop postgres } diff --git a/rabbitmq.sh b/rabbitmq.sh index ca4e37f..719f472 100755 --- a/rabbitmq.sh +++ b/rabbitmq.sh @@ -4,12 +4,9 @@ SOURCE_DIR=$(realpath $(dirname "${0}"))/rabbitmq # Build Docker container docker build -t rabbitmq ${SOURCE_DIR} +cp ${SOURCE_DIR}/etc/init.d/rabbitmq /etc/init.d/rabbitmq +rc-update -u # Create RabbitMQ directory structure mkdir -p /srv/rabbitmq/data chown 5672:5672 /srv/rabbitmq/data - -# Configure RabbitMQ service -cp ${SOURCE_DIR}/etc/init.d/rabbitmq /etc/init.d/rabbitmq -rc-update add rabbitmq -service rabbitmq start diff --git a/rabbitmq/etc/init.d/rabbitmq b/rabbitmq/etc/init.d/rabbitmq index 63f20fe..b58a73f 100755 --- a/rabbitmq/etc/init.d/rabbitmq +++ b/rabbitmq/etc/init.d/rabbitmq @@ -3,8 +3,7 @@ description="RabbitMQ docker container" depend() { - need docker net - use dns logger netmount + need docker } start() { diff --git a/redis.sh b/redis.sh index 7d96ac5..337ee4f 100755 --- a/redis.sh +++ b/redis.sh @@ -4,13 +4,10 @@ SOURCE_DIR=$(realpath $(dirname "${0}"))/redis # Build Docker container docker build -t redis ${SOURCE_DIR} +cp ${SOURCE_DIR}/etc/init.d/redis /etc/init.d/redis +rc-update -u # Configure Redis mkdir -p /srv/redis/conf /srv/redis/data cp ${SOURCE_DIR}/srv/redis/conf/redis.conf /srv/redis/conf/redis.conf chown -R 6379:6379 /srv/redis/data - -# Configure Redis service -cp ${SOURCE_DIR}/etc/init.d/redis /etc/init.d/redis -rc-update add redis -service redis start diff --git a/redis/etc/init.d/redis b/redis/etc/init.d/redis index 7c1ca55..92d57f6 100755 --- a/redis/etc/init.d/redis +++ b/redis/etc/init.d/redis @@ -3,8 +3,7 @@ description="Redis docker container" depend() { - need docker net - use dns logger netmount + need docker } start() { diff --git a/sahana-demo.sh b/sahana-demo.sh index 6ca6482..c9c208c 100755 --- a/sahana-demo.sh +++ b/sahana-demo.sh @@ -6,7 +6,12 @@ export TEMPLATE=${TEMPLATE:-"default"} # Check prerequisites docker image ls | grep -q postfix || $(realpath $(dirname "${0}"))/postfix.sh docker image ls | grep -q postgres || $(realpath $(dirname "${0}"))/postgres.sh -docker image ls | grep -q sahana || docker build -t sahana $(realpath $(dirname "${0}"))/sahana +service postgres start + +# Build Docker container +docker build -t sahana ${SOURCE_DIR} +envsubst <${SOURCE_DIR}/etc/init.d/sahana-demo >/etc/init.d/sahana-demo +chmod +x /etc/init.d/sahana-demo # Create PostgreSQL user and database export SAHANADEMO_PWD=$(head -c 18 /dev/urandom | base64) @@ -25,16 +30,8 @@ export SAHANADEMO_ADMIN_PWD=$(head -c 12 /dev/urandom | base64) envsubst <${SOURCE_DIR}/srv/sahana-demo/conf/000_config.py >/srv/sahana-demo/conf/000_config.py envsubst <${SOURCE_DIR}/masterUsers.csv >/tmp/masterUsers.csv cp ${SOURCE_DIR}/srv/sahana-demo/update-url.sh /srv/sahana-demo/update-url.sh +spotter-appmgr update-login sahana-demo "${SAHANADEMO_ADMIN_USER}" "${SAHANADEMO_ADMIN_PWD}" # Populate database docker run --rm -h sahana-demo --link postgres -v /srv/sahana-demo/conf:/srv/web2py/applications/eden/models -v /srv/sahana-demo/data/databases:/srv/web2py/applications/eden/databases -v /tmp/masterUsers.csv:/srv/web2py/applications/eden/modules/templates/default/users/masterUsers.csv sahana su - sahana -c "./web2py.py -S eden -M -R applications/eden/static/scripts/tools/noop.py" rm /tmp/masterUsers.csv - -# Create Sahana service -envsubst <${SOURCE_DIR}/etc/init.d/sahana-demo >/etc/init.d/sahana-demo -chmod +x /etc/init.d/sahana-demo -rc-update add sahana-demo -service sahana-demo start - -# Add application definition -spotter-appmgr add-app sahana-demo "https://sahana-demo.{host}/eden/" "${SAHANADEMO_ADMIN_USER}" "${SAHANADEMO_ADMIN_PWD}" diff --git a/sahana-demo/etc/init.d/sahana-demo b/sahana-demo/etc/init.d/sahana-demo index db3ed0e..e2a658d 100755 --- a/sahana-demo/etc/init.d/sahana-demo +++ b/sahana-demo/etc/init.d/sahana-demo @@ -3,8 +3,7 @@ description="Sahana Eden Demo docker container" depend() { - need docker net postgres - use dns logger netmount postfix + need docker postfix postgres } start() { @@ -21,7 +20,11 @@ start() { } start_post() { - /usr/local/bin/spotter-appmgr update-proxy sahana-demo + /usr/bin/spotter-appmgr register-proxy sahana-demo +} + +stop_pre() { + /usr/bin/spotter-appmgr unregister-proxy sahana-demo } stop() { diff --git a/sahana-demo/srv/sahana-demo/conf/000_config.py b/sahana-demo/srv/sahana-demo/conf/000_config.py index 36e1298..86c95b6 100644 --- a/sahana-demo/srv/sahana-demo/conf/000_config.py +++ b/sahana-demo/srv/sahana-demo/conf/000_config.py @@ -50,7 +50,7 @@ settings.gis.spatialdb = True #settings.base.system_name = T("Sahana Eden Humanitarian Management Platform") #settings.base.system_name_short = T("Sahana Eden") # Set this to the Public URL of the instance -settings.base.public_url = "http://127.0.0.1" +settings.base.public_url = "https://sahana-demo.spotter.vm" # Switch to "False" in Production for a Performance gain # (need to set to "True" again when Table definitions are changed) diff --git a/sahana.sh b/sahana.sh index 3c19e9a..46a9f06 100755 --- a/sahana.sh +++ b/sahana.sh @@ -5,9 +5,12 @@ SOURCE_DIR=$(realpath $(dirname "${0}"))/sahana # Check prerequisites docker image ls | grep -q postfix || $(realpath $(dirname "${0}"))/postfix.sh docker image ls | grep -q postgres || $(realpath $(dirname "${0}"))/postgres.sh +service postgres start # Build Docker container docker build -t sahana ${SOURCE_DIR} +cp ${SOURCE_DIR}/etc/init.d/sahana /etc/init.d/sahana +rc-update -u # Create PostgreSQL user and database export SAHANA_PWD=$(head -c 18 /dev/urandom | base64) @@ -30,6 +33,7 @@ envsubst <${SOURCE_DIR}/srv/sahana/conf/000_config.py >/srv/sahana/conf/000_conf envsubst <${SOURCE_DIR}/srv/sahana/data/Spotter/masterUsers.csv >/srv/sahana/data/Spotter/masterUsers.csv cp ${SOURCE_DIR}/srv/sahana/conf/00_settings.py /srv/sahana/conf/00_settings.py cp ${SOURCE_DIR}/srv/sahana/update-url.sh /srv/sahana/update-url.sh +spotter-appmgr update-login sahana "${SAHANA_ADMIN_USER}" "${SAHANA_ADMIN_PWD}" # Populate database docker run --rm -h sahana --link postgres -v /srv/sahana/conf:/srv/web2py/applications/eden/models -v /srv/sahana/data/Spotter:/srv/web2py/applications/eden/modules/templates/Spotter -v /srv/sahana/data/databases:/srv/web2py/applications/eden/databases sahana su - sahana -c "./web2py.py -S eden -M -R applications/eden/static/scripts/tools/noop.py" @@ -40,11 +44,3 @@ if [ ${DEBUG:-0} -eq 0 ]; then sed -i 's/settings.base.debug = True/settings.base.debug = False/' /srv/sahana/conf/000_config.py sed -i 's/#settings.base.prepopulate = 0/settings.base.prepopulate = 0/' /srv/sahana/conf/000_config.py fi - -# Create Sahana service -cp ${SOURCE_DIR}/etc/init.d/sahana /etc/init.d/sahana -rc-update add sahana -service sahana start - -# Add application definition -spotter-appmgr add-app sahana "https://sahana.{host}/eden/" "${SAHANA_ADMIN_USER}" "${SAHANA_ADMIN_PWD}" diff --git a/sahana/etc/init.d/sahana b/sahana/etc/init.d/sahana index 91084d7..e1a082a 100755 --- a/sahana/etc/init.d/sahana +++ b/sahana/etc/init.d/sahana @@ -3,8 +3,7 @@ description="Sahana Eden docker container" depend() { - need docker net postgres - use dns logger netmount postfix + need docker postfix postgres } start() { @@ -21,7 +20,11 @@ start() { } start_post() { - /usr/local/bin/spotter-appmgr update-proxy sahana + /usr/bin/spotter-appmgr register-proxy sahana +} + +stop_pre() { + /usr/bin/spotter-appmgr unregister-proxy sahana } stop() { diff --git a/sahana/srv/sahana/conf/000_config.py b/sahana/srv/sahana/conf/000_config.py index 5c550ef..efc4374 100644 --- a/sahana/srv/sahana/conf/000_config.py +++ b/sahana/srv/sahana/conf/000_config.py @@ -50,7 +50,7 @@ settings.gis.spatialdb = True #settings.base.system_name = T("Sahana Eden Humanitarian Management Platform") #settings.base.system_name_short = T("Sahana Eden") # Set this to the Public URL of the instance -settings.base.public_url = "http://127.0.0.1" +settings.base.public_url = "https://sahana.spotter.vm" # Switch to "False" in Production for a Performance gain # (need to set to "True" again when Table definitions are changed) diff --git a/sambro.sh b/sambro.sh index 640956f..2e56780 100755 --- a/sambro.sh +++ b/sambro.sh @@ -5,7 +5,12 @@ SOURCE_DIR=$(realpath $(dirname "${0}"))/sambro # Check prerequisites docker image ls | grep -q postfix || $(realpath $(dirname "${0}"))/postfix.sh docker image ls | grep -q postgres || $(realpath $(dirname "${0}"))/postgres.sh -docker image ls | grep -q sahana || docker build -t sahana $(realpath $(dirname "${0}"))/sahana +service postgres start + +# Build Docker container +docker build -t sahana ${SOURCE_DIR} +cp ${SOURCE_DIR}/etc/init.d/sambro /etc/init.d/sambro +rc-update -u # Create PostgreSQL user and database export SAMBRO_PWD=$(head -c 18 /dev/urandom | base64) @@ -26,6 +31,7 @@ envsubst <${SOURCE_DIR}/masterUsers.csv >/tmp/masterUsers.csv cp ${SOURCE_DIR}/srv/sambro/conf/00_settings.py /srv/sambro/conf/00_settings.py cp ${SOURCE_DIR}/srv/sambro/data/SAMBRO/config.py /srv/sambro/data/SAMBRO/config.py cp ${SOURCE_DIR}/srv/sambro/update-url.sh /srv/sambro/update-url.sh +spotter-appmgr update-login sambro "${SAMBRO_ADMIN_USER}" "${SAMBRO_ADMIN_PWD}" # Populate database docker run --rm -h sambro --link postgres -v /srv/sambro/conf:/srv/web2py/applications/eden/models -v /srv/sambro/data/SAMBRO:/srv/web2py/applications/eden/modules/templates/SAMBRO -v /tmp/masterUsers.csv:/srv/web2py/applications/eden/modules/templates/default/users/masterUsers.csv -v /srv/sambro/data/databases:/srv/web2py/applications/eden/databases sahana su - sahana -c "./web2py.py -S eden -M -R applications/eden/static/scripts/tools/noop.py" @@ -37,12 +43,3 @@ if [ ${DEBUG:-0} -eq 0 ]; then sed -i 's/settings.base.debug = True/settings.base.debug = False/' /srv/sambro/conf/000_config.py sed -i 's/#settings.base.prepopulate = 0/settings.base.prepopulate = 0/' /srv/sambro/conf/000_config.py fi - -# Create SAMBRO service -cp ${SOURCE_DIR}/etc/init.d/sambro /etc/init.d/sambro -rc-update add sambro -service sambro start - -# Add application definition -spotter-appmgr add-app sambro "https://sambro.{host}/eden/" "${SAMBRO_ADMIN_USER}" "${SAMBRO_ADMIN_PWD}" -spotter-appmgr add-app sambro-mobile -p clienturl "https://sambro.{host}/eden/" diff --git a/sambro/etc/init.d/sambro b/sambro/etc/init.d/sambro index a69b895..8dde8f3 100755 --- a/sambro/etc/init.d/sambro +++ b/sambro/etc/init.d/sambro @@ -3,8 +3,7 @@ description="SAMBRO docker container" depend() { - need docker net postgres - use dns logger netmount postfix + need docker postfix postgres } start() { @@ -21,7 +20,11 @@ start() { } start_post() { - /usr/local/bin/spotter-appmgr update-proxy sambro + /usr/bin/spotter-appmgr register-proxy sambro +} + +stop_pre() { + /usr/bin/spotter-appmgr unregister-proxy sambro } stop() { diff --git a/sambro/srv/sambro/conf/000_config.py b/sambro/srv/sambro/conf/000_config.py index e2f113c..1f2b1ca 100644 --- a/sambro/srv/sambro/conf/000_config.py +++ b/sambro/srv/sambro/conf/000_config.py @@ -50,7 +50,7 @@ settings.gis.spatialdb = True #settings.base.system_name = T("Sahana Eden Humanitarian Management Platform") #settings.base.system_name_short = T("Sahana Eden") # Set this to the Public URL of the instance -settings.base.public_url = "http://127.0.0.1" +settings.base.public_url = "https://sambro.spotter.vm" # Switch to "False" in Production for a Performance gain # (need to set to "True" again when Table definitions are changed) diff --git a/seeddms.sh b/seeddms.sh index 3184a57..502349f 100755 --- a/seeddms.sh +++ b/seeddms.sh @@ -5,9 +5,12 @@ SOURCE_DIR=$(realpath $(dirname "${0}"))/seeddms # Check prerequisites docker image ls | grep -q postfix || $(realpath $(dirname "${0}"))/postfix.sh docker image ls | grep -q postgres || $(realpath $(dirname "${0}"))/postgres.sh +service postgres start # Build Docker container docker build -t seeddms ${SOURCE_DIR} +cp ${SOURCE_DIR}/etc/init.d/seeddms /etc/init.d/seeddms +rc-update -u # Populate database export SEEDDMS_PWD=$(head -c 18 /dev/urandom | base64) @@ -27,14 +30,7 @@ export SEEDDMS_ADMIN_PWD=$(head -c 12 /dev/urandom | base64) export SEEDDMS_ADMIN_EMAIL=admin@example.com envsubst <${SOURCE_DIR}/adminpwd.sql | docker exec -i postgres psql seeddms chown -R 8010:8010 /srv/seeddms/conf - -# Create SeedDMS service -cp ${SOURCE_DIR}/etc/init.d/seeddms /etc/init.d/seeddms -rc-update add seeddms -service seeddms start +spotter-appmgr update-login seeddms "${SEEDDMS_ADMIN_USER}" "${SEEDDMS_ADMIN_PWD}" # Install cron job cp ${SOURCE_DIR}/etc/periodic/hourly/seeddms /etc/periodic/hourly/seeddms - -# Add application definition -spotter-appmgr add-app seeddms "https://seeddms.{host}/" "${SEEDDMS_ADMIN_USER}" "${SEEDDMS_ADMIN_PWD}" diff --git a/seeddms/etc/init.d/seeddms b/seeddms/etc/init.d/seeddms index b4aca02..5cb2fc5 100755 --- a/seeddms/etc/init.d/seeddms +++ b/seeddms/etc/init.d/seeddms @@ -3,8 +3,7 @@ description="SeedDMS docker container" depend() { - need docker net postgres - use dns logger netmount postfix + need docker postfix postgres } start() { @@ -19,7 +18,11 @@ start() { } start_post() { - /usr/local/bin/spotter-appmgr update-proxy seeddms + /usr/bin/spotter-appmgr register-proxy seeddms +} + +stop_pre() { + /usr/bin/spotter-appmgr unregister-proxy seeddms } stop() { diff --git a/sigmah.sh b/sigmah.sh index e3fc4e0..3670b56 100755 --- a/sigmah.sh +++ b/sigmah.sh @@ -6,9 +6,12 @@ SOURCE_DIR=$(realpath $(dirname "${0}"))/sigmah docker image ls | grep -q postgres || $(realpath $(dirname "${0}"))/postgres.sh docker image ls | grep -q postfix || $(realpath $(dirname "${0}"))/postfix.sh docker image ls | grep -q tomcat || $(realpath $(dirname "${0}"))/tomcat.sh +service postgres start # Build Docker container docker build -t sigmah ${SOURCE_DIR} +cp ${SOURCE_DIR}/etc/init.d/sigmah /etc/init.d/sigmah +rc-update -u # Create database export SIGMAH_PWD=$(head -c 18 /dev/urandom | base64) @@ -41,11 +44,4 @@ sed -i "s|\$2a\$10\$pMcTA1p9fefR8U9NoOPei.H0eq/TbbdSF27M0tn9iDWBrA4JHeCDC|${SIGM cat /tmp/sigmah-MinimumDataKit.sql | docker exec -i -e PGPASSWORD=${SIGMAH_PWD} postgres psql -U sigmah sigmah cat /tmp/sigmah-newOrganizationLaunchScript.sql | docker exec -i -e PGPASSWORD=${SIGMAH_PWD} postgres psql -U sigmah sigmah rm -f /tmp/sigmah-MinimumDataKit.sql /tmp/sigmah-newOrganizationLaunchScript.sql - -# Create Sigmah service -cp ${SOURCE_DIR}/etc/init.d/sigmah /etc/init.d/sigmah -rc-update add sigmah -service sigmah start - -# Add application definition -spotter-appmgr add-app sigmah "https://sigmah.{host}/sigmah/" "${SIGMAH_ADMIN_EMAIL}" "${SIGMAH_ADMIN_PWD}" +spotter-appmgr update-login sigmah "${SIGMAH_ADMIN_EMAIL}" "${SIGMAH_ADMIN_PWD}" diff --git a/sigmah/etc/init.d/sigmah b/sigmah/etc/init.d/sigmah index ec35d22..d87d9de 100755 --- a/sigmah/etc/init.d/sigmah +++ b/sigmah/etc/init.d/sigmah @@ -3,8 +3,7 @@ description="Sigmah docker container" depend() { - need docker net postgres - use dns logger netmount postfix + need docker postfix postgres } start() { @@ -20,7 +19,11 @@ start() { } start_post() { - /usr/local/bin/spotter-appmgr update-proxy sigmah + /usr/bin/spotter-appmgr register-proxy sigmah +} + +stop_pre() { + /usr/bin/spotter-appmgr unregister-proxy sigmah } stop() { diff --git a/solr.sh b/solr.sh index 52b62e3..4155e6f 100755 --- a/solr.sh +++ b/solr.sh @@ -7,14 +7,11 @@ docker image ls | grep -q java || $(realpath $(dirname "${0}"))/java.sh # Build Docker container docker build -t solr ${SOURCE_DIR} +cp ${SOURCE_DIR}/etc/init.d/solr /etc/init.d/solr +rc-update -u # Configure Solr mkdir -p /srv/solr/data cp ${SOURCE_DIR}/srv/solr/data/solr.xml /srv/solr/data/solr.xml cp ${SOURCE_DIR}/srv/solr/data/.solr.in.sh /srv/solr/data/.solr.in.sh chown -R 8983:8983 /srv/solr/data - -# Configure Solr service -cp ${SOURCE_DIR}/etc/init.d/solr /etc/init.d/solr -rc-update add solr -service solr start diff --git a/solr/etc/init.d/solr b/solr/etc/init.d/solr index 4d5cfb8..6e89789 100755 --- a/solr/etc/init.d/solr +++ b/solr/etc/init.d/solr @@ -3,8 +3,7 @@ description="Solr docker container" depend() { - need docker net - use dns logger netmount + need docker } start() { diff --git a/ushahidi.sh b/ushahidi.sh index 0af79c9..4e94fb8 100755 --- a/ushahidi.sh +++ b/ushahidi.sh @@ -5,9 +5,12 @@ SOURCE_DIR=$(realpath $(dirname "${0}"))/ushahidi # Check prerequisites docker image ls | grep -q mariadb || $(realpath $(dirname "${0}"))/mariadb.sh docker image ls | grep -q postfix || $(realpath $(dirname "${0}"))/postfix.sh +service mariadb start # Build Docker container docker build -t ushahidi ${SOURCE_DIR} +cp ${SOURCE_DIR}/etc/init.d/ushahidi /etc/init.d/ushahidi +rc-update -u # Create database export USHAHIDI_PWD=$(head -c 18 /dev/urandom | base64) @@ -28,15 +31,7 @@ export USHAHIDI_ADMIN_USER=admin@example.com export USHAHIDI_ADMIN_PWD=$(head -c 12 /dev/urandom | base64) export USHAHIDI_ADMIN_HASH=$(docker run --rm ushahidi php -r "echo password_hash('${USHAHIDI_ADMIN_PWD}', PASSWORD_BCRYPT);") envsubst <${SOURCE_DIR}/adminpwd.sql | docker exec -i mariadb mysql ushahidi - -# Create Ushahidi service -cp ${SOURCE_DIR}/etc/init.d/ushahidi /etc/init.d/ushahidi -rc-update add ushahidi -service ushahidi start +spotter-appmgr update-login ushahidi "${USHAHIDI_ADMIN_USER}" "${USHAHIDI_ADMIN_PWD}" # Install cron job cp ${SOURCE_DIR}/etc/periodic/15min/ushahidi /etc/periodic/15min/ushahidi - -# Add application definition -spotter-appmgr add-app ushahidi "https://ushahidi.{host}/" "${USHAHIDI_ADMIN_USER}" "${USHAHIDI_ADMIN_PWD}" -spotter-appmgr add-app ushahidi-mobile -p clienturl "ushahidi.{host}" diff --git a/ushahidi/adminpwd.sql b/ushahidi/adminpwd.sql index ed00a26..61fa9fe 100644 --- a/ushahidi/adminpwd.sql +++ b/ushahidi/adminpwd.sql @@ -2,4 +2,4 @@ UPDATE users SET email = '${USHAHIDI_ADMIN_USER}', password = '${USHAHIDI_ADMIN_ INSERT INTO `config` (`group_name`, `config_key`, `config_value`) VALUES ('data-provider','email','{\"incoming_type\":\"IMAP\",\"incoming_server\":\"localhost\",\"incoming_port\":143,\"incoming_security\":\"None\",\"incoming_username\":\"ushahidi@spotter.ngo\",\"incoming_password\":\"password\",\"outgoing_type\":\"SMTP\",\"outgoing_server\":\"postfix\",\"outgoing_port\":25,\"outgoing_security\":\"None\",\"outgoing_username\":\"ushahidi@spotter.ngo\",\"outgoing_password\":\"password\",\"from\":\"ushahidi@spotter.ngo\",\"from_name\":\"Ushahidi\"}'), -('data-provider','url','\"http:\\/\\/127.0.0.1\\/platform\\/api\\/v3\\/config\\/data-provider\"'); +('data-provider','url','\"https:\\/\\/ush.spotter.vm\\/platform\\/api\\/v3\\/config\\/data-provider\"'); diff --git a/ushahidi/etc/init.d/ushahidi b/ushahidi/etc/init.d/ushahidi index 1012ed3..6ddfaee 100755 --- a/ushahidi/etc/init.d/ushahidi +++ b/ushahidi/etc/init.d/ushahidi @@ -3,8 +3,7 @@ description="Ushahidi docker container" depend() { - need docker net mariadb - use dns logger netmount postfix + need docker mariadb postfix } start() { @@ -20,7 +19,11 @@ start() { } start_post() { - /usr/local/bin/spotter-appmgr update-proxy ushahidi + /usr/bin/spotter-appmgr register-proxy ushahidi +} + +stop_pre() { + /usr/bin/spotter-appmgr unregister-proxy ushahidi } stop() { diff --git a/ushahidi/srv/ushahidi/conf/config.json b/ushahidi/srv/ushahidi/conf/config.json index 77095cc..7a46b18 100644 --- a/ushahidi/srv/ushahidi/conf/config.json +++ b/ushahidi/srv/ushahidi/conf/config.json @@ -1,5 +1,5 @@ { - "backend_url": "http://127.0.0.1/platform", + "backend_url": "https://ush.spotter.vm/platform", "client_id": "ushahidiui", "client_secret": "35e7f0bca957836d05ca0492211b0ac707671261", "google_analytics_id": "AIzaSyBvIF3D550tlpL6o1xRrDurGo-81VhHlOw"