Skip to content

Commit

Permalink
enh: properly check for nginx status before attempting to reload
Browse files Browse the repository at this point in the history
  • Loading branch information
paulmueller committed Jan 18, 2024
1 parent 42df7f6 commit 81ba35c
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 5 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
0.9.5
- enh: properly check for nginx status before attempting to reload
0.9.4
- maintenance release
0.9.3
Expand Down
5 changes: 1 addition & 4 deletions dcor_control/cli/inspect.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import subprocess as sp

import click
from dcor_shared import paths

Expand Down Expand Up @@ -59,8 +57,7 @@ def inspect(assume_yes=False):

inspect_mod.reload_supervisord()

click.secho("Reloading nginx...", bold=True)
sp.check_output("systemctl reload nginx", shell=True)
inspect_mod.reload_nginx()

# ask the user whether to search for orphaned files
if assume_yes or click.confirm('Perform search for orphaned files?'):
Expand Down
6 changes: 5 additions & 1 deletion dcor_control/inspect/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@
check_ckan_uploader_patch_to_support_symlinks,
)
from .config_nginx import check_nginx
from .config_supervisord import check_supervisord, reload_supervisord
from .config_supervisord import (
check_supervisord,
reload_supervisord,
reload_nginx,
)
from .config_uwsgi import check_uwsgi
from .data_ckan import check_orphaned_files
19 changes: 19 additions & 0 deletions dcor_control/inspect/config_supervisord.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,16 @@ def check_supervisord(autocorrect):
wpath.write_text(data)


def is_nginx_running():
"""Simple check for whether supervisord is running"""
try:
sp.check_output("sudo systemctl status nginx", shell=True)
except sp.CalledProcessError:
return False
else:
return True


def is_supervisord_running():
"""Simple check for whether supervisord is running"""
try:
Expand All @@ -38,6 +48,15 @@ def is_supervisord_running():
return True


def reload_nginx():
if is_nginx_running():
click.secho("Reloading nginx...", bold=True)
sp.check_output("sudo systemctl reload nginx", shell=True)
else:
click.secho("Not reloading nginx (not running)...",
bold=True, fg="red")


def reload_supervisord():
if is_supervisord_running():
click.secho("Reloading CKAN...", bold=True)
Expand Down

0 comments on commit 81ba35c

Please sign in to comment.