Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
strudel2_backend
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
hpc-team
strudel2_backend
Commits
4874ae35
Commit
4874ae35
authored
6 years ago
by
Chris Hines
Browse files
Options
Downloads
Patches
Plain Diff
fix a bug with session timeouts
parent
4a7e5cd7
No related branches found
No related tags found
No related merge requests found
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
runserver.py
+3
-3
3 additions, 3 deletions
runserver.py
tes/__init__.py
+8
-2
8 additions, 2 deletions
tes/__init__.py
tes/apiendpoints.py
+2
-0
2 additions, 0 deletions
tes/apiendpoints.py
tes/localtunnelstat/__init__.py
+8
-0
8 additions, 0 deletions
tes/localtunnelstat/__init__.py
with
21 additions
and
5 deletions
runserver.py
+
3
−
3
View file @
4874ae35
from
tes
import
app
#
import logging
import
logging
#logging.basicConfig(filename="tes.log",format="%(asctime)s %(levelname)s:%(process)s: %(message)s")
#
logger=logging.getLogger()
#
logger.setLevel(logging.DEBUG)
logger
=
logging
.
getLogger
()
logger
.
setLevel
(
logging
.
DEBUG
)
app
.
run
(
host
=
'
localhost
'
,
debug
=
True
,
port
=
5000
)
This diff is collapsed.
Click to expand it.
tes/__init__.py
+
8
−
2
View file @
4874ae35
...
...
@@ -8,7 +8,7 @@ app = Flask(__name__)
app
.
config
[
'
DEBUG
'
]
=
True
app
.
config
[
'
SECRET_KEY
'
]
=
'
asdasfdfj
'
import
datetime
app
.
config
[
'
PERMANENT_SESSION_LIFETIME
'
]
=
datetime
.
timedelta
(
seconds
=
6
00
)
app
.
config
[
'
PERMANENT_SESSION_LIFETIME
'
]
=
datetime
.
timedelta
(
seconds
=
12
00
)
app
.
config
[
'
SESSION_REFRESH_EACH_REQUEST
'
]
=
True
api
=
Api
(
app
)
sshsessions
=
{}
...
...
@@ -19,7 +19,12 @@ from . import apiendpoints
@app.after_request
def
after_cleanup_sessions
(
response
):
print
(
"
in after_cleanup_sessions
"
)
import
logging
logger
=
logging
.
getLogger
()
logger
.
debug
(
"
in after_cleanup_sessions
"
)
sshsessid
=
session
.
get
(
'
sshsessid
'
,
None
)
print
(
"
the sshsessid for this request was {}
"
.
format
(
sshsessid
))
# kvsessionextension.cleanup_sessions(app)
_ttl
=
app
.
config
[
'
PERMANENT_SESSION_LIFETIME
'
]
if
isinstance
(
_ttl
,
int
):
...
...
@@ -28,6 +33,7 @@ def after_cleanup_sessions(response):
ttl
=
_ttl
for
k
,
sshsess
in
list
(
sshsessions
.
items
()):
if
datetime
.
datetime
.
now
()
>
sshsess
.
last
+
ttl
:
print
(
"
session last seen at {} now {}
"
.
format
(
sshsess
.
last
,
datetime
.
datetime
.
now
()))
sshsess
.
kill
()
del
sshsessions
[
k
]
return
response
...
...
This diff is collapsed.
Click to expand it.
tes/apiendpoints.py
+
2
−
0
View file @
4874ae35
...
...
@@ -66,6 +66,7 @@ class StartAgent(Resource):
class
AddKey
(
Resource
):
def
post
(
self
):
session
.
permanent
=
True
from
.localtunnelstat
import
SSHSession
sshsess
=
SSHSession
.
get_sshsession
()
data
=
request
.
get_json
()
...
...
@@ -162,6 +163,7 @@ class Stat(Resource):
logger
.
info
(
'
/stat endpoint entered
'
)
params
=
get_conn_params
()
sshsess
=
SSHSession
.
get_sshsession
()
sshsess
.
refresh
()
logger
.
info
(
'
/stat endpoint, all parameters collected
'
)
try
:
res
=
Ssh
.
execute
(
sshsess
,
host
=
params
[
'
host
'
],
user
=
params
[
'
user
'
],
cmd
=
params
[
'
statcmd
'
])
...
...
This diff is collapsed.
Click to expand it.
tes/localtunnelstat/__init__.py
+
8
−
0
View file @
4874ae35
...
...
@@ -113,6 +113,10 @@ class SSHSession:
def
refresh
(
self
):
import
datetime
self
.
last
=
datetime
.
datetime
.
now
()
import
logging
logger
=
logging
.
getLogger
()
logger
.
debug
(
"
updated datetime to {} for {}
"
.
format
(
self
.
last
,
self
.
authtok
))
print
(
"
updated datetime to {} for {}
"
.
format
(
self
.
last
,
self
.
authtok
))
def
set_authtok
(
self
,
authtok
):
self
.
authtok
=
authtok
...
...
@@ -123,7 +127,11 @@ class SSHSession:
def
kill
(
self
):
import
os
import
signal
import
logging
logger
=
logging
.
getLogger
()
print
(
"
killing all processes associated with this sshsession
"
)
logger
.
debug
(
"
shuting down ssh session for {} last seen at {}
"
.
format
(
self
.
authtok
,
self
.
last
))
print
(
"
shuting down ssh session for {} last seen at {}
"
.
format
(
self
.
authtok
,
self
.
last
))
print
(
self
.
pids
)
for
pid
in
self
.
pids
:
try
:
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment