From 9424789f6989c174f2b15ad2b1d7f010d2024f8c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ram=C3=B3n=20M=2E=20G=C3=B3mez?= Date: Tue, 30 Jun 2020 14:55:35 +0200 Subject: [PATCH] #940: Adapt code to run the Linux daemon. --- src/opengnsys/linux/__init__.py | 5 ++--- src/opengnsys/linux/daemon.py | 14 ++++++-------- src/opengnsys/linux/log.py | 12 +++++------- 3 files changed, 13 insertions(+), 18 deletions(-) diff --git a/src/opengnsys/linux/__init__.py b/src/opengnsys/linux/__init__.py index 3a98c78..97ac9be 100644 --- a/src/opengnsys/linux/__init__.py +++ b/src/opengnsys/linux/__init__.py @@ -26,7 +26,6 @@ # OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -''' +""" @author: Adolfo Gómez, dkmaster at dkmon dot com -''' -from __future__ import unicode_literals +""" diff --git a/src/opengnsys/linux/daemon.py b/src/opengnsys/linux/daemon.py index 3753808..a2e8960 100644 --- a/src/opengnsys/linux/daemon.py +++ b/src/opengnsys/linux/daemon.py @@ -25,18 +25,16 @@ # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, # OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -''' +""" @author: : http://www.jejik.com/authors/sander_marechal/ @see: : http://www.jejik.com/articles/2007/02/a_simple_unix_linux_daemon_in_python/ -''' +""" -from __future__ import unicode_literals -import sys -import os -import time import atexit +import os +import sys +import time from opengnsys.log import logger - from signal import SIGTERM @@ -89,7 +87,7 @@ class Daemon: sys.stderr.flush() si = open(self.stdin, 'r') so = open(self.stdout, 'a+') - se = open(self.stderr, 'a+', 0) + se = open(self.stderr, 'a+') os.dup2(si.fileno(), sys.stdin.fileno()) os.dup2(so.fileno(), sys.stdout.fileno()) os.dup2(se.fileno(), sys.stderr.fileno()) diff --git a/src/opengnsys/linux/log.py b/src/opengnsys/linux/log.py index dc54e19..396a2db 100644 --- a/src/opengnsys/linux/log.py +++ b/src/opengnsys/linux/log.py @@ -26,18 +26,16 @@ # OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -''' +""" @author: Adolfo Gómez, dkmaster at dkmon dot com -''' -from __future__ import unicode_literals +""" import logging import os import tempfile -import six -# Valid logging levels, from UDS Broker (uds.core.utils.log) -OTHER, DEBUG, INFO, WARN, ERROR, FATAL = (10000 * (x + 1) for x in six.moves.xrange(6)) # @UndefinedVariable +# Logging levels +OTHER, DEBUG, INFO, WARN, ERROR, FATAL = (10000 * (x + 1) for x in range(6)) class LocalLogger(object): @@ -46,7 +44,7 @@ class LocalLogger(object): # service wil get c:\windows\temp, while user will get c:\users\XXX\temp # Try to open logger at /var/log path # If it fails (access denied normally), will try to open one at user's home folder, and if - # agaim it fails, open it at the tmpPath + # again it fails, open it at the tmpPath for logDir in ('/var/log', os.path.expanduser('~'), tempfile.gettempdir()): try: