diff --git a/lib/discourse.sh b/lib/discourse.sh new file mode 100644 index 0000000..8726b94 --- /dev/null +++ b/lib/discourse.sh @@ -0,0 +1,209 @@ +#!/bin/bash +# +# Discourse Service + +PATH=$HOME/.docker/cli-plugins:/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin +get_appvars + +config_discourse() { + echo -ne "\n* Configuring discourse container.." + + if [ ! -d "/federated/apps/discourse" ]; then + mkdir -p /federated/apps/discourse/data/discourse/bitnami/discourse + mkdir -p /federated/apps/discourse/data/sidekiq/bitnami/discourse + fi + +cat > /federated/apps/discourse/docker-compose.yml < /federated/apps/discourse/.env < /dev/null +#docker exec pdnsmysql bash -c "mysql -uroot -p$MYSQL_ROOTPASSWORD -h 10.0.0.2 -e \"CREATE USER 'discourse'@'%' IDENTIFIED BY '$DISCOURSE_SECRET';\"" &> /dev/null +#docker exec pdnsmysql bash -c "mysql -uroot -p$MYSQL_ROOTPASSWORD -h 10.0.0.2 -e \"grant all privileges on discourse.* to 'discourse'@'%';\"" &> /dev/null +#docker exec pdnsmysql bash -c "mysql -uroot -p$MYSQL_ROOTPASSWORD -h 10.0.0.2 -e 'flush privileges;'" &> /dev/null + + +# Create database and user in postgresql +docker exec postgresql bash -c "PGPASSWORD=LUemlFaADvgD0QCVn9KDaqy9qKpn05Ed psql -U postgres -h 10.0.0.2 -w -c \"CREATE USER discourse WITH PASSWORD '$DISCOURSE_SECRET'\"" +docker exec postgresql bash -c "PGPASSWORD=LUemlFaADvgD0QCVn9KDaqy9qKpn05Ed psql -U postgres -h 10.0.0.2 -w -c \"CREATE DATABASE discourse\"" +docker exec postgresql bash -c "PGPASSWORD=LUemlFaADvgD0QCVn9KDaqy9qKpn05Ed psql -U postgres -h 10.0.0.2 -w -c \"GRANT ALL PRIVILEGES ON DATABASE discourse TO discourse\"" +#docker exec postgresql psql -U postgres -c "CREATE USER discourse WITH PASSWORD '$DISCOURSE_SECRET'" &> /dev/null +#docker exec postgresql psql -U postgres -c "CREATE DATABASE discourse" &> /dev/null +#docker exec postgresql psql -U postgres -c "GRANT ALL PRIVILEGES ON DATABASE discourse TO discourse" &> /dev/null + +echo -ne "done.\n" +} +start_discourse() { + # Start service with command to make sure it's up before proceeding + start_service "discourse" "nc -z 172.99.0.43 8080 &> /dev/null" "7" + + docker exec pdns pdnsutil add-record $DOMAIN discourse A 86400 $EXTERNALIP &> /dev/null + [ $? -ne 0 ] && fail "Couldn't add dns record for discourse" + + kill -9 $SPINPID &> /dev/null + echo -ne "done.\n" +} +email_discourse() { + echo -ne "* Sending email to customer.." + spin & + SPINPID=$! + +cat > /federated/apps/mail/data/root/certs/mailfile < +
+

+

Discourse is now installed on $DOMAIN

+

+Here is your applications chart on how to access this service:
+

+

Applications

+ + ++++++++ + + + + + + + + + + + + + + + + + + + + +
ServiceLinkUser / PassAccessDocsDescription
Discoursediscourse.$DOMAINadmin@$DOMAIN
$ADMINPASS
User access is separate from panelClick hereDiscourse is a simple, open-source, self-hosted, easy-to-use platform (Wiki) for organising and storing information
+

Thanks for your support!

+

+Thank you for your support of Federated Computer. We really appreciate it and hope you have a very successful +time with Federated Core. +

+Again, if we can be of any assistance, please don't hesitate to get in touch. +

+Support: https://support.federated.computer
+Phone: (970) 722-8715
+Email: support@federated.computer
+

+It's your computer. Let's make it work for you! + +EOF + + # Send out e-mail from mail container with details + docker exec mail bash -c "mail -r admin@$DOMAIN -a \"Content-type: text/html\" -s \"Application installed on $DOMAIN\" $EMAIL < /root/certs/mailfile" + rm /federated/apps/mail/data/root/certs/mailfile + + kill -9 $SPINPID &> /dev/null + echo -ne "done.\n" +} +uninstall_discourse() { + echo -ne "* Uninstalling discourse container.." + spin & + SPINPID=$! + + # First stop the service + cd /federated/apps/discourse && docker-compose -f docker-compose.yml -p discourse down &> /dev/null + + # Delete database and user in postgresql + docker exec postgresql psql -U postgres -c "DROP DATABASE discourse" &> /dev/null + docker exec postgresql psql -U postgres -c "DROP USER discourse" &> /dev/null + + # Delete the app directory + rm -rf /federated/apps/discourse + + kill -9 $SPINPID &> /dev/null + echo -ne "done.\n" +} diff --git a/lib/redis.sh b/lib/redis.sh new file mode 100644 index 0000000..ac3da10 --- /dev/null +++ b/lib/redis.sh @@ -0,0 +1,74 @@ +#!/bin/bash +# +# Redis Service + +PATH=$HOME/.docker/cli-plugins:/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin +get_appvars + +config_redis() { + echo -ne "\n* Configuring redis container.." + + if [ ! -d "/federated/apps/redis" ]; then + mkdir -p /federated/apps/redis/data/bitnami/redis/data + chown -R 1001 /federated/apps/redis/data/bitnami/redis + fi + +cat > /federated/apps/redis/docker-compose.yml < /federated/apps/redis/.env < /dev/null" "7" + + kill -9 $SPINPID &> /dev/null + echo -ne "done.\n" +} +uninstall_redis() { + spin & + SPINPID=$! + + # First stop the service + cd /federated/apps/redis && docker-compose -f docker-compose.yml -p redis down &> /dev/null + + # Delete the app directory + rm -rf /federated/apps/redis + + kill -9 $SPINPID &> /dev/null + echo -ne "done.\n" +}