Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
E
envsetup
Manage
Activity
Members
Plan
Redmine
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Container Registry
Model registry
Analyze
Contributor 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
mediaserver
envsetup
Commits
4674090c
Commit
4674090c
authored
7 years ago
by
Stéphane Diemer
Browse files
Options
Downloads
Patches
Plain Diff
Added a script to set domain of an app (refs
#21163
).
parent
6b230b7f
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
set_app_domain.py
+78
-13
78 additions, 13 deletions
set_app_domain.py
with
78 additions
and
13 deletions
set_app_domain.py
+
78
−
13
View file @
4674090c
...
@@ -13,7 +13,7 @@ from utils import log
...
@@ -13,7 +13,7 @@ from utils import log
class
SetAppDomain
():
class
SetAppDomain
():
USAGE
=
'''
%s [-d] [-f] [-h] [app] <domain>
USAGE
=
'''
USAGE:
%s [-d] [-f] [-h] [app] <domain>
-d: Debug mode (can be started with non root users).
-d: Debug mode (can be started with non root users).
-f: Force mode (to force replacement of configuration even if there are warnings).
-f: Force mode (to force replacement of configuration even if there are warnings).
-h: Show this message.
-h: Show this message.
...
@@ -23,7 +23,8 @@ class SetAppDomain():
...
@@ -23,7 +23,8 @@ class SetAppDomain():
It is possible to specify which MS instance should be targetted
It is possible to specify which MS instance should be targetted
by using this format: ms-<instance name> (for example ms-msuser).
by using this format: ms-<instance name> (for example ms-msuser).
domain: The new domain.
'''
%
__file__
domain: The new domain.
'''
%
__file__
MS_INSTANCE_USER_PATTERN
=
r
'
[a-z0-9\-]+
'
UNIX_USER_PATTERN
=
r
'
[a-z0-9\-]+
'
DOMAIN_PATTERN
=
r
'
[a-z0-9\-]+\.[a-z0-9\-]+\.[a-z]+
'
NGINX_SERVER_NAME_PATTERN
=
r
'
\s*server_name\s+([\w\-\_\.\ ]+);
'
NGINX_SERVER_NAME_PATTERN
=
r
'
\s*server_name\s+([\w\-\_\.\ ]+);
'
def
__init__
(
self
,
*
args
):
def
__init__
(
self
,
*
args
):
...
@@ -31,7 +32,7 @@ class SetAppDomain():
...
@@ -31,7 +32,7 @@ class SetAppDomain():
args
=
list
(
args
)
args
=
list
(
args
)
# Check if help is required
# Check if help is required
if
'
-h
'
in
args
:
if
'
-h
'
in
args
:
log
(
'
USAGE:
'
+
self
.
USAGE
)
log
(
self
.
USAGE
)
sys
.
exit
(
0
)
sys
.
exit
(
0
)
# Check current dir
# Check current dir
root_dir
=
utils
.
get_dir
(
__file__
)
root_dir
=
utils
.
get_dir
(
__file__
)
...
@@ -56,33 +57,38 @@ class SetAppDomain():
...
@@ -56,33 +57,38 @@ class SetAppDomain():
# Parse args
# Parse args
if
not
args
:
if
not
args
:
log
(
'
Not enough arguments.
'
)
log
(
'
Not enough arguments.
'
)
log
(
'
USAGE:
'
+
self
.
USAGE
)
log
(
self
.
USAGE
)
sys
.
exit
(
1
)
sys
.
exit
(
1
)
new_domain
=
args
.
pop
()
new_domain
=
args
.
pop
()
if
not
re
.
match
(
self
.
DOMAIN_PATTERN
,
new_domain
):
log
(
'
The given domain
"
%s
"
does not match the expected pattern (%s).
\n
'
%
(
new_domain
,
self
.
DOMAIN_PATTERN
))
log
(
self
.
USAGE
)
sys
.
exit
(
1
)
if
args
:
if
args
:
app
=
args
.
pop
()
app
=
args
.
pop
()
# Change domain
# Change domain
instance
=
None
instance
=
None
if
app
==
'
cm
'
:
if
app
==
'
cm
'
:
nginx_conf
=
'
/etc/nginx/sites-available/skyreach.conf
'
nginx_conf
=
'
/etc/nginx/sites-available/skyreach.conf
'
self
.
change_cm_domain
(
new_domain
)
elif
app
==
'
mon
'
:
elif
app
==
'
mon
'
:
nginx_conf
=
'
/etc/nginx/sites-available/msmonitor.conf
'
nginx_conf
=
'
/etc/nginx/sites-available/msmonitor.conf
'
elif
app
==
'
ms
'
or
app
.
startswith
(
'
ms-
'
):
elif
app
==
'
ms
'
or
app
.
startswith
(
'
ms-
'
):
if
app
.
startswith
(
'
ms-
'
):
if
app
.
startswith
(
'
ms-
'
):
instance
=
app
[
3
:].
strip
(
'
. -
\t\n
'
)
instance
=
app
[
3
:].
strip
(
'
. -
\t\n
'
)
if
not
re
.
match
(
self
.
MS_INSTANCE
_USER_PATTERN
,
instance
):
if
not
re
.
match
(
self
.
UNIX
_USER_PATTERN
,
instance
):
log
(
'
Invalid MS instance requested. Validation reg exp is: %s
'
%
self
.
MS_INSTANCE
_USER_PATTERN
)
log
(
'
Invalid MS instance requested. Validation reg exp is: %s
'
%
self
.
UNIX
_USER_PATTERN
)
sys
.
exit
(
1
)
sys
.
exit
(
1
)
else
:
else
:
instance
=
'
msuser
'
instance
=
'
msuser
'
nginx_conf
=
'
/etc/nginx/sites-available/mediaserver-%s.conf
'
%
instance
nginx_conf
=
'
/etc/nginx/sites-available/mediaserver-%s.conf
'
%
instance
self
.
change_ms_domain
(
new_domain
,
instance
)
else
:
else
:
log
(
'
Invalid app name requested.
'
)
log
(
'
Invalid app name requested.
'
)
log
(
'
USAGE:
'
+
self
.
USAGE
)
log
(
self
.
USAGE
)
sys
.
exit
(
1
)
sys
.
exit
(
1
)
self
.
change_nginx_domain
(
nginx_conf
,
new_domain
)
self
.
change_nginx_domain
(
nginx_conf
,
new_domain
)
if
instance
:
self
.
change_hosts_file
(
new_domain
)
self
.
change_ms_instance_domain
(
instance
,
new_domain
)
sys
.
exit
(
0
)
sys
.
exit
(
0
)
def
change_nginx_domain
(
self
,
path
,
new_domain
):
def
change_nginx_domain
(
self
,
path
,
new_domain
):
...
@@ -117,19 +123,78 @@ class SetAppDomain():
...
@@ -117,19 +123,78 @@ class SetAppDomain():
with
open
(
path
,
'
w
'
)
as
fo
:
with
open
(
path
,
'
w
'
)
as
fo
:
fo
.
write
(
new_vhost
)
fo
.
write
(
new_vhost
)
log
(
'
The configuration file
"
%s
"
has been update.
'
%
path
)
log
(
'
The configuration file
"
%s
"
has been update.
'
%
path
)
utils
.
run_commands
([
'
service nginx restart
'
])
else
:
else
:
log
(
'
The configuration file
"
%s
"
is already up to date.
'
%
path
)
log
(
'
The configuration file
"
%s
"
is already up to date.
'
%
path
)
def
change_ms_instance_domain
(
self
,
instance
,
new_domain
):
def
change_hosts_file
(
self
,
new_domain
):
# TODO: set MS url in site settings
with
open
(
'
/etc/hosts
'
,
'
r
'
)
as
fo
:
# TODO: reset all local resources managers
hosts
=
fo
.
read
()
if
'
'
+
new_domain
in
hosts
:
hosts
=
hosts
.
replace
(
'
'
+
new_domain
,
''
)
elif
'
\t
'
+
new_domain
in
hosts
:
hosts
=
hosts
.
replace
(
'
\t
'
+
new_domain
,
''
)
hosts
=
hosts
.
strip
()
new_hosts
=
''
for
line
in
hosts
.
split
(
'
\n
'
):
new_hosts
+=
'
\n
'
+
line
if
line
.
startswith
(
'
127.0.0.1
'
):
new_hosts
+=
'
'
+
new_domain
if
new_hosts
!=
hosts
:
if
self
.
debug
:
log
(
'
New hosts:
'
)
log
(
new_hosts
)
else
:
with
open
(
'
/etc/hosts
'
,
'
w
'
)
as
fo
:
fo
.
write
(
new_hosts
)
log
(
'
The hosts file has been update.
'
)
utils
.
run_commands
([
'
service nscd restart
'
])
else
:
log
(
'
The hosts file is already up to date.
'
)
def
change_ms_domain
(
self
,
new_domain
,
instance
):
try
:
try
:
utils
.
run_commands
([
'
sudo su %s -c
"
ls
"'
%
instance
])
import
mediaserver
ms_path
=
mediaserver
.
__path__
[
0
]
new_url
=
'
https://%s
'
%
new_domain
log
(
'
Assuming that the new url is using HTTPS:
"
%s
"'
%
new_url
)
cmds
=
[
# set site url in site settings
'
python3
'
,
os
.
path
.
join
(
ms_path
,
'
scripts
'
,
'
mssiteconfig.py
'
),
instance
,
'
site_url=
"
%s
"'
%
new_url
,
# reset all local resources managers
'
python3
'
,
os
.
path
.
join
(
ms_path
,
'
scripts
'
,
'
reset_service_resources.py
'
),
instance
,
'
local
'
,
# change configuration of worker on MS side
'
sed -i
"
s@
\'
url
\'
:
\'\\
(http[s]*
\\
)://.*
\'
@
\'
url
\'
:
\'\\
1://%s
\'
@
"
/etc/celerity/config.py
'
%
new_domain
,
]
worker_ips
=
utils
.
get_conf
(
'
CELERITY_WORKER_IP
'
)
or
'
127.0.1.1
'
# change configuration of worker on worker side
for
worker_ip
in
worker_ips
.
split
(
'
,
'
):
cmds
.
append
(
'
ssh root@%s sed -i
"
s@
\'
url
\'
:
\'\\
(http[s]*
\\
)://.*
\'
@
\'
url
\'
:
\'\\
1://%s
\'
@
"
/etc/celerity/config.py
'
%
(
worker_ip
,
new_domain
))
utils
.
run_commands
(
cmds
)
except
Exception
as
e
:
except
Exception
as
e
:
log
(
'
Unable to set MS domain:
\n
%s
'
%
e
)
log
(
'
Unable to set MS domain:
\n
%s
'
%
e
)
sys
.
exit
(
1
)
sys
.
exit
(
1
)
else
:
else
:
log
(
'
MS domain changed
'
)
log
(
'
MS domain changed
'
)
log
(
'
Some steps to change the domain should be done manually:
'
)
log
(
'
- Change the domain of MS used in CM stations configuration.
'
)
def
change_cm_domain
(
self
,
new_domain
):
try
:
new_url
=
'
https://%s
'
%
new_domain
log
(
'
Assuming that the new url is using HTTPS:
"
%s
"'
%
new_url
)
cmds
=
[
# set site url in site settings
'
echo
\'
from skyreach_site.base.models import SiteSettings; ss = SiteSettings.get_singleton(); ss.url =
"
%s
"
; ss.save(); print(
"
site settings saved
"
)
\'
| su skyreach -c
"
python3 /home/skyreach/htdocs/skyreach_site/manage.py shell --plain --no-startup
"'
%
new_url
,
]
utils
.
run_commands
(
cmds
)
except
Exception
as
e
:
log
(
'
Unable to set CM domain:
\n
%s
'
%
e
)
sys
.
exit
(
1
)
else
:
log
(
'
CM domain changed
'
)
log
(
'
Some steps to change the domain should be done manually:
'
)
log
(
'
- Change the url of CM in the related MS.
'
)
if
__name__
==
'
__main__
'
:
if
__name__
==
'
__main__
'
:
...
...
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