1. INTRODUCTION

lockserver is a simple lock server that enables the coordination of several clients
  to accede to a single resource in a network that has a maximum number of simultaneous
  sessions.
  
The origin of this server is the access to a Dell Equallogic SAN. Such SAN has a limit
  of 7 (or 8) SSH concurrent sessions, but we had more clients that were trying to ssh
  this SAN. A limit was needed, and so this lockserver was created.
  
Clients are modified to use the Lock object from the lockcli module and connect to the
  server that is located in a URL in the network. The server is configured to allow a
  number of simultaneous clients.
  
The server is created in a general way so multiple locks can be created although it is
  disabled the remote creation of locks. The server is able to create a lock at startup,
  and the parameters of such lock are stated in the .conf file.
  
* There is a start-up service created for debian, but it is not supposed to work in Red
  Hat based distros.

2. JOB PENDING

- Include some kind of authentication for clients (i.e. a secret key)

- Include a script to start as a service in other than debian-based distros
  
3. EXAMPLE

  3.1 SERVER: lockserver.my.url.com
  
  Will run lockserver with the "DefaultLock" lock created on startup, and will allow up
  to 6 concurrent locks. If a lock query is not used for more than 1200 seconds, it will
  expire.
    
  3.1.1 FILE /etc/lockserver.conf

  [general]
  # set to localhost if you do not want access from outside this server
  SERVER=0.0.0.0
  # the port where it will listen
  PORT=9090
  # the log file
  LOG_FILE=/var/log/lockserver.log
  # the log level (superdebug, debug, info, error or warning)
  LOGLEVEL=debug
  # the period for evaluating the queue
  LIFECYCLE_PERIOD=1
  # the parameters of the lock that will be created on startup
  DEFAULT_LOCK=DefaultLock
  DEFAULT_LOCK_SIZE=6
  DEFAULT_LOCK_GRACE_TIME=10
  DEFAULT_LOCK_EXPIRATION_TIME=1200
  DEFAULT_LOCK_MAX_LOCK_TIME=1200

  3.2 CLIENTS (e.g. node1.my.url.com, node2.my.url.com, node3.my.url.com)

  Will run cliapp to coordinate
  
  3.2.1 APPLICATION cliapp

  /usr/bin/myapp.py
  #!/usr/bin/python
  import lockcli
  import socket
  l = lockcli.Lock("http://lockserver.my.url.com:9090/RPC2", "DefaultLock")
  if l.lock_query("i queried a lock from %s" % socket.gethostname()):
      print "lock queried"
      if l.lock_wait():
          print "lock acquired"
          time.sleep(30) # this is the hard job
          l.lock_release()
          print "lock released"
      else:
          print "could not get lock"
  else:
      print "could not query for lock"
            
4. LICENSE

# The MIT License (MIT)
#
# Copyright (c) 2014 Carlos de Alfonso (caralla@upv.es)
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.