Skip to content

Commit

Permalink
HA on process kill
Browse files Browse the repository at this point in the history
  • Loading branch information
elg committed Jul 18, 2019
1 parent 3a19dfa commit c243a79
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 6 deletions.
4 changes: 2 additions & 2 deletions passhport/passhport
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ SCRIPT_LOGS_PATH = conf.get("Environment", "SCRIPT_LOGS_PATH")
# MISC Confgiruation
SCP_THROUGH_TARGET = conf.getboolean("MISC", "SCP_THROUGH_TARGET")
UNIQ_TARGETS_ID = conf.getboolean("MISC", "UNIQ_TARGETS_ID")

NODE_NAME = conf.get("MISC", "NODE_NAME")

def signal_handler(signal, frame):
"""Handle 'ctrl-c' from the users"""
Expand Down Expand Up @@ -127,7 +127,7 @@ def checkandconnect(indexed_target_list, choice, username, originalcmd,
isodate = datetime.now().isoformat().replace(":",""). \
replace("-","").split('.')[0]
pid = os.getpid()
filename = isodate + "-PID" + \
filename = NODE_NAME + "-" + isodate + "-PID" + \
str(pid) + "-" + targetname + "-" + \
login + "@" + target + "-" + username
filelog = pathlog + filename
Expand Down
2 changes: 2 additions & 0 deletions passhport/passhport.ini
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,5 @@ SCP_THROUGH_TARGET = False
UNIQ_TARGETS_ID = True
# Relaunch passhport once a session is over
KEEPCONNECT = True
# Node name when working in HA
NODE_NAME = passhport-node
12 changes: 8 additions & 4 deletions passhportd/app/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,11 +143,13 @@ def currentsshconnections():
@app.route("/connection/ssh/current/killbiglog")
def currecntsshconnectionskillbiglog():
"""Kill the actives sessions whith log files too big"""
# Request to check only the connections on this node
lentries = logentry.Logentry.query.filter(db.and_(
logentry.Logentry.endsessiondate == None,
logentry.Logentry.target != None,
logentry.Logentry.connectioncmd.like('%ssh%'),
logentry.Logentry.user != None)).all()
logentry.Logentry.user != None,
logentry.Logentry.logfilename.like(
config.NODE_NAME + '-%'))).all()

killedpid = ""
confmaxsize = int(config.MAXLOGSIZE)*1024*1024
Expand Down Expand Up @@ -179,8 +181,10 @@ def checkandterminatesshsession():
"""Check all the connections and close those without a process runing"""
isodate = datetime.now().isoformat().replace(":",""). \
replace("-","").split('.')[0]
lentries = logentry.Logentry.query.filter(
logentry.Logentry.endsessiondate == None).all()
lentries = logentry.Logentry.query.filter(db.and_(
logentry.Logentry.endsessiondate == None,
logentry.Logentry.logfilename.like(
config.NODE_NAME + '-%'))).all()

if not lentries:
return "No active connection."
Expand Down
1 change: 1 addition & 0 deletions passhportd/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,4 @@

""" MISC """
MAXLOGSIZE = conf.get("MISC", "MAXLOGSIZE")
NODE_NAME = conf.get("MISC", "NODE_NAME")
2 changes: 2 additions & 0 deletions passhportd/passhportd.ini
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,5 @@ OPEN_ACCESS_PATH = /home/passhport/passhwall.sh
[MISC]
# Maximum log file size in MB
MAXLOGSIZE = 5
# Node Name in case of HA
NODE_NAME = passhport-node

0 comments on commit c243a79

Please sign in to comment.