Skip to content

Commit

Permalink
feat: deb package build script
Browse files Browse the repository at this point in the history
  • Loading branch information
ggmartins committed Aug 21, 2020
1 parent 1873168 commit f810559
Show file tree
Hide file tree
Showing 10 changed files with 63 additions and 8 deletions.
17 changes: 14 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,18 @@
# netmicroscope-daemon
NetMicroscope Backend Integration Agent (linux daemon).

#### Install from GitHub ####
#### Install from .deb package (recommended). ####

1. download ```netmicroscope-daemon-v0.9.8.deb```
2. run ```sudo dpkg -i netmicroscope-daemon-v0.9.8.deb```
3. edit .env file and rename to <br>
```
vim /usr/local/src/netmicroscope-daemon/env_template &&
mv /usr/local/src/netmicroscope-daemon/env_template /usr/local/src/netmicroscope-daemon/.env
```
4. run ```sudo nmd restart```

#### Manual installation from GitHub ####

```
sudo apt-get install python3-venv python3-dev -y
Expand All @@ -11,13 +22,13 @@ python3 -m pip install wheel
python3 -m pip install -r requirements.txt
```

#### Crontab Setup ####
#### Manual Crontab Setup ####

```
@reboot root cd /home/<user>/netmicroscope-daemon; sleep 30; ./nm.sh >/tmp/nm.sh.log 2>&1
```

where nm.sh should look like:
where <b>nm.sh</b> should look like:
```
#!/bin/bash
Expand Down
8 changes: 4 additions & 4 deletions appmonitor/appmonitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,10 @@ def influxdb_updater_thread(self):
',application=' + app +\
' value=' + str(insert[dev][app]['KbpsUp']) +\
' ' + str(insert[dev][app]['TsEnd']) + '000000000' + '\n'
data = data.encode()
req = urllib.request.Request(self.url, data, self.header)
with urllib.request.urlopen(req) as response:
self.printF('OK' if response.getcode()==204 else 'Unexpected:'+str(response.getcode()))
data = data.encode()
req = urllib.request.Request(self.url, data, self.header)
with urllib.request.urlopen(req) as response:
self.printF('OK' if response.getcode()==204 else 'Unexpected:'+str(response.getcode()))
except Exception as e:
self.printF("EXCEPTION: influxdb_updater_thread {0}".format(e))
self.influxdb_queue.task_done()
Expand Down
7 changes: 6 additions & 1 deletion nmd
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python
#!/usr/bin/env python3

import os, sys
import datetime
Expand All @@ -10,6 +10,11 @@ import signal
import logging
from appmonitor.appmonitor import AppMonitor

#TODO: move this to setup.py
__name__ = "netmicroscope-daemon",
__version__ = "0.9.8"
__author__ = "Guilherme Martins",

PROGNAME = 'appmonitor'
PATHCTRL = '/tmp/' #path to control files pid and lock
logpath = os.path.join(PATHCTRL, PROGNAME + ".log")
Expand Down
1 change: 1 addition & 0 deletions package/deb/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*.deb
1 change: 1 addition & 0 deletions package/deb/backup/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*.deb
16 changes: 16 additions & 0 deletions package/deb/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/bin/bash

mv *.deb backup/
version_pyc=$(cat ../../nmd | grep "__version__" | grep -Po '\d.\d.\d')
version_deb=$(cat netmicroscope-daemon/DEBIAN/control| grep "Version:" | grep -Po '\d.\d.\d')
echo "python version:" ${version_pyc}
echo "debian version:" ${version_deb}
cp ../../cron-nm netmicroscope-daemon/etc/cron.d/
cp ../../nmd netmicroscope-daemon/usr/local/src/netmicroscope-daemon/
cp ../../env_template netmicroscope-daemon/usr/local/src/netmicroscope-daemon/
cp ../../appmonitor.py netmicroscope-daemon/usr/local/src/netmicroscope-daemon/
cp -R ../../appmonitor/ netmicroscope-daemon/usr/local/src/netmicroscope-daemon/
cp -R ../../venv/ netmicroscope-daemon/usr/local/src/netmicroscope-daemon/
sed -i 's/'${version_deb}'/'${version_pyc}'/g' netmicroscope-daemon/DEBIAN/control
dpkg-deb --build netmicroscope-daemon
mv netmicroscope-daemon.deb netmicroscope-daemon-v${version_pyc}.deb
9 changes: 9 additions & 0 deletions package/deb/netmicroscope-daemon/DEBIAN/control
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
Package: netmicroscope-daemon
Version: 0.9.8
Section: custom
Priority: optional
Architecture: all
Essential: no
Installed-Size: 1024
Maintainer: ggmartins
Description: NetMicroscope Backend Integration Agent (linux daemon).
1 change: 1 addition & 0 deletions package/deb/netmicroscope-daemon/etc/cron.d/cron-nm
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
@reboot root cd /home/gmartins/; /sbin/ifconfig >/tmp/ifconfig.txt ; sleep 30; ./nm.sh >/tmp/nm.sh.log 2>&1
5 changes: 5 additions & 0 deletions package/deb/netmicroscope-daemon/usr/local/bin/nmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/bash

cd /usr/local/src/netmicroscope-daemon/
. venv/bin/activate
venv/bin/python3 nmd $@
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
nmd
appmonitor/
appmonitor.py
venv/
.env
env_template

0 comments on commit f810559

Please sign in to comment.