Skip to content

Commit

Permalink
Merge pull request #6608 from RocketChat/feature/snap-oplog
Browse files Browse the repository at this point in the history
[New] Switch Snaps to use oplog
  • Loading branch information
engelgabriel authored Apr 6, 2017
2 parents 2fa965c + f755848 commit b3dcf1a
Show file tree
Hide file tree
Showing 7 changed files with 63 additions and 29 deletions.
8 changes: 4 additions & 4 deletions .snapcraft/edge/snapcraft.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down
6 changes: 0 additions & 6 deletions .snapcraft/resources/initmongo

This file was deleted.

8 changes: 0 additions & 8 deletions .snapcraft/resources/initmongoreplset.js

This file was deleted.

13 changes: 13 additions & 0 deletions .snapcraft/resources/initreplset.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
var ism = db.isMaster();
if (!ism.ismaster) {
rs.initiate(
{
_id: 'rs0',
members: [
{
_id: 0,
host: 'localhost:27017'
}
]
});
}
41 changes: 41 additions & 0 deletions .snapcraft/resources/startRocketChat
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#!/bin/bash

function start_rocketchat {
echo "Checking if oplog has been enabled, and enabling if not"
LC_ALL=C 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
8 changes: 1 addition & 7 deletions .snapcraft/resources/startmongo
Original file line number Diff line number Diff line change
@@ -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
8 changes: 4 additions & 4 deletions .snapcraft/stable/snapcraft.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit b3dcf1a

Please sign in to comment.