From 3ccb1d1d05faeae8788057f20ee6bec3ad4d96db Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C4=B0smail=20Ba=C5=9Faran?= Date: Mon, 1 Feb 2016 17:00:34 +0200 Subject: [PATCH] ahenk service --- debian/postinst | 29 +++++++++++++++ etc/init.d/ahenk | 45 ++++++++++++++++++++++++ lib/systemd/system/ahenk.service | 12 +++++++ opt/ahenk/ahenkd.py | 0 opt/ahenk/api/service/ps_util.py | 7 ++++ opt/ahenk/base/plugin/AbstractPlugin.py | 34 ++++++++++++++++++ opt/ahenk/plugins/plugin1/main.py | 8 +++++ opt/ahenk/plugins/plugin1/main.pyc | Bin 0 -> 391 bytes opt/ahenk/plugins/plugin2/main.py | 6 ++++ opt/ahenk/plugins/plugin2/main.pyc | Bin 0 -> 392 bytes 10 files changed, 141 insertions(+) create mode 100644 debian/postinst create mode 100644 etc/init.d/ahenk create mode 100644 lib/systemd/system/ahenk.service create mode 100644 opt/ahenk/ahenkd.py create mode 100644 opt/ahenk/api/service/ps_util.py create mode 100644 opt/ahenk/base/plugin/AbstractPlugin.py create mode 100644 opt/ahenk/plugins/plugin1/main.py create mode 100644 opt/ahenk/plugins/plugin1/main.pyc create mode 100644 opt/ahenk/plugins/plugin2/main.py create mode 100644 opt/ahenk/plugins/plugin2/main.pyc diff --git a/debian/postinst b/debian/postinst new file mode 100644 index 0000000..2cedb78 --- /dev/null +++ b/debian/postinst @@ -0,0 +1,29 @@ +#!/bin/sh +# postinst script for ahenk +# +# see: dh_installdeb(1) + +set -e + + +case "$1" in + configure) + + systemctl --system daemon-reload + systemctl enable ahenk.service + + update-rc.d ahenk defaults + /etc/init.d/ahenk start + + ;; + + abort-upgrade|abort-remove|abort-deconfigure) + ;; + + *) + echo "postinst called with unknown argument \`$1'" >&2 + exit 1 + ;; +esac + +exit 0 diff --git a/etc/init.d/ahenk b/etc/init.d/ahenk new file mode 100644 index 0000000..15d1417 --- /dev/null +++ b/etc/init.d/ahenk @@ -0,0 +1,45 @@ +#! /bin/bash +### BEGIN INIT INFO +# Provides: ahenk +# Required-Start: $remote_fs $syslog $network +# Required-Stop: $remote_fs $syslog $network +# Default-Start: 2 3 4 5 +# Default-Stop: 0 1 6 +# Short-Description: Manages ahenk service. +# Description: Debian init script for the ahenk executables +# scheduler +### END INIT INFO +# +# Author: S Suleyman Arslan +# + +# Activate the python virtual environment +# . /path_to_virtualenv/activate +case "$1" in + start) + echo "Starting server" + # Start the daemon + #python $AHENKDPATH start + systemctl start ahenk.service + ;; + stop) + echo "Stopping server" + systemctl stop ahenk.service + ;; + restart) + echo "Restarting server" + systemctl restart ahenk.service + ;; + status) + echo "Server Status" + # Status of the daemon + systemctl status ahenk.service + ;; + *) + # Refuse to do other stuff + echo "Usage: /etc/init.d/ahenk.sh {start|stop|restart|status}" + exit 1 + ;; +esac + +exit 0 \ No newline at end of file diff --git a/lib/systemd/system/ahenk.service b/lib/systemd/system/ahenk.service new file mode 100644 index 0000000..4efe333 --- /dev/null +++ b/lib/systemd/system/ahenk.service @@ -0,0 +1,12 @@ +[Unit] +Description=Starts Ahenk at system startup +After=network.target + +[Service] +Type=forking +ExecStart=python "/opt/ahenk/ahenkd.py start" +ExecStop=python "/opt/ahenk/ahenkd.py stop" +PIDFile=/var/run/ahenkd.pid + +[Install] +WantedBy=multi-user.target \ No newline at end of file diff --git a/opt/ahenk/ahenkd.py b/opt/ahenk/ahenkd.py new file mode 100644 index 0000000..e69de29 diff --git a/opt/ahenk/api/service/ps_util.py b/opt/ahenk/api/service/ps_util.py new file mode 100644 index 0000000..2f25859 --- /dev/null +++ b/opt/ahenk/api/service/ps_util.py @@ -0,0 +1,7 @@ +#!/usr/bin/python +# -*- coding: utf-8 -*- +# Author: İsmail BAŞARAN +import psutil + +if __name__ == '__main__': + diff --git a/opt/ahenk/base/plugin/AbstractPlugin.py b/opt/ahenk/base/plugin/AbstractPlugin.py new file mode 100644 index 0000000..526a676 --- /dev/null +++ b/opt/ahenk/base/plugin/AbstractPlugin.py @@ -0,0 +1,34 @@ +#!/usr/bin/python +# -*- coding: utf-8 -*- +# Author: İsmail BAŞARAN +import imp,os +""" + class AbstractPlugin(object): + This is base class for plugins + def __init__(self, arg): + super(AbstrackPlugin, self).__init__() + self.arg = arg +""" +pluginFolder = '/home/ismail/devzone/workspace/LiderAhenk/ahenk/opt/ahenk/plugins' +mainModule = 'main' + +def getPlugins(): + plugins = [] + possibleplugins = os.listdir(pluginFolder) + for i in possibleplugins: + location = os.path.join(pluginFolder, i) + if not os.path.isdir(location) or not mainModule + ".py" in os.listdir(location): + continue + info = imp.find_module(mainModule, [location]) + plugins.append({"name": i, "info": info}) + return plugins + +def loadPlugin(plugin): + return imp.load_module(mainModule, *plugin["info"]) + + +if __name__ == '__main__': + for i in getPlugins(): + print("Loading plugin " + i["name"]) + plugin = loadPlugin(i) + plugin.run("tabisi") diff --git a/opt/ahenk/plugins/plugin1/main.py b/opt/ahenk/plugins/plugin1/main.py new file mode 100644 index 0000000..d01e893 --- /dev/null +++ b/opt/ahenk/plugins/plugin1/main.py @@ -0,0 +1,8 @@ +#!/usr/bin/python +# -*- coding: utf-8 -*- +# Author: İsmail BAŞARAN + + + +def run(val): + print "oo yeah plugin1 " + str(val) diff --git a/opt/ahenk/plugins/plugin1/main.pyc b/opt/ahenk/plugins/plugin1/main.pyc new file mode 100644 index 0000000000000000000000000000000000000000..fe32482136b349cbf0bf38fd89bdc1f9bf212a33 GIT binary patch literal 391 zcmcIfy9&ZE6uq^BA`}D%*W%Pc4DKR|gAP(q!NDyw!Irj3Y1&G~P5;M_^9Q_13;hBE z=j1+e?>Vu*&Tu;WTmop1h4&hv93%$t2DoBi!P)C!CD45h8?i;GF%q^5fG5Dqg2`@= zW6f({jj$`FTXPz^SyJ92v2Z;-U+4v@$h)MXiH9{Xq>dPoP^O$jDy30E7_S~uaB`P< ztTGyKa)=nuHz5}>p@wBvv{56aNGnNjgP3Qv5zR}{*V_6!VEM+tNhh89KP?PUX_-n^ KCVXXlXd6FHvs*v_ literal 0 HcmV?d00001 diff --git a/opt/ahenk/plugins/plugin2/main.py b/opt/ahenk/plugins/plugin2/main.py new file mode 100644 index 0000000..0465cf4 --- /dev/null +++ b/opt/ahenk/plugins/plugin2/main.py @@ -0,0 +1,6 @@ +#!/usr/bin/python +# -*- coding: utf-8 -*- +# Author: İsmail BAŞARAN + +def run(val): + print "oo yeah plugin2 " + str(val) diff --git a/opt/ahenk/plugins/plugin2/main.pyc b/opt/ahenk/plugins/plugin2/main.pyc new file mode 100644 index 0000000000000000000000000000000000000000..72d90e83df0b1f192b15f2bbbb2101356017ae99 GIT binary patch literal 392 zcmcIfy9&ZE6uq?wB6JW1*Nz>;fU}6=po0`taBvGvu%&HMnzmAL)Bo|~`~h#$LchSk zIk~Ugb7Fs;;biu?1kfG}?=?a>NDSZ&aK*rav)98)p!*s&VvA5?By1M|Pk@&N)7>7Q zHPgNtVOL7G<}`G(q`XC9;kuq)Q0NV+$h)MXiH9{Xq>dPoP^O$jDy30E7_S~uaB`P< ztTGyKa)=nuHz5}>p@wBvv{9p_NUKS3gP3Qv5zR}{*V_6&VEM+tNhh89KP?PUX_-n^ KCVXXlXd6Fnc3V;a literal 0 HcmV?d00001