Thanks Clark!  I found the same thing.  I've added a few of options and a
dependency on the getopt library.  Take a look at this patch and let me
know if there's anything you'd like me to add / remove.

Cheers,

C.J.


On Mon, Feb 29, 2016 at 6:47 PM, Clark Boylan <[email protected]> wrote:

> On Mon, Feb 29, 2016, at 01:26 PM, C.J. Collier wrote:
> > Hey folks,
> >
> > I'm having a heck of a time getting gerritbot working.  It currently
> > exits
> > prematurely without any console output and returns 0 to the calling
> > process.  No entries in the logs.  Very frustrating.  Can I get some help
> > with this?
> >
>
> Looking at the source [0] it uses a default pid lock file path, if I had
> to guess the user running the process isn't able to write to that
> directory or it does not exist. You can specify an alternate path under
> ircbot.pid in the ini config file if I am reading that correctly.
>
> [0]
>
> https://git.openstack.org/cgit/openstack-infra/gerritbot/tree/gerritbot/bot.py#n344
>
> Hope this helps,
> Clark
>
diff --git a/gerritbot/bot.py b/gerritbot/bot.py
index e050ca5..bf9d112 100755
--- a/gerritbot/bot.py
+++ b/gerritbot/bot.py
@@ -47,6 +47,7 @@ openstack-dev:
       - master
 """
 
+import getopt
 import ConfigParser
 import daemon
 import irc.bot
@@ -59,6 +60,10 @@ import threading
 import time
 import yaml
 
+import paramiko
+
+paramiko.util.log_to_file('ssh.log') # sets up logging
+
 try:
     import daemon.pidlockfile
     pid_file_module = daemon.pidlockfile
@@ -78,6 +83,7 @@ irc.client.ServerConnection.buffer_class.errors = 'replace'
 class GerritBot(irc.bot.SingleServerIRCBot):
     def __init__(self, channels, nickname, password, server, port=6667,
                  force_ssl=False, server_password=None):
+        print("initializing GerritBot Object!")
         if force_ssl or port == 6697:
             factory = irc.connection.Factory(wrapper=ssl.wrap_socket)
             super(GerritBot, self).__init__([(server, port, server_password)],
@@ -123,6 +129,7 @@ class GerritBot(irc.bot.SingleServerIRCBot):
 class Gerrit(threading.Thread):
     def __init__(self, ircbot, channel_config, server,
                  username, port=29418, keyfile=None):
+        print("initializing Gerrit Object!")
         super(Gerrit, self).__init__()
         self.ircbot = ircbot
         self.channel_config = channel_config
@@ -273,6 +280,7 @@ class Gerrit(threading.Thread):
 
 class ChannelConfig(object):
     def __init__(self, data):
+        print("initializing ChannelConfig Object!")
         self.data = data
         keys = data.keys()
         for key in keys:
@@ -298,16 +306,21 @@ class ChannelConfig(object):
 
 
 def _main(config):
+    print("running _main!")
     setup_logging(config)
 
+    print("Getting ircbot config!")
     fp = config.get('ircbot', 'channel_config')
     if fp:
+        print("ircbot config gotten!")
+        print("expanding os path!")
         fp = os.path.expanduser(fp)
         if not os.path.exists(fp):
             raise Exception("Unable to read layout config file at %s" % fp)
     else:
         raise Exception("Channel Config must be specified in config file.")
 
+    print("reading channel config!")
     try:
         channel_config = ChannelConfig(yaml.load(open(fp)))
     except Exception:
@@ -331,15 +344,51 @@ def _main(config):
     g.start()
     bot.start()
 
+def ensure_dir(f):
+    d = os.path.dirname(f)
+    if not os.path.exists(d):
+        os.makedirs(d)
+
+def usage():
+    print("Usage: " + sys.argv[0] + " [options]\n"
+          + "Options:\n"
+          + "-h --help           Show help\n"
+          + "-f                  Run in foreground\n"
+          + "-c --config <file>  Read configuration from <file>\n"
+          + "                    (default: /etc/gerritbot/gerritbot.conf)" )
+    sys.exit( 0 );
 
 def main():
-    if len(sys.argv) != 2:
-        print("Usage: %s CONFIGFILE" % sys.argv[0])
-        sys.exit(1)
+    print("Running main function!")
 
+    try:
+        opts, args = getopt.getopt(sys.argv[1:], "vhc:f", ["verbose","help","config"])
+    except getopt.GetoptError as err:
+        # print help information and exit:
+        print str(err) # will print something like "option -a not recognized"
+        usage()
+        sys.exit(2)
+
+    verbose = False
+    foreground = False
+    config_file = '/etc/gerritbot/gerritbot.conf'
+    
+    for o, a in opts:
+        if o in( "-v", "--verbose" ):
+            verbose = True
+        elif o in( "-h", "--help" ):
+            usage()
+        elif o in( "-c", "--config" ):
+            config_file = a
+        elif o == "-f":
+            foreground = True
+
+            
+    print("initializing config parser!")
     config = ConfigParser.ConfigParser({'force_ssl': 'false',
                                         'server_password': None})
-    config.read(sys.argv[1])
+    print("parsing config file " + config_file)
+    config.read(config_file)
 
     pid_path = ""
     if config.has_option('ircbot', 'pid'):
@@ -347,11 +396,17 @@ def main():
     else:
         pid_path = "/var/run/gerritbot/gerritbot.pid"
 
+    print("pid_path: " + pid_path + "\n");
+    ensure_dir(pid_path)
     pid = pid_file_module.TimeoutPIDLockFile(pid_path, 10)
-    with daemon.DaemonContext(pidfile=pid):
+    if foreground == False:
+        print("starting daemon!")
+        with daemon.DaemonContext(pidfile=pid):
+            _main(config)
+    else:
+        print("starting in foreground!!")
         _main(config)
 
-
 def setup_logging(config):
     if config.has_option('ircbot', 'log_config'):
         log_config = config.get('ircbot', 'log_config')
@@ -364,4 +419,5 @@ def setup_logging(config):
 
 
 if __name__ == "__main__":
+    print("Running main!")
     main()
diff --git a/requirements.txt b/requirements.txt
index 9b11d5b..e72e261 100644
--- a/requirements.txt
+++ b/requirements.txt
@@ -4,6 +4,7 @@ gerritlib
 # irc depends on jaraco modules. jaraco.functools 1.6 attempts to import
 # backports which do not exist. This appears to be a dependency issue
 # upstream. Avoid this by forcing the use of older jaraco.functools.
+pycrypto>=2.6
 jaraco.functools<1.6
 jaraco.itertools<1.6
 jaraco.collections<1.2
_______________________________________________
OpenStack-Infra mailing list
[email protected]
http://lists.openstack.org/cgi-bin/mailman/listinfo/openstack-infra

Reply via email to