From 49f638ddeef6c65c6c64bfeb1cec7b80f842de40 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C4=B0smail=20Ba=C5=9Faran?= Date: Mon, 8 Feb 2016 19:03:38 +0200 Subject: [PATCH] ahenk deamon --- opt/ahenk/ahenkd.py | 44 +++++++++++++++++++++++ opt/ahenk/base/plugin/__init__.py | 0 opt/ahenk/helper/ConfigurationHelper.py | 46 ------------------------- opt/ahenk/helper/__init__.py | 0 4 files changed, 44 insertions(+), 46 deletions(-) create mode 100644 opt/ahenk/base/plugin/__init__.py delete mode 100644 opt/ahenk/helper/ConfigurationHelper.py create mode 100644 opt/ahenk/helper/__init__.py diff --git a/opt/ahenk/ahenkd.py b/opt/ahenk/ahenkd.py index bd72a3c..d3ace1d 100644 --- a/opt/ahenk/ahenkd.py +++ b/opt/ahenk/ahenkd.py @@ -2,4 +2,48 @@ # -*- coding: utf-8 -*- # Author: İsmail BAŞARAN +from base.config.ConfigManager import ConfigManager +from base.deamon.BaseDeamon import BaseDeamon +from base.logging.AhenkLogger import Logger +import sys,logging + +class AhenkDeamon(BaseDeamon): + """docstring for AhenkDeamon""" + def __init__(self, arg): + super(AhenkDeamon, self).__init__() + self.arg = arg + +if __name__ == '__main__': + + configFilePath='/etc/ahenk/ahenk.conf' + configfileFolderPath='/etc/ahenk/config.d/' + pidfilePath='/var/run/ahenk.pid' + + configManager = ConfigManager(configFilePath,configfileFolderPath) + config = configManager.read() + + logger = Logger('/tmp/ahenk.log',logging.DEBUG) + logger.info("obaraaa") + +""" + deamon = AhenkDeamon(pidfilePath) + + if len(sys.argv) == 2: + if sys.argv[1] == "start": + deamon.start() + elif sys.argv[1] == 'stop': + deamon.stop() + elif sys.argv[1] == 'restart': + deamon.restart() + elif sys.argv[1] == 'status': + # print status + pass + else: + print 'Unknown command. Usage : %s start|stop|restart|status' % sys.argv[0] + sys.exit(2) + sys.exit(0) + else: + print 'Usage : %s start|stop|restart|status' % sys.argv[0] + sys.exit(2) +""" \ No newline at end of file diff --git a/opt/ahenk/base/plugin/__init__.py b/opt/ahenk/base/plugin/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/opt/ahenk/helper/ConfigurationHelper.py b/opt/ahenk/helper/ConfigurationHelper.py deleted file mode 100644 index bc2bf2f..0000000 --- a/opt/ahenk/helper/ConfigurationHelper.py +++ /dev/null @@ -1,46 +0,0 @@ -#!/usr/bin/python -# -*- coding: utf-8 -*- -# Author: İsmail BAŞARAN - -import ConfigParser,os -from os import listdir -from os.path import isfile, join - -class ConfigurationHelper(object): - """ - This class written for configuration file management of ahenk and ahenk plugins - Sample ahenk configuration file path /etc/ahenk/ahenk.conf and sample ahenk plugins configuration folder path /etc/ahenk/config.d/ - Takes two argument, - both of them are optional - one of the is a configuration file path the other one is configuration files folder path - """ - def __init__(self, configurationFilePath=None, configurationFolderPath=None): - super(ConfigurationHelper, self).__init__() - self.configurationFilePath = configurationFilePath - self.configurationFolderPath = configurationFolderPath - - - def read(self): - configFiles = [] - - # Check if given ahenk configuration file exists - # If file exists add it to configFiles array. - if self.configurationFilePath: - if os.path.exists(self.configurationFilePath): - configFiles.append(self.configurationFilePath) - - if self.configurationFolderPath and os.path.exists(self.configurationFolderPath): - files = [f for f in listdir(self.configurationFolderPath) if isfile(join(self.configurationFolderPath, f))] - for f in files: - - configFiles.append(f) - - parser = SafeConfigParser() - configValues = parser.read(configFiles) - - return configValues - - - - - - - diff --git a/opt/ahenk/helper/__init__.py b/opt/ahenk/helper/__init__.py new file mode 100644 index 0000000..e69de29