Page MenuHomeDevCentral

D3454.id.diff
No OneTemporary

D3454.id.diff

diff --git a/_modules/node.py b/_modules/node.py
--- a/_modules/node.py
+++ b/_modules/node.py
@@ -259,6 +259,28 @@
return " ".join(["[" + ip + "]" for ip in ipv6])
+def get_all_ips():
+ """
+ A function to get a list of IPv4, not enclosed,
+ and IPv6, enclosed by [].
+ Returns a string depending on the IPv6 currently assigned.
+
+ CLI Example:
+
+ salt * node.get_all_ips
+ """
+ all_ips = []
+
+ for _interface, ips in __grains__.get("ip4_interfaces").items():
+ all_ips.extend(ips)
+
+ for _interface, ips in __grains__.get("ip6_interfaces").items():
+ ips = ["[" + ip + "]" for ip in ips]
+ all_ips.extend(ips)
+
+ return " ".join(set(all_ips))
+
+
def resolve_network():
"""
A function to determine canonical properties of networks
diff --git a/roles/devserver/init.sls b/roles/devserver/init.sls
--- a/roles/devserver/init.sls
+++ b/roles/devserver/init.sls
@@ -13,4 +13,5 @@
- .pkg
- .userland-software
- .userland-home
+ - .webserver-home
- .webserver-wwwroot51
diff --git a/roles/devserver/webserver-home/files/001-server.conf b/roles/devserver/webserver-home/files/001-server.conf
new file mode 100644
--- /dev/null
+++ b/roles/devserver/webserver-home/files/001-server.conf
@@ -0,0 +1,65 @@
+# -------------------------------------------------------------
+# Nginx :: server homepage and home directories
+# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
+# Project: Nasqueron
+# License: Trivial work, not eligible to copyright
+# Source file: roles/devserver/webserver-home/files/001-server.conf
+# -------------------------------------------------------------
+#
+# <auto-generated>
+# This file is managed by our rOPS SaltStack repository.
+#
+# Changes to this file may cause incorrect behavior
+# and will be lost if the state is redeployed.
+# </auto-generated>
+
+ server {
+ listen 80;
+ listen [::]:80;
+ server_name {{ fqdn }} {{ hostname }}.nasqueron.drake localhost {{ ips }};
+
+ include includes/tls;
+ ssl_certificate /usr/local/etc/letsencrypt/live/{{ fqdn }}/fullchain.pem;
+ ssl_certificate_key /usr/local/etc/letsencrypt/live/{{ fqdn }}/privkey.pem;
+
+ include includes/letsencrypt;
+
+ ###
+ ### Cover pages
+ ###
+
+ root /var/wwwroot/nasqueron.org/{{ hostname }};
+ index index.html index.htm;
+
+ ###
+ ### API
+ ###
+
+ location ~ ^/datasources/.*\.json(/|$) {
+ include includes/cors-open;
+ }
+
+ ###
+ ### public_html user directories
+ ###
+
+ set $userdir public_html;
+
+ location ~ ^/~(.+?)(/.*)?$ {
+ alias /var/home-wwwroot/$1$2;
+ index index.html index.htm;
+
+ autoindex on;
+ charset utf-8;
+ }
+
+ ###
+ ### Misc directories
+ ###
+
+ location /poudriere {
+ alias /usr/local/poudriere/data/logs/bulk;
+ autoindex on;
+ }
+
+ }
diff --git a/roles/devserver/webserver-home/files/setup-web-home.py b/roles/devserver/webserver-home/files/setup-web-home.py
new file mode 100755
--- /dev/null
+++ b/roles/devserver/webserver-home/files/setup-web-home.py
@@ -0,0 +1,75 @@
+#!/usr/bin/env python3
+
+# -------------------------------------------------------------
+# Setup web home
+# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
+# Project: Nasqueron
+# Description: Create folder and symlink for public_html
+# License: BSD-2-Clause
+# -------------------------------------------------------------
+
+
+import os
+import shutil
+import sys
+
+
+# -------------------------------------------------------------
+# Web setup
+# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
+
+
+def is_clean(username):
+ return not os.path.exists(f"/var/home-wwwroot/{username}") and not os.path.exists(
+ f"/home/{username}/public_html"
+ )
+
+
+def is_valid_setup(username):
+ return (
+ os.path.exists(f"/var/home-wwwroot/{username}")
+ and not os.path.islink(f"/var/home-wwwroot/{username}")
+ and os.path.islink(f"/home/{username}/public_html")
+ and os.readlink(f"/home/{username}/public_html")
+ == f"/var/home-wwwroot/{username}"
+ )
+
+
+def setup(username):
+ os.mkdir(f"/var/home-wwwroot/{username}", mode=0o755)
+ shutil.chown(f"/var/home-wwwroot/{username}", user=username, group="web")
+ os.symlink(f"/var/home-wwwroot/{username}", f"/home/{username}/public_html")
+
+
+# -------------------------------------------------------------
+# Application entry point
+# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
+
+
+def run(username):
+ if is_valid_setup(username):
+ print("Setup is already done and looks correct.", file=sys.stderr)
+ sys.exit(4)
+
+ if not is_clean(username):
+ print(
+ "Directories exist but aren't correct, check them manually.",
+ file=sys.stderr,
+ )
+ sys.exit(2)
+
+ try:
+ setup(username)
+ except OSError as e:
+ print(e, file=sys.stderr)
+ sys.exit(8)
+
+
+if __name__ == "__main__":
+ argc = len(sys.argv)
+
+ if argc < 2:
+ print(f"Usage: {sys.argv[0]} <username>", file=sys.stderr)
+ sys.exit(1)
+
+ run(sys.argv[1])
diff --git a/roles/devserver/webserver-home/init.sls b/roles/devserver/webserver-home/init.sls
new file mode 100644
--- /dev/null
+++ b/roles/devserver/webserver-home/init.sls
@@ -0,0 +1,36 @@
+# -------------------------------------------------------------
+# Salt — Provision a development server
+# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
+# Project: Nasqueron
+# License: Trivial work, not eligible to copyright
+# -------------------------------------------------------------
+
+{% from "map.jinja" import dirs with context %}
+
+# -------------------------------------------------------------
+# Home directories
+# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
+
+/var/home-wwwroot:
+ file.directory:
+ - mode: 711
+ - group: web
+
+{{ dirs.bin }}/setup-web-home:
+ file.managed:
+ - source: salt://roles/devserver/webserver-home/files/setup-web-home.py
+ - mode: 755
+
+# -------------------------------------------------------------
+# Default vhost
+# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
+
+{{ dirs.etc }}/nginx/vhosts/001-server.conf:
+ file.managed:
+ - source: salt://roles/devserver/webserver-home/files/001-server.conf
+ - mode: 644
+ - template: jinja
+ - context:
+ hostname: {{ grains.host }}
+ fqdn: {{ grains.fqdn }}
+ ips: "{{ salt["node.get_all_ips"]() }}"

File Metadata

Mime Type
text/plain
Expires
Mon, Dec 23, 10:49 (17 h, 54 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2312323
Default Alt Text
D3454.id.diff (6 KB)

Event Timeline