Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
synapse
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Terraform modules
Monitor
Service Desk
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
Timo Ley
synapse
Commits
6cdca710
Commit
6cdca710
authored
8 years ago
by
Anant Prakash
Committed by
Richard van der Hoff
8 years ago
Browse files
Options
Downloads
Patches
Plain Diff
synctl.py: wait for synapse to stop before restarting (#2020)
parent
3ce8d591
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
synapse/app/synctl.py
+43
-4
43 additions, 4 deletions
synapse/app/synctl.py
with
43 additions
and
4 deletions
synapse/app/synctl.py
+
43
−
4
View file @
6cdca710
...
@@ -23,14 +23,27 @@ import signal
...
@@ -23,14 +23,27 @@ import signal
import
subprocess
import
subprocess
import
sys
import
sys
import
yaml
import
yaml
import
errno
import
time
SYNAPSE
=
[
sys
.
executable
,
"
-B
"
,
"
-m
"
,
"
synapse.app.homeserver
"
]
SYNAPSE
=
[
sys
.
executable
,
"
-B
"
,
"
-m
"
,
"
synapse.app.homeserver
"
]
GREEN
=
"
\x1b
[1;32m
"
GREEN
=
"
\x1b
[1;32m
"
YELLOW
=
"
\x1b
[1;33m
"
RED
=
"
\x1b
[1;31m
"
RED
=
"
\x1b
[1;31m
"
NORMAL
=
"
\x1b
[m
"
NORMAL
=
"
\x1b
[m
"
def
pid_running
(
pid
):
try
:
os
.
kill
(
pid
,
0
)
return
True
except
OSError
,
err
:
if
err
.
errno
==
errno
.
EPERM
:
return
True
return
False
def
write
(
message
,
colour
=
NORMAL
,
stream
=
sys
.
stdout
):
def
write
(
message
,
colour
=
NORMAL
,
stream
=
sys
.
stdout
):
if
colour
==
NORMAL
:
if
colour
==
NORMAL
:
stream
.
write
(
message
+
"
\n
"
)
stream
.
write
(
message
+
"
\n
"
)
...
@@ -38,6 +51,11 @@ def write(message, colour=NORMAL, stream=sys.stdout):
...
@@ -38,6 +51,11 @@ def write(message, colour=NORMAL, stream=sys.stdout):
stream
.
write
(
colour
+
message
+
NORMAL
+
"
\n
"
)
stream
.
write
(
colour
+
message
+
NORMAL
+
"
\n
"
)
def
abort
(
message
,
colour
=
RED
,
stream
=
sys
.
stderr
):
write
(
message
,
colour
,
stream
)
sys
.
exit
(
1
)
def
start
(
configfile
):
def
start
(
configfile
):
write
(
"
Starting ...
"
)
write
(
"
Starting ...
"
)
args
=
SYNAPSE
args
=
SYNAPSE
...
@@ -45,7 +63,8 @@ def start(configfile):
...
@@ -45,7 +63,8 @@ def start(configfile):
try
:
try
:
subprocess
.
check_call
(
args
)
subprocess
.
check_call
(
args
)
write
(
"
started synapse.app.homeserver(%r)
"
%
(
configfile
,),
colour
=
GREEN
)
write
(
"
started synapse.app.homeserver(%r)
"
%
(
configfile
,),
colour
=
GREEN
)
except
subprocess
.
CalledProcessError
as
e
:
except
subprocess
.
CalledProcessError
as
e
:
write
(
write
(
"
error starting (exit code: %d); see above for logs
"
%
e
.
returncode
,
"
error starting (exit code: %d); see above for logs
"
%
e
.
returncode
,
...
@@ -76,8 +95,16 @@ def start_worker(app, configfile, worker_configfile):
...
@@ -76,8 +95,16 @@ def start_worker(app, configfile, worker_configfile):
def
stop
(
pidfile
,
app
):
def
stop
(
pidfile
,
app
):
if
os
.
path
.
exists
(
pidfile
):
if
os
.
path
.
exists
(
pidfile
):
pid
=
int
(
open
(
pidfile
).
read
())
pid
=
int
(
open
(
pidfile
).
read
())
os
.
kill
(
pid
,
signal
.
SIGTERM
)
try
:
write
(
"
stopped %s
"
%
(
app
,),
colour
=
GREEN
)
os
.
kill
(
pid
,
signal
.
SIGTERM
)
write
(
"
stopped %s
"
%
(
app
,),
colour
=
GREEN
)
except
OSError
,
err
:
if
err
.
errno
==
errno
.
ESRCH
:
write
(
"
%s not running
"
%
(
app
,),
colour
=
YELLOW
)
elif
err
.
errno
==
errno
.
EPERM
:
abort
(
"
Cannot stop %s: Operation not permitted
"
%
(
app
,))
else
:
abort
(
"
Cannot stop %s: Unknown error
"
%
(
app
,))
Worker
=
collections
.
namedtuple
(
"
Worker
"
,
[
Worker
=
collections
.
namedtuple
(
"
Worker
"
,
[
...
@@ -190,7 +217,19 @@ def main():
...
@@ -190,7 +217,19 @@ def main():
if
start_stop_synapse
:
if
start_stop_synapse
:
stop
(
pidfile
,
"
synapse.app.homeserver
"
)
stop
(
pidfile
,
"
synapse.app.homeserver
"
)
# TODO: Wait for synapse to actually shutdown before starting it again
# Wait for synapse to actually shutdown before starting it again
if
action
==
"
restart
"
:
running_pids
=
[]
if
start_stop_synapse
and
os
.
path
.
exists
(
pidfile
):
running_pids
.
append
(
int
(
open
(
pidfile
).
read
()))
for
worker
in
workers
:
if
os
.
path
.
exists
(
worker
.
pidfile
):
running_pids
.
append
(
int
(
open
(
worker
.
pidfile
).
read
()))
if
len
(
running_pids
)
>
0
:
write
(
"
Waiting for process to exit before restarting...
"
)
for
running_pid
in
running_pids
:
while
pid_running
(
running_pid
):
time
.
sleep
(
0.2
)
if
action
==
"
start
"
or
action
==
"
restart
"
:
if
action
==
"
start
"
or
action
==
"
restart
"
:
if
start_stop_synapse
:
if
start_stop_synapse
:
...
...
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