* 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:
sigoa 2017-12-22 20:07:15 +00:00 committed by GitHub
parent d84ef22726
commit 4ac0d30e4d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 85 additions and 6 deletions

View File

@ -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, another person or to many subscribers. It is decentralized and trustless,
meaning that you need-not inherently trust any entities like root certificate meaning that you need-not inherently trust any entities like root certificate
authorities. It uses strong authentication, which means that the sender of a 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 sender and receiver of messages, from passive eavesdroppers like those running
warrantless wiretapping programs. warrantless wiretapping programs.

View 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)

View 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

View File

@ -363,7 +363,7 @@ class Main:
# fork not implemented # fork not implemented
pass pass
else: else:
shared.thisapp.lock() # relock shared.thisapp.lock(True) # relock and write pid
shared.thisapp.lockPid = None # indicate we're the final child shared.thisapp.lockPid = None # indicate we're the final child
sys.stdout.flush() sys.stdout.flush()
sys.stderr.flush() sys.stderr.flush()

View File

@ -36,7 +36,7 @@ class singleinstance:
self.initialized = True self.initialized = True
atexit.register(self.cleanup) atexit.register(self.cleanup)
def lock(self): def lock(self, writePid = False):
if self.lockPid is None: if self.lockPid is None:
self.lockPid = os.getpid() self.lockPid = os.getpid()
if sys.platform == 'win32': if sys.platform == 'win32':
@ -68,6 +68,7 @@ class singleinstance:
sys.exit(-1) sys.exit(-1)
else: else:
pidLine = "%i\n" % self.lockPid pidLine = "%i\n" % self.lockPid
if writePid:
self.fp.truncate(0) self.fp.truncate(0)
self.fp.write(pidLine) self.fp.write(pidLine)
self.fp.flush() self.fp.flush()