From da6c850091f66d82c5f838361c219dba3ee4eac3 Mon Sep 17 00:00:00 2001 From: Aaron Ogle Date: Wed, 5 Apr 2017 14:05:14 -0500 Subject: [PATCH 1/4] Switch snap to replicaset mode --- .snapcraft/resources/initmongo | 6 ---- .snapcraft/resources/initmongoreplset.js | 8 ----- .snapcraft/resources/initreplset.js | 13 ++++++++ .snapcraft/resources/startRocketChat | 41 ++++++++++++++++++++++++ .snapcraft/resources/startmongo | 8 +---- .snapcraft/stable/snapcraft.yaml | 8 ++--- 6 files changed, 59 insertions(+), 25 deletions(-) delete mode 100755 .snapcraft/resources/initmongo delete mode 100644 .snapcraft/resources/initmongoreplset.js create mode 100644 .snapcraft/resources/initreplset.js create mode 100755 .snapcraft/resources/startRocketChat diff --git a/.snapcraft/resources/initmongo b/.snapcraft/resources/initmongo deleted file mode 100755 index 176f208ba809..000000000000 --- a/.snapcraft/resources/initmongo +++ /dev/null @@ -1,6 +0,0 @@ -#!/bin/sh -echo "initializing replset if necessary... in 60 seconds" -sleep 60 -echo "after 60 seconds, checking for replset..." -mongo $SNAP/bin/initmongoreplset.js - diff --git a/.snapcraft/resources/initmongoreplset.js b/.snapcraft/resources/initmongoreplset.js deleted file mode 100644 index 5ef3b0e0caa7..000000000000 --- a/.snapcraft/resources/initmongoreplset.js +++ /dev/null @@ -1,8 +0,0 @@ -var ism = db.isMaster(); -printjson(ism); -if (ism.ismaster) { - } else -{ - var msg = rs.initiate(); - printjson(msg); -} diff --git a/.snapcraft/resources/initreplset.js b/.snapcraft/resources/initreplset.js new file mode 100644 index 000000000000..6883e248ebd6 --- /dev/null +++ b/.snapcraft/resources/initreplset.js @@ -0,0 +1,13 @@ +var ism = db.isMaster(); +if (!ism.ismaster) { + rs.initiate( + { + _id: 'rs0', + members: [ + { + _id: 0, + host: 'localhost:27017' + } + ] + }); +} diff --git a/.snapcraft/resources/startRocketChat b/.snapcraft/resources/startRocketChat new file mode 100755 index 000000000000..af95ddce5f95 --- /dev/null +++ b/.snapcraft/resources/startRocketChat @@ -0,0 +1,41 @@ +#!/bin/bash + +function start_rocketchat { + echo "Checking if oplog has been enabled, and enabling if not" + mongo $SNAP/bin/initreplset.js + + export BABEL_CACHE_DIR=/tmp + export ROOT_URL=http://localhost + export PORT=3000 + export MONGO_URL=mongodb://localhost:27017/parties + export MONGO_OPLOG_URL=mongodb://localhost:27017/local + export Accounts_AvatarStorePath=$SNAP_COMMON/uploads + + node $SNAP/main.js +} + +sleep_time=5 +try_times=0 + +function try_start { + + search=$(ps --pid $(cat $SNAP_COMMON/mongod.pid) -o comm=) + + if [ $search ] + then + start_rocketchat + else + if [[ "$try_times" == 5 || "$try_times" > 5 ]]; then + echo "Was unable to connect to Mongo. Please make sure Mongo has started successfully: sudo systemctl status snap.rocketchat-server.rocketchat-mongo to view logs: sudo journalctl -u snap.rocketchat-server.rocketchat-mongo" + exit 1; + fi + + ((try_times += 1)) + ((sleep_time += 5)) + echo "Mongo is not available, can't start. Waiting ${sleep_time} seconds and trying again" + sleep $sleep_time + try_start + fi +} + +try_start diff --git a/.snapcraft/resources/startmongo b/.snapcraft/resources/startmongo index 9df9df325609..5697c6df6dba 100755 --- a/.snapcraft/resources/startmongo +++ b/.snapcraft/resources/startmongo @@ -1,7 +1 @@ -#!/bin/sh -echo "initializing replset backgrounded..." -$SNAP/bin/initmongo & - -echo "Starting mongodb server in replicaset standalone mode..." -mongod --bind_ip 127.0.0.1 --smallfiles --dbpath=$SNAP_COMMON --journal --replSet rcreplset - +env LC_ALL=C mongod --bind_ip 127.0.0.1 --pidfilepath $SNAP_COMMON/mongod.pid --smallfiles --journal --dbpath=$SNAP_COMMON --replSet rs0 diff --git a/.snapcraft/stable/snapcraft.yaml b/.snapcraft/stable/snapcraft.yaml index 96d3b44d9a2e..9c6c3cb65763 100644 --- a/.snapcraft/stable/snapcraft.yaml +++ b/.snapcraft/stable/snapcraft.yaml @@ -13,11 +13,11 @@ description: Have your own Slack like online chat, built with Meteor. https://ro confinement: strict apps: rocketchat-server: - command: env BABEL_CACHE_DIR=/tmp ROOT_URL=http://localhost PORT=3000 MONGO_URL=mongodb://localhost:27017/parties Accounts_AvatarStorePath=$SNAP_COMMON/uploads node $SNAP/main.js + command: startRocketChat daemon: simple plugs: [network, network-bind] rocketchat-mongo: - command: env LC_ALL=C mongod --bind_ip 127.0.0.1 --smallfiles --dbpath=$SNAP_COMMON + command: startmongo daemon: simple plugs: [network, network-bind] rocketchat-caddy: @@ -84,10 +84,10 @@ parts: organize: rcbackup: bin/rcbackup startmongo: bin/startmongo - initmongo: bin/initmongo + startRocketChat: bin/startRocketChat + initreplset.js: bin/initreplset.js Caddyfile: bin/Caddyfile initcaddy: bin/initcaddy - initmongoreplset.js: bin/initmongoreplset.js snap: - bin caddy: From 1d8d7e43aca02810e111c514a2c676f217e501f1 Mon Sep 17 00:00:00 2001 From: Aaron Ogle Date: Wed, 5 Apr 2017 14:08:38 -0500 Subject: [PATCH 2/4] Add for edge channel as well --- .snapcraft/edge/snapcraft.yaml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.snapcraft/edge/snapcraft.yaml b/.snapcraft/edge/snapcraft.yaml index 218104482cf7..432d07b0eba7 100644 --- a/.snapcraft/edge/snapcraft.yaml +++ b/.snapcraft/edge/snapcraft.yaml @@ -13,11 +13,11 @@ description: Have your own Slack like online chat, built with Meteor. https://ro confinement: strict apps: rocketchat-server: - command: env BABEL_CACHE_DIR=/tmp ROOT_URL=http://localhost PORT=3000 MONGO_URL=mongodb://localhost:27017/parties Accounts_AvatarStorePath=$SNAP_COMMON/uploads node $SNAP/main.js + command: startRocketChat daemon: simple plugs: [network, network-bind] rocketchat-mongo: - command: env LC_ALL=C mongod --bind_ip 127.0.0.1 --smallfiles --dbpath=$SNAP_COMMON + command: startmongo daemon: simple plugs: [network, network-bind] rocketchat-caddy: @@ -84,10 +84,10 @@ parts: organize: rcbackup: bin/rcbackup startmongo: bin/startmongo - initmongo: bin/initmongo + startRocketChat: bin/startRocketChat + initreplset.js: bin/initreplset.js Caddyfile: bin/Caddyfile initcaddy: bin/initcaddy - initmongoreplset.js: bin/initmongoreplset.js snap: - bin caddy: From 5bc06daced8daa404463c68459eebd854b325e28 Mon Sep 17 00:00:00 2001 From: Aaron Ogle Date: Wed, 5 Apr 2017 16:27:01 -0500 Subject: [PATCH 3/4] Add LC_ALL --- .snapcraft/resources/startRocketChat | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.snapcraft/resources/startRocketChat b/.snapcraft/resources/startRocketChat index af95ddce5f95..1adac509a218 100755 --- a/.snapcraft/resources/startRocketChat +++ b/.snapcraft/resources/startRocketChat @@ -2,7 +2,7 @@ function start_rocketchat { echo "Checking if oplog has been enabled, and enabling if not" - mongo $SNAP/bin/initreplset.js + LC_ALL=C mongo $SNAP/bin/initreplset.js export BABEL_CACHE_DIR=/tmp export ROOT_URL=http://localhost From f755848a9c6af5a6ce07a5d78256534018f90494 Mon Sep 17 00:00:00 2001 From: Aaron Ogle Date: Wed, 5 Apr 2017 16:28:46 -0500 Subject: [PATCH 4/4] fix space --- .snapcraft/resources/startRocketChat | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.snapcraft/resources/startRocketChat b/.snapcraft/resources/startRocketChat index 1adac509a218..b00ab757b0f5 100755 --- a/.snapcraft/resources/startRocketChat +++ b/.snapcraft/resources/startRocketChat @@ -27,7 +27,7 @@ function try_start { else if [[ "$try_times" == 5 || "$try_times" > 5 ]]; then echo "Was unable to connect to Mongo. Please make sure Mongo has started successfully: sudo systemctl status snap.rocketchat-server.rocketchat-mongo to view logs: sudo journalctl -u snap.rocketchat-server.rocketchat-mongo" - exit 1; + exit 1; fi ((try_times += 1))