Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,14 @@ RUN apt-get update -q && \
python2 \
net-tools \
pritunl \
mongodb-clients \
psmisc && \
rm -rf /var/lib/apt/lists/*

COPY plugins /var/lib/pritunl/plugins
COPY entrypoint.sh /
RUN chmod +x /entrypoint.sh
COPY mongo-attach-all.js /

EXPOSE 80
EXPOSE 443
Expand Down
7 changes: 7 additions & 0 deletions entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,11 @@ cat << EOF >/etc/pritunl.conf
}
EOF

#detach the process, sleep for 1 min, then do the thing
# --quiet so passwords don't land in logs
nohup bash -c "sleep 60 && mongo --host $PRITUNL_MONGODB_URI --quiet /mongo-attach-all.js" >>/var/log/pritunl_journal.log 2>&1 &
# do it again at 5 min in case you missed some at 5
nohup bash -c "sleep 300 && mongo --host $PRITUNL_MONGODB_URI --quiet /mongo-attach-all.js" >>/var/log/pritunl_journal.log 2>&1 &


exec /usr/bin/pritunl start -c /etc/pritunl.conf
9 changes: 9 additions & 0 deletions mongo-attach-all.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
var hostName = 'vpn.stratasan.com';
//remove lingering Offline hosts
db.hosts.remove({'status': 'offline'});
//update hosts that arent the hostName to have the hostname
db.hosts.updateMany({'public_address': {$ne: hostName}}, {$set: {'public_address': hostName}});
// Update server(s) to attach all online hosts
var hostIds = db.hosts.find({'status': 'online'}, {_id:1}).map(function(item){ return item._id; });
db.servers.update({}, {$set: {'hosts': hostIds}});
db.servers.updateMany({'status': 'offline'}, {$set: {'status': 'online'}});