summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSylvain Th?nault <sylvain.thenault@logilab.fr>2011-09-08 18:14:56 +0200
committerSylvain Th?nault <sylvain.thenault@logilab.fr>2011-09-08 18:14:56 +0200
commit1330b4a098a289fe5e9719637aa68d0cb2a2d281 (patch)
tree2942d0c85c93421af18577309feb32fc73cd4d3f
parent06b2f1360a6edf985d95f6041b6ee16455d73293 (diff)
parentb08685292622e990dea201544e157d2c112e1820 (diff)
downloadlogilab-common-1330b4a098a289fe5e9719637aa68d0cb2a2d281.tar.gz
backport stable
-rw-r--r--ChangeLog3
-rwxr-xr-xbin/pytest2
-rw-r--r--daemon.py104
3 files changed, 5 insertions, 104 deletions
diff --git a/ChangeLog b/ChangeLog
index d42fbce..006d410 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,6 +1,9 @@
ChangeLog for logilab.common
============================
+-- <default>
+ * daemon: remove unused(?) DaemonMixin class
+
2011-09-08 -- 0.56.2
* daemon: call initgroups/setgid before setuid (closes #74173)
diff --git a/bin/pytest b/bin/pytest
index 852bdd1..0ad0ecb 100755
--- a/bin/pytest
+++ b/bin/pytest
@@ -1,4 +1,4 @@
-#!/usr/bin/python -u
+#!/usr/bin/python -uWdefault
from logilab.common.pytest import run
run()
diff --git a/daemon.py b/daemon.py
index 2eedca5..6815bc9 100644
--- a/daemon.py
+++ b/daemon.py
@@ -15,7 +15,7 @@
#
# You should have received a copy of the GNU Lesser General Public License along
# with logilab-common. If not, see <http://www.gnu.org/licenses/>.
-"""A daemonize function (for Unices) and daemon mix-in class"""
+"""A daemonize function (for Unices)"""
__docformat__ = "restructuredtext en"
@@ -96,105 +96,3 @@ def daemonize(pidfile=None, uid=None, umask=077):
if uid:
setugid(uid)
return None
-
-
-class DaemonMixIn:
- """Mixin to make a daemon from watchers/queriers.
- """
-
- def __init__(self, configmod) :
- self.delay = configmod.DELAY
- self.name = str(self.__class__).split('.')[-1]
- self._pid_file = os.path.join('/tmp', '%s.pid'%self.name)
- if os.path.exists(self._pid_file):
- raise Exception('''Another instance of %s must be running.
-If it i not the case, remove the file %s''' % (self.name, self._pid_file))
- self._alive = 1
- self._sleeping = 0
- self.config = configmod
-
- def _daemonize(self):
- if not self.config.NODETACH:
- if daemonize(self._pid_file) is None:
- # put signal handler
- signal.signal(signal.SIGTERM, self.signal_handler)
- signal.signal(signal.SIGHUP, self.signal_handler)
- else:
- return -1
-
- def run(self):
- """ optionally go in daemon mode and
- do what concrete class has to do and pauses for delay between runs
- If self.delay is negative, do a pause before starting
- """
- if self._daemonize() == -1:
- return
- if self.delay < 0:
- self.delay = -self.delay
- time.sleep(self.delay)
- while True:
- try:
- self._run()
- except Exception, ex:
- # display for info, sleep, and hope the problem will be solved
- # later.
- self.config.exception('Internal error: %s', ex)
- if not self._alive:
- break
- try:
- self._sleeping = 1
- time.sleep(self.delay)
- self._sleeping = 0
- except SystemExit:
- break
- self.config.info('%s instance exited', self.name)
- # remove pid file
- os.remove(self._pid_file)
-
- def signal_handler(self, sig_num, stack_frame):
- if sig_num == signal.SIGTERM:
- if self._sleeping:
- # we are sleeping so we can exit without fear
- self.config.debug('exit on SIGTERM')
- sys.exit(0)
- else:
- self.config.debug('exit on SIGTERM (on next turn)')
- self._alive = 0
- elif sig_num == signal.SIGHUP:
- self.config.info('reloading configuration on SIGHUP')
- reload(self.config)
-
- def _run(self):
- """should be overridden in the mixed class"""
- raise NotImplementedError()
-
-
-import logging
-from logilab.common.logging_ext import set_log_methods
-set_log_methods(DaemonMixIn, logging.getLogger('lgc.daemon'))
-
-## command line utilities ######################################################
-
-L_OPTIONS = ["help", "log=", "delay=", 'no-detach']
-S_OPTIONS = 'hl:d:n'
-
-def print_help(modconfig):
- print """ --help or -h
- displays this message
- --log <log_level>
- log treshold (7 record everything, 0 record only emergency.)
- Defaults to %s
- --delay <delay>
- the number of seconds between two runs.
- Defaults to %s""" % (modconfig.LOG_TRESHOLD, modconfig.DELAY)
-
-def handle_option(modconfig, opt_name, opt_value, help_meth):
- if opt_name in ('-h', '--help'):
- help_meth()
- sys.exit(0)
- elif opt_name in ('-l', '--log'):
- modconfig.LOG_TRESHOLD = int(opt_value)
- elif opt_name in ('-d', '--delay'):
- modconfig.DELAY = int(opt_value)
- elif opt_name in ('-n', '--no-detach'):
- modconfig.NODETACH = 1