Changeset 307


Ignore:
Timestamp:
04/17/07 17:02:55 (17 years ago)
Author:
bastiaans
Message:

jobmond/jobmond.py:

  • added: pidfile support (thanks Michael Jeanson)
  • added: usage (thanks Michael Jeanson)
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/jobmond/jobmond.py

    r282 r307  
    2424import sys, getopt, ConfigParser
    2525
     26def usage():
     27
     28        print
     29        print 'usage: jobmond [options]'
     30        print 'options:'
     31        print '      --config, -c      configuration file'
     32        print '      --pidfile, -p     pid file'
     33        print '      --help, -h        help'
     34        print
     35
     36
    2637def processArgs( args ):
    2738
     
    2940        LONG_L = 'config='
    3041
    31         config_filename = None
     42        global PIDFILE
     43        PIDFILE = None
     44        config_filename = '/etc/jobmond.conf'
    3245
    3346        try:
     
    3548                opts, args = getopt.getopt( args, SHORT_L, LONG_L )
    3649
    37         except getopt.error, detail:
     50        except getopt.GetoptError, detail:
    3851
    3952                print detail
     53                usage()
    4054                sys.exit(1)
    4155
     
    4660                        config_filename = value
    4761
    48         if not config_filename:
    49 
    50                 config_filename = '/etc/jobmond.conf'
     62                if opt in [ '--pidfile', '-p' ]:
     63
     64                        PIDFILE = value
     65               
     66                if opt in [ '--help', '-h' ]:
     67 
     68                        usage()
     69                        sys.exit(1)
    5170
    5271        return loadConfig( config_filename )
     
    571590                        sys.exit(0)  # end parent
    572591
     592                write_pidfile()
     593
    573594                # Go to the root directory and set the umask
    574595                #
     
    606627                        sys.stderr.write( msg + '\n' )
    607628
     629def write_pidfile():
     630
     631        # Write pidfile if PIDFILE exists
     632        if PIDFILE:
     633                pid = os.getpid()
     634
     635                pidfile = open(PIDFILE, 'w')
     636                pidfile.write(str(pid))
     637                pidfile.close()
     638
    608639def main():
    609640        """Application start"""
Note: See TracChangeset for help on using the changeset viewer.