I've been trying to understand how to setup systems from
the ground up on Ubuntu. I just installed redis
onto
the box and here's how I did it and some things to look
out for.
To install:
# probably ripped off from somewhere on drupal.org | |
# requires the services module | |
import xmlrpclib | |
s = xmlrpclib.ServerProxy('http://localhost/services/xmlrpc') | |
class DrupalNode: | |
def __init__(self, title, body, path, ntype='page', uid=1, username='mmatienzo'): | |
self.title = title |
#! /usr/bin/python | |
import xmlrpclib, pprint | |
class DrupalNode: | |
def __init__(self, title, body, ntype='article', uid=1, username ='admin'): | |
self.title = title | |
self.body = body | |
self.type = ntype |
description "Celery for ReadTheDocs" | |
start on runlevel [2345] | |
stop on runlevel [!2345] | |
#Send KILL after 20 seconds | |
kill timeout 20 | |
script | |
chdir /home/ubuntu/playground/tw | |
exec bin/python manage.py celeryd -B -c 4 -f /home/ubuntu/log/celery.log | |
end script |
description "Test Django instance" | |
start on runlevel [2345] | |
stop on runlevel [06] | |
respawn | |
respawn limit 10 5 | |
exec /path/to/test/hello/script.sh | |
#!/bin/bash |
function write($path, $content, $mode="w+") | |
{ if (file_exists($path) && !is_writeable($path)){ return false; } if ($fp = fopen($path, $mode)){ fwrite($fp, $content); fclose($fp); } else { return false; } return true; } |
""" | |
This is a simple example of WebSocket + Tornado + Redis Pub/Sub usage. | |
Do not forget to replace YOURSERVER by the correct value. | |
Keep in mind that you need the *very latest* version of your web browser. | |
You also need to add Jacob Kristhammar's websocket implementation to Tornado: | |
Grab it here: | |
http://gist.github.com/526746 | |
Or clone my fork of Tornado with websocket included: | |
http://github.com/pelletier/tornado | |
Oh and the Pub/Sub protocol is only available in Redis 2.0.0: |
<?xml version="1.0" encoding="UTF-8"?> | |
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> | |
<plist version="1.0"> | |
<dict> | |
<key>Label</key> | |
<string>redis-server</string> | |
<key>ProgramArguments</key> | |
<array> | |
<string>/opt/local/bin/redis-server</string> | |
</array> |
dispatch_queue_t queue = dispatch_queue_create("yourname", NULL); | |
// execute a task on that queue asynchronously | |
dispatch_async(queue, ^{ | |
//Code to execute here | |
dispatch_async(dispatch_get_main_queue(), ^{ | |
// Callback on the main thread when code above is done |