nginx: make it possible to skip systemctl restart nginx
This commit is contained in:
parent
0b5535eaa3
commit
84a7774368
|
@ -7,6 +7,7 @@ from pyinfra.operations import files, server, apt, systemd
|
||||||
from pyinfra.facts.deb import DebPackages
|
from pyinfra.facts.deb import DebPackages
|
||||||
from pyinfra_acmetool import deploy_acmetool
|
from pyinfra_acmetool import deploy_acmetool
|
||||||
|
|
||||||
|
|
||||||
def deploy_nginx():
|
def deploy_nginx():
|
||||||
if not host.get_fact(DebPackages):
|
if not host.get_fact(DebPackages):
|
||||||
raise DeployError(("Can't deploy prerequisites on non-deb system"))
|
raise DeployError(("Can't deploy prerequisites on non-deb system"))
|
||||||
|
@ -18,6 +19,7 @@ def deploy_nginx():
|
||||||
packages=["nginx-extras"],
|
packages=["nginx-extras"],
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
def add_nginx_domain(
|
def add_nginx_domain(
|
||||||
domain: str,
|
domain: str,
|
||||||
config_path: str = None,
|
config_path: str = None,
|
||||||
|
@ -25,7 +27,9 @@ def add_nginx_domain(
|
||||||
proxy_port: int = None,
|
proxy_port: int = None,
|
||||||
redirect: str = None,
|
redirect: str = None,
|
||||||
enabled=True,
|
enabled=True,
|
||||||
acmetool=True):
|
acmetool=True,
|
||||||
|
skip_restart=False,
|
||||||
|
):
|
||||||
"""Let a domain be handled by nginx, create a Let's Encrypt certificate for it, and deploy the config.
|
"""Let a domain be handled by nginx, create a Let's Encrypt certificate for it, and deploy the config.
|
||||||
|
|
||||||
This method supports 3 template configs for configuring your site:
|
This method supports 3 template configs for configuring your site:
|
||||||
|
@ -42,6 +46,7 @@ def add_nginx_domain(
|
||||||
:param redirect: where to 301 redirect to, e.g. https://i.delta.chat$request_uri
|
:param redirect: where to 301 redirect to, e.g. https://i.delta.chat$request_uri
|
||||||
:param enabled: whether the site should be enabled at /etc/nginx/sites-enabled
|
:param enabled: whether the site should be enabled at /etc/nginx/sites-enabled
|
||||||
:param acmetool: whether acmetool should fetch TLS certs for the domain
|
:param acmetool: whether acmetool should fetch TLS certs for the domain
|
||||||
|
:param skip_restart: set True if the nginx restart is done later anyway
|
||||||
"""
|
"""
|
||||||
default_config_link = files.link(
|
default_config_link = files.link(
|
||||||
path="/etc/nginx/sites-enabled/default", present=False
|
path="/etc/nginx/sites-enabled/default", present=False
|
||||||
|
@ -77,7 +82,8 @@ def add_nginx_domain(
|
||||||
)
|
)
|
||||||
elif proxy_port:
|
elif proxy_port:
|
||||||
config = files.template(
|
config = files.template(
|
||||||
src=importlib.resources.files(__package__) / "proxy_pass.nginx_config.j2",
|
src=importlib.resources.files(__package__)
|
||||||
|
/ "proxy_pass.nginx_config.j2",
|
||||||
dest=f"/etc/nginx/sites-available/{domain}",
|
dest=f"/etc/nginx/sites-available/{domain}",
|
||||||
user="root",
|
user="root",
|
||||||
group="root",
|
group="root",
|
||||||
|
@ -102,6 +108,7 @@ def add_nginx_domain(
|
||||||
group="root",
|
group="root",
|
||||||
present=enabled,
|
present=enabled,
|
||||||
)
|
)
|
||||||
|
if not skip_restart:
|
||||||
if config.changed or config_link.changed:
|
if config.changed or config_link.changed:
|
||||||
systemd.service(
|
systemd.service(
|
||||||
name="NGINX should be enabled and running",
|
name="NGINX should be enabled and running",
|
||||||
|
@ -110,4 +117,3 @@ def add_nginx_domain(
|
||||||
enabled=True,
|
enabled=True,
|
||||||
restarted=True,
|
restarted=True,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue