-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
bring weather.im iembot's runtime script here
- Loading branch information
Showing
4 changed files
with
80 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
"""Our script that is exec'd from twistd via run.sh""" | ||
# Base Python | ||
import json | ||
|
||
# Twisted Bits | ||
from twisted.application import service, internet | ||
from twisted.web import server | ||
from twisted.internet import reactor | ||
from twisted.enterprise import adbapi | ||
from txyam.client import YamClient | ||
|
||
# Local Import | ||
from iembot import iemchatbot, webservices | ||
|
||
dbconfig = json.load(open('settings.json')) | ||
|
||
application = service.Application("Public IEMBOT") | ||
serviceCollection = service.IServiceCollection(application) | ||
|
||
# This provides DictCursors! | ||
dbrw = dbconfig.get('databaserw') | ||
dbpool = adbapi.ConnectionPool("pyiem.twistedpg", cp_reconnect=True, | ||
database=dbrw.get('openfire'), | ||
host=dbrw.get('host'), | ||
password=dbrw.get('password'), | ||
user=dbrw.get('user')) | ||
|
||
memcache_client = YamClient(reactor, ['tcp:iem-memcached3:11211', ]) | ||
memcache_client.connect() | ||
|
||
jabber = iemchatbot.JabberClient("iembot", dbpool, memcache_client) | ||
|
||
defer = dbpool.runQuery("select propname, propvalue from properties") | ||
defer.addCallback(jabber.fire_client_with_config, serviceCollection) | ||
|
||
# 2. JSON channel requests | ||
json = server.Site(webservices.JSONRootResource(jabber), logPath='/dev/null') | ||
x = internet.TCPServer(9003, json) # pylint: disable=no-member | ||
x.setServiceParent(serviceCollection) | ||
|
||
# 3. Answer requests for RSS feeds of the bot logs | ||
rss = server.Site(webservices.RSSRootResource(jabber), logPath="/dev/null") | ||
r = internet.TCPServer(9004, rss) # pylint: disable=no-member | ||
r.setServiceParent(serviceCollection) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
#!/bin/sh | ||
# Starts the IEMBot Process, run from ldm's crontab | ||
|
||
if [ -e iembot.pid ]; then | ||
kill -INT `cat iembot.pid ` | ||
sleep 5 | ||
if [ -e iembot.pid ]; then | ||
echo 'IEMBot still alive? kill -9 this time' | ||
kill -9 `cat iembot.pid ` | ||
sleep 1 | ||
rm -f iembot.pid | ||
fi | ||
fi | ||
twistd --logfile=logs/iembot.log --pidfile=iembot.pid -y iembot.tac |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
{ | ||
"databaserw": { | ||
"openfire": "mesosite", | ||
"postgis": "nwschat-postgis", | ||
"archive": "nwschat-archive", | ||
"host": "postgreswrite", | ||
"user": "akrherz", | ||
"password": "secret" | ||
}, | ||
"databasero": { | ||
"openfire": "nwschat-openfire", | ||
"postgis": "nwschat-postgis", | ||
"archive": "nwschat-archive", | ||
"host": "postgresread", | ||
"user": "nwschatread", | ||
"password": "secret" | ||
} | ||
} |