Skip to main content

Simple lock server and client api for distributed coordination using a simple centralized python lock server

Project description

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.

5. CHANGE LOG

2014-12-16 (v.0.36)
Bug correction in install for pypi.

2014-12-16 (v.0.35)
Added web browsing support. Using a web browser we can get statistics of usage
and the current state of the locks (locks locked and the queue).

2014-12-11 (v.0.30)
Initial public version, submited to pypi

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Filename, size & hash SHA256 hash help File type Python version Upload date
lockserver-0.36.tar.gz (7.6 kB) Copy SHA256 hash SHA256 Source None

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN SignalFx SignalFx Supporter DigiCert DigiCert EV certificate StatusPage StatusPage Status page