Skip to content

Database Administration for Diaspora pods (mongo shell)

One advantage of running your own Diaspora pod is the fact, that you have access to the MongoDB which is used to store your Seed. This allows you to do some functions which do not yet have a UI (for example canging the E-Mail address of a user) or which is required to work around alpha hickups (deleting duplicate requests). The mongo shell is a client to the mongodb, which can evaluate JavaScript expressions. It has some macros ("use", "show" and "help"), the other commands are typically JavaScript methods. First you assign a Database Object to the variable "db", you can use that with "use". In the case of Diaspora, the database is named "diaspora-ENVIRONMENT". If you start mongo shell, it will start with the database "test", but you can list all existing databases, and pick one:
$ mongo
connecting to: test
> print('hello JavaScript!')
hello JavaScript!
> show dbs
> use diaspora-development
switched to db diaspora-development
> db
> show collections
Note: you can specify non-existing databases and collections, they are initially empty but will be created, so do not misstype. You can use to see the available methods on a collection object. find() is used to search and display documents. If you specify no parameters it will return a cursort with all documents. The first parameter can be a list of filter criterias, and the second parameters a list of properties to return. mongo shell will iterate and print the first ten entries of a cursor automatically:
> db.users.find({},{username:1,email:1})
{ "_id" : ObjectId("4cf1..02"), "username" : "bernd", "email" : "" }
{ "_id" : ObjectId("4cf1..2d"), "username" : "mela", "email" : "" }
{ "_id" : ObjectId("4cf2..3b"), "username" : null, "email" : "" }
Here you can see, that this pod has 3 users (seeds), two are already established, the third is a pending invite (token). To change the e-mail address of a existing user you can assign the document to a variable, change the desired property and update the collection. For this we use the findOne method, which does return the first match instead of a cursor:
> var bernd = db.users.findOne({username:"bernd"})
> print(
> = ""
> db.users.findOne({username:"bernd"}).email
The above will not create a new document, since the variable "bernd" contains the property _id, and therefore it will update the existing entry in the collection. You need to know that db.users contains the actual users of the pod (i.e. the seeds) and db.people contains a copy of the public part of other seeds (if you received a request from them, or if you added them to an aspect).
> db.requests.findOne()
        "_id" : ObjectId("4cf1...a3"),
        "sent" : true,
        "from_id" : ObjectId("4cf1...03"),
        "to_id" : ObjectId("4cee7...a9"),
        "into_id" : ObjectId("4cf1...9d")
> db.people.findOne({_id:ObjectId("4cf1...03")}).diaspora_handle
> db.people.findOne({_id:ObjectId("4cee7...a9")}).diaspora_handle
> db.aspects.findOne({_id: ObjectId("4cf1...9d")}).name
As you can see I sent a request to "Daniel", inviting him to my aspect "Piraten", but he has not yet responded. Hope this helps you to find your way around in the object model of Diaspora. I recommend you read the MongoDB tutorial to better use the mongo shell, and check the JS API documentation for the details.

Apache als Reverse Proxy für Diaspora

Diaspora* die Software für verteilte soziale Netze wurde in einer Alpha Version veröffentlicht. Bei Diaspora ist vorgesehen dass es keine zentrale Plattform gibt, sondern Benutzer Ihre eigenen Server - Pods genannt - betreiben. Da es aktuell auch auf dem offiziellen pod von keine Benutzer freigeschalten werden, ergibt es Sinn einen eigenen Server aufzusetzen. Im Diaspora Wiki findet man dazu eine Anleitung. Allerdings beschreibt diese nicht, wie man in einer Produktivumgebung die Ruby Anwendung mit einem Webserver versieht, der die Anfragen auf Port 80 entgegennimmt (und statische Assets direkt ausliefert). Ich habe dazu einen virtuellen Host mit Apache eingerichtet, die Konfiguration sieht so aus:
LoadModule proxy_module ...
LoadModule proxy_http_module...

<VirtualHost *>
    DocumentRoot /var/www/
    ErrorLog /var/log/httpd/
    CustomLog /var/log/httpd/ combined

    Alias /uploads/ "/var/www/"
    Alias /images/ "/var/www/"
    Alias /stylesheets/ "/var/www/"
    Alias /javascripts/ "/var/www/"

    ProxyPass /

  <Directory "/var/www/">
    Options Indexes FollowSymLinks MultiViews IncludesNoExec ExecCGI
    AllowOverride All
    Order Allow,Deny
    Allow from All
D.h. Diaspora ist im Verzeichnis /var/www/ installiert, und der Ruby Server "thin" ist erreichbar auf dem Port 3000. Falls es jemand testen will, mein Diaspora Seed ist damit unter erreichbar.