Rework Ushahidi

This commit is contained in:
Disassembler 2019-10-05 15:40:27 +02:00
parent 4ac414c691
commit 0f093a1087
Signed by: Disassembler
GPG Key ID: 524BD33A0EE29499
10 changed files with 74 additions and 65 deletions

View File

@ -3,18 +3,24 @@ set -ev
cd $(realpath $(dirname "${0}"))/install
# Check prerequisites
[ ! -e /run/openrc/started/mariadb ] && service mariadb start && STOP_MARIADB=1
# Create MariaDB instance
mkdir -p /srv/ushahidi/mariadb_conf /srv/ushahidi/mariadb_data
chown 103306:103306 /srv/ushahidi/mariadb_data
cp mariadb_conf/my.cnf /srv/ushahidi/mariadb_conf/my.cnf
chown -R 100000:100000 /srv/ushahidi/mariadb_conf
lxc-execute ushahidi-mariadb -- mysql_install_db --user=mysql --datadir=/var/lib/mysql --auth-root-authentication-method=socket --skip-test-db
# Create database
export USHAHIDI_PWD=$(head -c 18 /dev/urandom | base64 | tr -d '+/=')
envsubst <createdb.sql | lxc-attach mariadb -- mysql
service ushahidi-mariadb start
envsubst <createdb.sql | lxc-attach ushahidi-mariadb -- mysql
# Configure Ushahidi
mkdir -p /srv/ushahidi/conf /srv/ushahidi/data
chown 8014:8014 /srv/ushahidi/data
envsubst <srv/ushahidi/conf/env >/srv/ushahidi/conf/env
cp srv/ushahidi/conf/config.json /srv/ushahidi/conf/config.json
mkdir -p /srv/ushahidi/ushahidi_conf /srv/ushahidi/ushahidi_data
chown 108014:108014 /srv/ushahidi/ushahidi_data
envsubst <ushahidi_conf/env >/srv/ushahidi/ushahidi_conf/env
cp ushahidi_conf/config.json /srv/ushahidi/ushahidi_conf/config.json
chown -R 100000:100000 /srv/ushahidi/ushahidi_conf
# Populate database
lxc-execute ushahidi -- /srv/ushahidi/platform/bin/phinx migrate -c /srv/ushahidi/platform/application/phinx.php
@ -23,20 +29,15 @@ lxc-execute ushahidi -- /srv/ushahidi/platform/bin/phinx migrate -c /srv/ushahid
export USHAHIDI_ADMIN_USER=admin@example.com
export USHAHIDI_ADMIN_PWD=$(head -c 12 /dev/urandom | base64 | tr -d '+/=')
export USHAHIDI_ADMIN_HASH=$(python3 -c "import bcrypt; print(bcrypt.hashpw('${USHAHIDI_ADMIN_PWD}'.encode(), bcrypt.gensalt()).decode().replace('2b', '2y'))")
envsubst <adminpwd.sql | lxc-attach mariadb -- mysql ushahidi
# Install cron job
cp etc/periodic/15min/ushahidi /etc/periodic/15min/ushahidi
# Install service
cp etc/init.d/ushahidi /etc/init.d/ushahidi
rc-update -u
envsubst <adminpwd.sql | lxc-attach ushahidi-mariadb -- mysql ushahidi
# Install config update script
cp srv/ushahidi/update-conf.sh /srv/ushahidi/update-conf.sh
cp update-conf.sh /srv/ushahidi/update-conf.sh
# Stop services required for build
[ ! -z ${STOP_MARIADB} ] && service mariadb stop
# Stop services required for setup
service ushahidi-mariadb stop
# Register application
vmmgr register-app ushahidi ush "${USHAHIDI_ADMIN_USER}" "${USHAHIDI_ADMIN_PWD}"
# TODO: cron

View File

@ -1,23 +0,0 @@
#!/sbin/openrc-run
description="Ushahidi container"
depend() {
need mariadb
}
start() {
lxc-start ushahidi
}
start_post() {
vmmgr register-proxy ushahidi
}
stop_pre() {
vmmgr unregister-proxy ushahidi
}
stop() {
lxc-stop ushahidi
}

