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
Container registry
Model registry
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
Maunium
synapse
Commits
82eacb0e
Unverified
Commit
82eacb0e
authored
3 years ago
by
Richard van der Hoff
Committed by
GitHub
3 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Fix --no-daemonize for synctl with workers (#9995)
parent
daca7b27
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
changelog.d/9995.bugfix
+1
-0
1 addition, 0 deletions
changelog.d/9995.bugfix
synctl
+32
-70
32 additions, 70 deletions
synctl
with
33 additions
and
70 deletions
changelog.d/9995.bugfix
0 → 100644
+
1
−
0
View file @
82eacb0e
Fix `synctl`'s `--no-daemonize` parameter to work correctly with worker processes.
This diff is collapsed.
Click to expand it.
synctl
+
32
−
70
View file @
82eacb0e
...
@@ -24,12 +24,13 @@ import signal
...
@@ -24,12 +24,13 @@ import signal
import
subprocess
import
subprocess
import
sys
import
sys
import
time
import
time
from
typing
import
Iterable
import
yaml
import
yaml
from
synapse.config
import
find_config_files
from
synapse.config
import
find_config_files
SYNAPSE
=
[
sys
.
executable
,
"
-m
"
,
"
synapse.app.homeserver
"
]
MAIN_PROCESS
=
"
synapse.app.homeserver
"
GREEN
=
"
\x1b
[1;32m
"
GREEN
=
"
\x1b
[1;32m
"
YELLOW
=
"
\x1b
[1;33m
"
YELLOW
=
"
\x1b
[1;33m
"
...
@@ -68,71 +69,37 @@ def abort(message, colour=RED, stream=sys.stderr):
...
@@ -68,71 +69,37 @@ def abort(message, colour=RED, stream=sys.stderr):
sys
.
exit
(
1
)
sys
.
exit
(
1
)
def
start
(
configfile
:
str
,
daemonize
:
bool
=
True
)
->
bool
:
def
start
(
pidfile
:
str
,
app
:
str
,
config
_
file
s
:
Iterable
[
str
]
,
daemonize
:
bool
)
->
bool
:
"""
Attempts to start synapse.
"""
Attempts to start
a
synapse
main or worker process
.
Args:
Args:
configfile: path to a yaml synapse config file
pidfile: the pidfile we expect the process to create
daemonize: whether to daemonize synapse or keep it attached to the current
app: the python module to run
session
config_files: config files to pass to synapse
daemonize: if True, will include a --daemonize argument to synapse
Returns:
Returns:
True if the process started successfully
True if the process started successfully
or was already running
False if there was an error starting the process
False if there was an error starting the process
If deamonize is False it will only return once synapse exits.
"""
"""
write
(
"
Starting ...
"
)
if
os
.
path
.
exists
(
pidfile
)
and
pid_running
(
int
(
open
(
pidfile
).
read
())):
args
=
SYNAPSE
print
(
app
+
"
already running
"
)
if
daemonize
:
args
.
extend
([
"
--daemonize
"
,
"
-c
"
,
configfile
])
else
:
args
.
extend
([
"
-c
"
,
configfile
])
try
:
subprocess
.
check_call
(
args
)
write
(
"
started synapse.app.homeserver(%r)
"
%
(
configfile
,),
colour
=
GREEN
)
return
True
return
True
except
subprocess
.
CalledProcessError
as
e
:
write
(
"
error starting (exit code: %d); see above for logs
"
%
e
.
returncode
,
colour
=
RED
,
)
return
False
def
start_worker
(
app
:
str
,
configfile
:
str
,
worker_configfile
:
str
)
->
bool
:
args
=
[
sys
.
executable
,
"
-m
"
,
app
]
"""
Attempts to start a synapse worker.
for
c
in
config_files
:
Args:
args
+=
[
"
-c
"
,
c
]
app: name of the worker
'
s appservice
if
daemonize
:
configfile: path to a yaml synapse config file
args
.
append
(
"
--daemonize
"
)
worker_configfile: path to worker specific yaml synapse file
Returns:
True if the process started successfully
False if there was an error starting the process
"""
args
=
[
sys
.
executable
,
"
-m
"
,
app
,
"
-c
"
,
configfile
,
"
-c
"
,
worker_configfile
,
"
--daemonize
"
,
]
try
:
try
:
subprocess
.
check_call
(
args
)
subprocess
.
check_call
(
args
)
write
(
"
started %s(%
r
)
"
%
(
app
,
worker_
configfile
),
colour
=
GREEN
)
write
(
"
started %s(%
s
)
"
%
(
app
,
"
,
"
.
join
(
config
_
file
s
)
),
colour
=
GREEN
)
return
True
return
True
except
subprocess
.
CalledProcessError
as
e
:
except
subprocess
.
CalledProcessError
as
e
:
write
(
write
(
"
error starting %s(%
r
) (exit code: %d); see above for logs
"
"
error starting %s(%
s
) (exit code: %d); see above for logs
"
%
(
app
,
worker_
configfile
,
e
.
returncode
),
%
(
app
,
"
,
"
.
join
(
config
_
file
s
)
,
e
.
returncode
),
colour
=
RED
,
colour
=
RED
,
)
)
return
False
return
False
...
@@ -224,10 +191,11 @@ def main():
...
@@ -224,10 +191,11 @@ def main():
if
not
os
.
path
.
exists
(
configfile
):
if
not
os
.
path
.
exists
(
configfile
):
write
(
write
(
"
No config file found
\n
"
f
"
Config file
{
configfile
}
does not exist.
\n
"
"
To generate a config file, run
'
%s -c %s --generate-config
"
f
"
To generate a config file, run:
\n
"
"
--server-name=<server name> --report-stats=<yes/no>
'
\n
"
f
"
{
sys
.
executable
}
-m
{
MAIN_PROCESS
}
"
%
(
"
"
.
join
(
SYNAPSE
),
options
.
configfile
),
f
"
-c
{
configfile
}
--generate-config
"
f
"
--server-name=<server name> --report-stats=<yes/no>
\n
"
,
stream
=
sys
.
stderr
,
stream
=
sys
.
stderr
,
)
)
sys
.
exit
(
1
)
sys
.
exit
(
1
)
...
@@ -323,7 +291,7 @@ def main():
...
@@ -323,7 +291,7 @@ def main():
has_stopped
=
False
has_stopped
=
False
if
start_stop_synapse
:
if
start_stop_synapse
:
if
not
stop
(
pidfile
,
"
synapse.app.homeserver
"
):
if
not
stop
(
pidfile
,
MAIN_PROCESS
):
has_stopped
=
False
has_stopped
=
False
if
not
has_stopped
and
action
==
"
stop
"
:
if
not
has_stopped
and
action
==
"
stop
"
:
sys
.
exit
(
1
)
sys
.
exit
(
1
)
...
@@ -346,30 +314,24 @@ def main():
...
@@ -346,30 +314,24 @@ def main():
if
action
==
"
start
"
or
action
==
"
restart
"
:
if
action
==
"
start
"
or
action
==
"
restart
"
:
error
=
False
error
=
False
if
start_stop_synapse
:
if
start_stop_synapse
:
# Check if synapse is already running
if
not
start
(
pidfile
,
MAIN_PROCESS
,
(
configfile
,),
options
.
daemonize
):
if
os
.
path
.
exists
(
pidfile
)
and
pid_running
(
int
(
open
(
pidfile
).
read
())):
abort
(
"
synapse.app.homeserver already running
"
)
if
not
start
(
configfile
,
bool
(
options
.
daemonize
)):
error
=
True
error
=
True
for
worker
in
workers
:
for
worker
in
workers
:
env
=
os
.
environ
.
copy
()
env
=
os
.
environ
.
copy
()
# Skip starting a worker if its already running
if
os
.
path
.
exists
(
worker
.
pidfile
)
and
pid_running
(
int
(
open
(
worker
.
pidfile
).
read
())
):
print
(
worker
.
app
+
"
already running
"
)
continue
if
worker
.
cache_factor
:
if
worker
.
cache_factor
:
os
.
environ
[
"
SYNAPSE_CACHE_FACTOR
"
]
=
str
(
worker
.
cache_factor
)
os
.
environ
[
"
SYNAPSE_CACHE_FACTOR
"
]
=
str
(
worker
.
cache_factor
)
for
cache_name
,
factor
in
worker
.
cache_factors
.
items
():
for
cache_name
,
factor
in
worker
.
cache_factors
.
items
():
os
.
environ
[
"
SYNAPSE_CACHE_FACTOR_
"
+
cache_name
.
upper
()]
=
str
(
factor
)
os
.
environ
[
"
SYNAPSE_CACHE_FACTOR_
"
+
cache_name
.
upper
()]
=
str
(
factor
)
if
not
start_worker
(
worker
.
app
,
configfile
,
worker
.
configfile
):
if
not
start
(
worker
.
pidfile
,
worker
.
app
,
(
configfile
,
worker
.
configfile
),
options
.
daemonize
,
):
error
=
True
error
=
True
# Reset env back to the original
# Reset env back to the original
...
...
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