V0.6 (#3)
* This type of data is called metadata * Systemd config file - tested on Debian 9, you may have to adjust paths/uids if your deployment differs * Add collectd monitoring script * Only write PID after last fork - should fix systemd integration
This commit is contained in:
parent
d84ef22726
commit
4ac0d30e4d
|
@ -5,7 +5,7 @@ Bitmessage is a P2P communications protocol used to send encrypted messages to
|
|||
another person or to many subscribers. It is decentralized and trustless,
|
||||
meaning that you need-not inherently trust any entities like root certificate
|
||||
authorities. It uses strong authentication, which means that the sender of a
|
||||
message cannot be spoofed, and it aims to hide "non-content" data, like the
|
||||
message cannot be spoofed, and it aims to hide metadata, like the
|
||||
sender and receiver of messages, from passive eavesdroppers like those running
|
||||
warrantless wiretapping programs.
|
||||
|
||||
|
|
60
packages/collectd/pybitmessagestatus.py
Normal file
60
packages/collectd/pybitmessagestatus.py
Normal file
|
@ -0,0 +1,60 @@
|
|||
#!/usr/bin/env python2.7
|
||||
|
||||
import collectd
|
||||
import json
|
||||
import xmlrpclib
|
||||
|
||||
pybmurl = ""
|
||||
api = ""
|
||||
|
||||
def init_callback():
|
||||
global api
|
||||
api = xmlrpclib.ServerProxy(pybmurl)
|
||||
collectd.info('pybitmessagestatus.py init done')
|
||||
|
||||
def config_callback(ObjConfiguration):
|
||||
global pybmurl
|
||||
apiUsername = ""
|
||||
apiPassword = ""
|
||||
apiInterface = "127.0.0.1"
|
||||
apiPort = 8445
|
||||
for node in ObjConfiguration.children:
|
||||
key = node.key.lower()
|
||||
if key.lower() == "apiusername" and node.values:
|
||||
apiUsername = node.values[0]
|
||||
elif key.lower() == "apipassword" and node.values:
|
||||
apiPassword = node.values[0]
|
||||
elif key.lower() == "apiinterface" and node.values:
|
||||
apiInterface = node.values[0]
|
||||
elif key.lower() == "apiport" and node.values:
|
||||
apiPort = node.values[0]
|
||||
pybmurl = "http://" + apiUsername + ":" + apiPassword + "@" + apiInterface+ ":" + str(int(apiPort)) + "/"
|
||||
collectd.info('pybitmessagestatus.py config done')
|
||||
|
||||
def read_callback():
|
||||
try:
|
||||
clientStatus = json.loads(api.clientStatus())
|
||||
except:
|
||||
collectd.info("Exception loading or parsing JSON")
|
||||
return
|
||||
|
||||
for i in ["networkConnections", "numberOfPubkeysProcessed", "numberOfMessagesProcessed", "numberOfBroadcastsProcessed"]:
|
||||
metric = collectd.Values()
|
||||
metric.plugin = "pybitmessagestatus"
|
||||
if i[0:6] == "number":
|
||||
metric.type = 'counter'
|
||||
else:
|
||||
metric.type = 'gauge'
|
||||
metric.type_instance = i.lower()
|
||||
try:
|
||||
metric.values = [clientStatus[i]]
|
||||
except:
|
||||
collectd.info("Value for %s missing" % (i))
|
||||
metric.dispatch()
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
else:
|
||||
collectd.register_init(init_callback)
|
||||
collectd.register_config(config_callback)
|
||||
collectd.register_read(read_callback)
|
18
packages/systemd/bitmessage.service
Normal file
18
packages/systemd/bitmessage.service
Normal file
|
@ -0,0 +1,18 @@
|
|||
[Unit]
|
||||
Description=Bitmessage Daemon
|
||||
After=network.target auditd.service
|
||||
|
||||
[Service]
|
||||
ExecStart=/usr/bin/python2 /usr/src/PyBitmessage/src/bitmessagemain.py
|
||||
ExecReload=/bin/kill -HUP $MAINPID
|
||||
KillMode=process
|
||||
Restart=on-failure
|
||||
Type=forking
|
||||
PIDFile=/var/lib/bitmessage/.config/PyBitmessage/singleton.lock
|
||||
User=bitmessage
|
||||
Group=nogroup
|
||||
WorkingDirectory=/var/lib/bitmessage
|
||||
Environment="HOME=/var/lib/bitmessage"
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
|
@ -363,7 +363,7 @@ class Main:
|
|||
# fork not implemented
|
||||
pass
|
||||
else:
|
||||
shared.thisapp.lock() # relock
|
||||
shared.thisapp.lock(True) # relock and write pid
|
||||
shared.thisapp.lockPid = None # indicate we're the final child
|
||||
sys.stdout.flush()
|
||||
sys.stderr.flush()
|
||||
|
|
|
@ -36,7 +36,7 @@ class singleinstance:
|
|||
self.initialized = True
|
||||
atexit.register(self.cleanup)
|
||||
|
||||
def lock(self):
|
||||
def lock(self, writePid = False):
|
||||
if self.lockPid is None:
|
||||
self.lockPid = os.getpid()
|
||||
if sys.platform == 'win32':
|
||||
|
@ -68,9 +68,10 @@ class singleinstance:
|
|||
sys.exit(-1)
|
||||
else:
|
||||
pidLine = "%i\n" % self.lockPid
|
||||
self.fp.truncate(0)
|
||||
self.fp.write(pidLine)
|
||||
self.fp.flush()
|
||||
if writePid:
|
||||
self.fp.truncate(0)
|
||||
self.fp.write(pidLine)
|
||||
self.fp.flush()
|
||||
|
||||
def cleanup(self):
|
||||
if not self.initialized:
|
||||
|
|
Reference in New Issue
Block a user