View File

@ -1,9 +0,0 @@
#!/bin/sh
if [ -e /run/openrc/started/ushahidi ]; then
lxc-attach -u 8014 -g 8014 ushahidi -- sh -c 'cd /srv/ushahidi/platform; bin/ushahidi dataprovider outgoing' >/dev/null
lxc-attach -u 8014 -g 8014 ushahidi -- sh -c 'cd /srv/ushahidi/platform; bin/ushahidi dataprovider incoming' >/dev/null
lxc-attach -u 8014 -g 8014 ushahidi -- sh -c 'cd /srv/ushahidi/platform; bin/ushahidi savedsearch' >/dev/null
lxc-attach -u 8014 -g 8014 ushahidi -- sh -c 'cd /srv/ushahidi/platform; bin/ushahidi notification queue' >/dev/null
lxc-attach -u 8014 -g 8014 ushahidi -- sh -c 'cd /srv/ushahidi/platform; bin/ushahidi webhook send' >/dev/null
fi

View File

@ -0,0 +1,24 @@
[mysqld]
skip-external-locking
skip-name-resolve
key_buffer_size = 16M
max_allowed_packet = 1M
table_open_cache = 64
sort_buffer_size = 512K
net_buffer_length = 8K
read_buffer_size = 256K
read_rnd_buffer_size = 512K
myisam_sort_buffer_size = 8M
[mysqldump]
quick
max_allowed_packet = 1M
[mysql]
no-auto-rehash
[myisamchk]
key_buffer_size = 20M
sort_buffer_size = 20M
read_buffer = 2M
write_buffer = 2M

View File

@ -33,8 +33,4 @@ RUN EOF
rm aura.patch
EOF
MOUNT FILE /srv/ushahidi/conf/env srv/ushahidi/platform/.env
MOUNT FILE /srv/ushahidi/conf/config.json srv/ushahidi/config.json
MOUNT DIR /srv/ushahidi/data srv/ushahidi/platform/application/media/uploads
CMD s6-svscan /etc/services.d

29
lxc-apps/ushahidi/meta Normal file
View File

@ -0,0 +1,29 @@
{
"version": "3.12.3-190620",
"meta": {
"title": "Ushahidi",
"desc-cs": "Skupinová reakce na události",
"desc-en": "Group reaction to events",
"license": "GPL",
},
"containers": {
"ushahidi": {
"image": "ushahidi_3.12.3-190620",
"depends": [
"ushahidi-mariadb"
],
"mounts": [
["FILE", "/srv/ushahidi/ushahidi_conf/env", "/srv/ushahidi/platform/.env"],
["FILE", "/srv/ushahidi/ushahidi_conf/config.json", "/srv/ushahidi/config.json"],
["DIR", "/srv/ushahidi/ushahidi_data", "/srv/ushahidi/platform/application/media/uploads"]
]
},
"ushahidi-mariadb": {
"image": "mariadb_10.3.15-190620",
"mounts": [
["FILE", "/srv/ushahidi/mariadb_conf/my.cnf", "/etc/my.cnf"],
["DIR", "/srv/ushahidi/mariadb_data", "/var/lib/mysql"]
]
}
}
}

View File

@ -1,17 +1,8 @@
#!/bin/sh
set -ev
# Remove cronjob
rm -f /etc/periodic/15min/ushahidi
# Remove service
rm -f /etc/init.d/ushahidi
rc-update -u
# Drop database and user
[ ! -e /run/openrc/started/mariadb ] && service mariadb start && STOP_MARIADB=1
echo 'DROP DATABASE IF EXISTS ushahidi; DROP USER IF EXISTS ushahidi;' | lxc-attach mariadb -- mysql
[ ! -z ${STOP_MARIADB} ] && service mariadb stop
# Remove persistent data
rm -rf /srv/ushahidi
# Unregister application
vmmgr unregister-app ushahidi