Skip to content

Instantly share code, notes, and snippets.

@azat
azat / mongos
Created April 25, 2012 09:16
mongos sysv init script
#!/bin/sh
#
# init.d script with LSB support.
#
# Copyright (c) 2007 Javier Fernandez-Sanguino <jfs@debian.org>
#
# This is free software; you may redistribute it and/or modify
# it under the terms of the GNU General Public License as
# published by the Free Software Foundation; either version 2,
# or (at your option) any later version.
@azat
azat / mongodb-configsrv
Created April 25, 2012 09:17
mongodb config server sysv init script
#!/bin/sh
#
# init.d script with LSB support.
#
# Copyright (c) 2007 Javier Fernandez-Sanguino <jfs@debian.org>
#
# This is free software; you may redistribute it and/or modify
# it under the terms of the GNU General Public License as
# published by the Free Software Foundation; either version 2,
# or (at your option) any later version.
@azat
azat / mongodb
Created April 25, 2012 09:17
clear mongodb sysv init script
#!/bin/sh
#
# init.d script with LSB support.
#
# Copyright (c) 2007 Javier Fernandez-Sanguino <jfs@debian.org>
#
# This is free software; you may redistribute it and/or modify
# it under the terms of the GNU General Public License as
# published by the Free Software Foundation; either version 2,
# or (at your option) any later version.
@azat
azat / mongodb-arbiter
Created May 21, 2012 12:12
mongodb arbiter sysv init script (replica set)
#!/bin/sh
#
# init.d script with LSB support.
#
# Copyright (c) 2007 Javier Fernandez-Sanguino <jfs@debian.org>
#
# This is free software; you may redistribute it and/or modify
# it under the terms of the GNU General Public License as
# published by the Free Software Foundation; either version 2,
# or (at your option) any later version.
@azat
azat / mongodb-arbiter.conf
Created May 21, 2012 12:13
mongodb arbiter configuration file
# mongodb-arbiter.conf
# Where to store the data.
# Note: if you run mongodb as a non-root user (recommended) you may
# need to create and set permissions for this directory manually,
# e.g., if the parent directory isn't mutable by the mongodb user.
#dbpath=/var/lib/mongodb
dbpath=/work/mongo/db_arbiter
@azat
azat / mongos.conf
Created May 21, 2012 12:14
mongos configuration file
logpath = /var/log/mongodb/mongos.log
logappend = true
configdb = 127.0.0.1:27019
@azat
azat / mongodb-configsrv.conf
Created May 21, 2012 12:15
mongodb-configsrv configuration file
configsvr = true
logpath = /var/log/mongodb/mongodcfg.log
logappend = true
dbpath = /work/mongo/configsrv
@azat
azat / crc32.js
Created May 21, 2012 12:40
crc32 javascript implementation
// @link http://www.digsys.se/JavaScript/CRC.aspx
var crc32 = {
// CRC polynomial 0xEDB88320
tab: [ // integer because this is a copy-paste from json string
0,1996959894,3993919788,2567524794,124634137,1886057615,3915621685,2657392035,
249268274,2044508324,3772115230,2547177864,162941995,2125561021,3887607047,2428444049,
498536548,1789927666,4089016648,2227061214,450548861,1843258603,4107580753,2211677639,
325883990,1684777152,4251122042,2321926636,335633487,1661365465,4195302755,2366115317,
997073096,1281953886,3579855332,2724688242,1006888145,1258607687,3524101629,2768942443,
901097722,1119000684,3686517206,2898065728,853044451,1172266101,3705015759,2882616665,
@azat
azat / shard-status.js
Created May 21, 2012 12:41
mongodb shard-status
// shard-status
while (true) {
db.currentOp().inprog.forEach(function(row) { if (row.query.moveChunk) printjson(row.query.shardId + " " + row.msg + " secs: " + row.secs_running + " switches: " + row.numYields); });
sleep(1000);
}
@azat
azat / mongodb-unshard.js
Created May 21, 2012 12:44
mongodb manually unshard
// set
var collection = ;
var db = ;
var fromHost = ;
// unshard
db = db.getMongo().getDB(db);
var collection = db.getCollection(collection);
var m = new Mongo(fromHost);