Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
R
Rosetta
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
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
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
ExaCT
Rosetta
Commits
a8cd3912
Commit
a8cd3912
authored
3 years ago
by
Stefano Alberto Russo
Browse files
Options
Downloads
Patches
Plain Diff
Fixed bugs in configuring the proxy.
parent
9c376ec8
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
services/webapp/code/rosetta/core_app/utils.py
+77
-74
77 additions, 74 deletions
services/webapp/code/rosetta/core_app/utils.py
with
77 additions
and
74 deletions
services/webapp/code/rosetta/core_app/utils.py
+
77
−
74
View file @
a8cd3912
...
@@ -559,10 +559,49 @@ def setup_tunnel_and_proxy(task):
...
@@ -559,10 +559,49 @@ def setup_tunnel_and_proxy(task):
task
.
tcp_tunnel_port
=
tcp_tunnel_port
task
.
tcp_tunnel_port
=
tcp_tunnel_port
task
.
save
()
task
.
save
()
# Setup the proxy now.
# Some info about the various SSL switches: https://serverfault.com/questions/577616/using-https-between-apache-loadbalancer-and-backends
# Esnure conf directory exists
# Check if the tunnel is (still) active, if not create it
logger
.
debug
(
'
Checking if task
"
{}
"
has a running tunnel
'
.
format
(
task
))
out
=
os_shell
(
'
ps -ef | grep
"
:{}:{}:{}
"
| grep -v grep
'
.
format
(
task
.
tcp_tunnel_port
,
task
.
interface_ip
,
task
.
interface_port
),
capture
=
True
)
if
out
.
exit_code
==
0
:
logger
.
debug
(
'
Task
"
{}
"
has a running tunnel, using it
'
.
format
(
task
))
else
:
logger
.
debug
(
'
Task
"
{}
"
has no running tunnel, creating it
'
.
format
(
task
))
# Get user keys
user_keys
=
KeyPair
.
objects
.
get
(
user
=
task
.
user
,
default
=
True
)
# Tunnel command
if
task
.
computing
.
type
==
'
remotehop
'
:
# Get computing params
first_host
=
task
.
computing
.
conf
.
get
(
'
first_host
'
)
first_user
=
task
.
computing
.
conf
.
get
(
'
first_user
'
)
#second_host = task.computing.conf.get('second_host')
#second_user = task.computing.conf.get('second_user')
#setup_command = task.computing.conf.get('setup_command')
#base_port = task.computing.conf.get('base_port')
tunnel_command
=
'
ssh -4 -i {} -o StrictHostKeyChecking=no -nNT -L 0.0.0.0:{}:{}:{} {}@{} &
'
.
format
(
user_keys
.
private_key_file
,
task
.
tcp_tunnel_port
,
task
.
interface_ip
,
task
.
interface_port
,
first_user
,
first_host
)
else
:
tunnel_command
=
'
ssh -4 -o StrictHostKeyChecking=no -nNT -L 0.0.0.0:{}:{}:{} localhost &
'
.
format
(
task
.
tcp_tunnel_port
,
task
.
interface_ip
,
task
.
interface_port
)
background_tunnel_command
=
'
nohup {} >/dev/null 2>&1 &
'
.
format
(
tunnel_command
)
# Log
logger
.
debug
(
'
Opening tunnel with command: {}
'
.
format
(
background_tunnel_command
))
# Execute
subprocess
.
Popen
(
background_tunnel_command
,
shell
=
True
)
# Setup the proxy now (if required.)
if
task
.
requires_proxy
:
# Ensure conf directory exists
if
not
os
.
path
.
exists
(
'
/shared/etc_apache2_sites_enabled
'
):
if
not
os
.
path
.
exists
(
'
/shared/etc_apache2_sites_enabled
'
):
os
.
makedirs
(
'
/shared/etc_apache2_sites_enabled
'
)
os
.
makedirs
(
'
/shared/etc_apache2_sites_enabled
'
)
...
@@ -573,8 +612,8 @@ def setup_tunnel_and_proxy(task):
...
@@ -573,8 +612,8 @@ def setup_tunnel_and_proxy(task):
if
not
os
.
path
.
exists
(
apache_conf_file
):
if
not
os
.
path
.
exists
(
apache_conf_file
):
# Write conf file
# Write conf file
# Some info about the various SSL switches: https://serverfault.com/questions/577616/using-https-between-apache-loadbalancer-and-backends
logger
.
debug
(
'
Writing task proxy conf to {}
'
.
format
(
apache_conf_file
))
logger
.
debug
(
'
Writing task proxy conf to {}
'
.
format
(
apache_conf_file
))
websocket_protocol
=
'
wss
'
if
task
.
container
.
interface_protocol
==
'
https
'
else
'
ws
'
websocket_protocol
=
'
wss
'
if
task
.
container
.
interface_protocol
==
'
https
'
else
'
ws
'
task_proxy_host
=
get_task_proxy_host
()
task_proxy_host
=
get_task_proxy_host
()
apache_conf_content
=
'''
apache_conf_content
=
'''
...
@@ -640,7 +679,7 @@ Listen '''+str(task.tcp_tunnel_port)+'''
...
@@ -640,7 +679,7 @@ Listen '''+str(task.tcp_tunnel_port)+'''
with
open
(
apache_conf_file
,
'
w
'
)
as
f
:
with
open
(
apache_conf_file
,
'
w
'
)
as
f
:
f
.
write
(
apache_conf_content
)
f
.
write
(
apache_conf_content
)
# Now check conf exist on proxy
# Now check
if
conf exist on proxy
logger
.
debug
(
'
Checking if conf is enabled on proxy service
'
)
logger
.
debug
(
'
Checking if conf is enabled on proxy service
'
)
out
=
os_shell
(
'
ssh -o StrictHostKeyChecking=no proxy
"
[ -e /etc/apache2/sites-enabled/{}.conf ]
"'
.
format
(
task
.
uuid
),
capture
=
True
)
out
=
os_shell
(
'
ssh -o StrictHostKeyChecking=no proxy
"
[ -e /etc/apache2/sites-enabled/{}.conf ]
"'
.
format
(
task
.
uuid
),
capture
=
True
)
...
@@ -661,42 +700,6 @@ Listen '''+str(task.tcp_tunnel_port)+'''
...
@@ -661,42 +700,6 @@ Listen '''+str(task.tcp_tunnel_port)+'''
raise
ErrorMessage
(
'
Somthing went wrong when loading the task proxy conf
'
)
raise
ErrorMessage
(
'
Somthing went wrong when loading the task proxy conf
'
)
# Check if the tunnel is (still) active and if not create it
logger
.
debug
(
'
Checking if task
"
{}
"
has a running tunnel
'
.
format
(
task
))
out
=
os_shell
(
'
ps -ef | grep
"
:{}:{}:{}
"
| grep -v grep
'
.
format
(
task
.
tcp_tunnel_port
,
task
.
interface_ip
,
task
.
interface_port
),
capture
=
True
)
if
out
.
exit_code
==
0
:
logger
.
debug
(
'
Task
"
{}
"
has a running tunnel, using it
'
.
format
(
task
))
else
:
logger
.
debug
(
'
Task
"
{}
"
has no running tunnel, creating it
'
.
format
(
task
))
# Get user keys
user_keys
=
KeyPair
.
objects
.
get
(
user
=
task
.
user
,
default
=
True
)
# Tunnel command
if
task
.
computing
.
type
==
'
remotehop
'
:
# Get computing params
first_host
=
task
.
computing
.
conf
.
get
(
'
first_host
'
)
first_user
=
task
.
computing
.
conf
.
get
(
'
first_user
'
)
#second_host = task.computing.conf.get('second_host')
#second_user = task.computing.conf.get('second_user')
#setup_command = task.computing.conf.get('setup_command')
#base_port = task.computing.conf.get('base_port')
tunnel_command
=
'
ssh -4 -i {} -o StrictHostKeyChecking=no -nNT -L 0.0.0.0:{}:{}:{} {}@{} &
'
.
format
(
user_keys
.
private_key_file
,
task
.
tcp_tunnel_port
,
task
.
interface_ip
,
task
.
interface_port
,
first_user
,
first_host
)
else
:
tunnel_command
=
'
ssh -4 -o StrictHostKeyChecking=no -nNT -L 0.0.0.0:{}:{}:{} localhost &
'
.
format
(
task
.
tcp_tunnel_port
,
task
.
interface_ip
,
task
.
interface_port
)
background_tunnel_command
=
'
nohup {} >/dev/null 2>&1 &
'
.
format
(
tunnel_command
)
# Log
logger
.
debug
(
'
Opening tunnel with command: {}
'
.
format
(
background_tunnel_command
))
# Execute
subprocess
.
Popen
(
background_tunnel_command
,
shell
=
True
)
...
...
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