summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJan Fuchs <fuky@asu.cas.cz>2016-03-14 18:47:59 +0100
committerJoel Rosdahl <joel@rosdahl.net>2016-07-19 15:02:34 +0200
commit6de51e60215ef37768b6ff3dc732db714dd6830a (patch)
tree09e127ff2f7c9903d3b53fe27daf6374f57bea34
parentf9eab6efbfd277a020de3128ec3cf9ac5f0f34d4 (diff)
downloadminiircd-6de51e60215ef37768b6ff3dc732db714dd6830a.tar.gz
miniircd-6de51e60215ef37768b6ff3dc732db714dd6830a.zip
Code style fixup and simplified method make_pidfile()
-rwxr-xr-xminiircd59
1 files changed, 24 insertions, 35 deletions
diff --git a/miniircd b/miniircd
index 3458e97..176c1d7 100755
--- a/miniircd
+++ b/miniircd
@@ -20,6 +20,7 @@
#
# Joel Rosdahl <joel@rosdahl.net>
+import logging
import os
import re
import select
@@ -28,14 +29,13 @@ import string
import sys
import tempfile
import time
-import logging
-import subprocess
from datetime import datetime
-from optparse import OptionParser
from logging.handlers import RotatingFileHandler
+from optparse import OptionParser
VERSION = "1.1"
+
def create_directory(path):
if not os.path.isdir(path):
os.makedirs(path)
@@ -644,9 +644,9 @@ class Server(object):
self.chroot = options.chroot
self.setuid = options.setuid
self.statedir = options.statedir
- self.miniircd_log_file = options.miniircd_log_file
- self.miniircd_log_maxbytes = options.miniircd_log_maxsize * 1024 * 1024
- self.miniircd_log_count = options.miniircd_log_count
+ self.log_file = options.log_file
+ self.log_maxbytes = options.log_maxsize * 1024 * 1024
+ self.log_count = options.log_count
self.logger = None
if self.ssl_pem_file:
@@ -673,23 +673,6 @@ class Server(object):
create_directory(self.statedir)
def make_pidfile(self, filename):
- if (os.path.isfile(filename)):
- pid_fo = open(filename, "r")
- old_pid = pid_fo.readline().strip()
- pid_fo.close()
-
- old_pid_is_deprecated = False
- try:
- result = subprocess.check_output(["ps", "--pid", old_pid, "-o", "pid=,args="])
- if (result.find("miniircd") == -1):
- old_pid_is_deprecated = True
- except:
- old_pid_is_deprecated = True
-
- if old_pid_is_deprecated:
- self.print_debug("Remove deprecated pidfile '%s'" % filename)
- os.remove(filename)
-
try:
fd = os.open(filename, os.O_RDWR | os.O_CREAT | os.O_EXCL, 0644)
os.write(fd, "%i\n" % os.getpid())
@@ -818,7 +801,7 @@ class Server(object):
raise
def miniircd_log_init(self):
- if not self.miniircd_log_file:
+ if not self.log_file:
return
log_level = logging.INFO
@@ -827,8 +810,13 @@ class Server(object):
self.logger = logging.getLogger("miniircd")
- formatter = logging.Formatter("%(asctime)s - %(name)s[%(process)d] - %(levelname)s - %(message)s")
- fh = RotatingFileHandler(self.miniircd_log_file, maxBytes=self.miniircd_log_maxbytes, backupCount=self.miniircd_log_count)
+ formatter = logging.Formatter(
+ ("%(asctime)s - %(name)s[%(process)d] - "
+ "%(levelname)s - %(message)s"))
+ fh = RotatingFileHandler(
+ self.log_file,
+ maxBytes=self.log_maxbytes,
+ backupCount=self.log_count)
fh.setLevel(log_level)
fh.setFormatter(formatter)
@@ -906,21 +894,22 @@ def main(argv):
metavar="X",
help="listen on specific IP address X")
op.add_option(
- "--make-pidfile",
+ "--pidfile",
metavar="X",
help="make pidfile file X")
op.add_option(
- "--miniircd-log-file",
+ "--log-file",
metavar="X",
- help="store miniircd log in file X")
+ help="store log in file X")
op.add_option(
- "--miniircd-log-maxsize",
+ "--log-maxsize",
metavar="X", default=10, type="int",
- help="set maximum miniircd log file size to X MiB [default: %default MiB]")
+ help=("set maximum log file size to X MiB "
+ "[default: %default MiB]"))
op.add_option(
- "--miniircd-log-count",
+ "--log-count",
metavar="X", default=10, type="int",
- help="set count backup miniircd log file to X [default: %default]")
+ help="set count backup log file to X [default: %default]")
op.add_option(
"--logdir",
metavar="X",
@@ -1004,8 +993,8 @@ def main(argv):
server = Server(options)
if options.daemon:
server.daemonize()
- if options.make_pidfile:
- server.make_pidfile(options.make_pidfile)
+ if options.pidfile:
+ server.make_pidfile(options.pidfile)
try:
server.start()
except KeyboardInterrupt: