mirror of
https://codeberg.org/Mo8it/AdvLabDB.git
synced 2025-03-13 19:38:10 +00:00
Clean up before container setup
This commit is contained in:
parent
b6008c1d31
commit
8cbb0d0d50
9 changed files with 2 additions and 182 deletions
|
@ -16,14 +16,7 @@ Assistants have a separate interface to set marks and schedule appointments with
|
||||||
== Status
|
== Status
|
||||||
The software is still in beta and under active development. Do not hesitate to open issues!
|
The software is still in beta and under active development. Do not hesitate to open issues!
|
||||||
|
|
||||||
== Setup
|
// TODO: New setup with containers
|
||||||
To setup a server, see the link:docs/server_setup.adoc[setup documentation].
|
|
||||||
|
|
||||||
=== Logs
|
|
||||||
After setting up a server, logs related to AdvLabDB can be found in the directory `/var/log/advlabdb` on the server.
|
|
||||||
|
|
||||||
== Known issues
|
|
||||||
* Update scripts are not working.
|
|
||||||
|
|
||||||
== What does the name mean?
|
== What does the name mean?
|
||||||
**Adv**anced **Lab** **D**ata**B**ase
|
**Adv**anced **Lab** **D**ata**B**ase
|
||||||
|
|
|
@ -1,16 +0,0 @@
|
||||||
from ..terminal_utils import box, run
|
|
||||||
from .shared import show_update_datetime
|
|
||||||
|
|
||||||
|
|
||||||
def main():
|
|
||||||
show_update_datetime()
|
|
||||||
|
|
||||||
box("Update system packages")
|
|
||||||
run("sudo apt update")
|
|
||||||
run("sudo apt upgrade -y")
|
|
||||||
|
|
||||||
run("sudo reboot")
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
|
||||||
main()
|
|
|
@ -1,27 +0,0 @@
|
||||||
from ..setup.shared import LOCAL_BIN, REPO_DIR, install_latest_pipx, poetry_update
|
|
||||||
from ..terminal_utils import box, run
|
|
||||||
from .shared import show_update_datetime
|
|
||||||
|
|
||||||
|
|
||||||
def main():
|
|
||||||
show_update_datetime()
|
|
||||||
|
|
||||||
box("Upgrade pipx")
|
|
||||||
install_latest_pipx()
|
|
||||||
|
|
||||||
box("Upgrade pipx packages")
|
|
||||||
pipx_bin = LOCAL_BIN / "pipx"
|
|
||||||
run(f"{pipx_bin} upgrade-all --include-injected")
|
|
||||||
|
|
||||||
box("Backup database")
|
|
||||||
# TODO: Backup
|
|
||||||
|
|
||||||
box("Pull updates from the git repository")
|
|
||||||
run("git pull origin main", cwd=REPO_DIR)
|
|
||||||
|
|
||||||
box("Install latest Poetry packages")
|
|
||||||
poetry_update()
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
|
||||||
main()
|
|
|
@ -1,9 +0,0 @@
|
||||||
server {
|
|
||||||
listen 80;
|
|
||||||
server_name localhost;
|
|
||||||
|
|
||||||
location / {
|
|
||||||
include proxy_params;
|
|
||||||
proxy_pass http://unix:/home/admin/advlabdb/gunicorn.sock;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,14 +0,0 @@
|
||||||
[Unit]
|
|
||||||
Description=Gunicorn - AdvLabDB
|
|
||||||
After=network.target
|
|
||||||
|
|
||||||
[Service]
|
|
||||||
User=admin
|
|
||||||
Group=www-data
|
|
||||||
Environment="PATH=/home/admin/advlabdb/.venv/bin"
|
|
||||||
WorkingDirectory=/home/admin/advlabdb
|
|
||||||
ExecStart=/home/admin/advlabdb/.venv/bin/gunicorn --workers 5 --bind unix:gunicorn.sock --umask 007 --log-file /var/log/advlabdb/gunicorn.log run:app
|
|
||||||
Restart=always
|
|
||||||
|
|
||||||
[Install]
|
|
||||||
WantedBy=multi-user.target
|
|
|
@ -5,15 +5,11 @@ No relative imports allowed in this file to be able to run server_setup.py witho
|
||||||
import sys
|
import sys
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
from shared import LOCAL_BIN, LOGS_DIR, install_latest_pipx, poetry_update
|
|
||||||
|
|
||||||
sys.path.insert(0, str(Path(__file__).parent.parent.absolute()))
|
sys.path.insert(0, str(Path(__file__).parent.parent.absolute()))
|
||||||
from terminal_utils import run, step
|
from terminal_utils import run, step
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
file_dir = Path(__file__).parent.absolute()
|
|
||||||
|
|
||||||
step("Update system packages")
|
step("Update system packages")
|
||||||
run("sudo apt update")
|
run("sudo apt update")
|
||||||
run("sudo apt dist-upgrade")
|
run("sudo apt dist-upgrade")
|
||||||
|
@ -36,58 +32,6 @@ def main():
|
||||||
run("sudo ufw enable")
|
run("sudo ufw enable")
|
||||||
run("sudo ufw status")
|
run("sudo ufw status")
|
||||||
|
|
||||||
step("Enable Gunicorn")
|
|
||||||
gunicorn_service_file = file_dir / "gunicorn.service"
|
|
||||||
run(f"sudo cp -v {gunicorn_service_file} /etc/systemd/system/")
|
|
||||||
run("sudo systemctl enable gunicorn")
|
|
||||||
|
|
||||||
step("Setup Nginx")
|
|
||||||
for dir_appendix in ("available", "enabled"):
|
|
||||||
run(f"sudo rm -v /etc/nginx/sites-{dir_appendix}/default")
|
|
||||||
|
|
||||||
nginx_conf_file = file_dir / "advlabdb.conf"
|
|
||||||
run(f"sudo cp -v {nginx_conf_file} /etc/nginx/sites-available/")
|
|
||||||
run("sudo ln -v -s /etc/nginx/sites-available/advlabdb.conf /etc/nginx/sites-enabled/")
|
|
||||||
run("sudo systemctl enable nginx")
|
|
||||||
|
|
||||||
step("Install pipx")
|
|
||||||
install_latest_pipx()
|
|
||||||
|
|
||||||
pipx_bin = LOCAL_BIN / "pipx"
|
|
||||||
|
|
||||||
step("Install Poetry")
|
|
||||||
run(f"{pipx_bin} install poetry")
|
|
||||||
# Place virtual environments in the root directory of the project
|
|
||||||
# The virtual environment will then be found in /home/admin/advlabdb/.venv
|
|
||||||
poetry_bin = LOCAL_BIN / "poetry"
|
|
||||||
run(f"{poetry_bin} config virtualenvs.in-project true")
|
|
||||||
|
|
||||||
step("Install Certbot")
|
|
||||||
run(f"{pipx_bin} install certbot")
|
|
||||||
run(f"{pipx_bin} inject certbot certbot-nginx")
|
|
||||||
|
|
||||||
step("Setup Certbot")
|
|
||||||
certbot_bin = LOCAL_BIN / "certbot"
|
|
||||||
run(f"sudo {certbot_bin} --nginx")
|
|
||||||
run(
|
|
||||||
f"echo \"0 0,12 * * * root python3 -c 'import random; import time; time.sleep(random.random() * 3600)' && sudo {certbot_bin} renew -q\" | sudo tee -a /etc/crontab"
|
|
||||||
)
|
|
||||||
|
|
||||||
step("Setup update cron jobs")
|
|
||||||
|
|
||||||
user_update_script = file_dir / "user_update.py"
|
|
||||||
user_update_log = LOGS_DIR / "user_update.log"
|
|
||||||
# Every Sunday at 04:00
|
|
||||||
run(f'echo "0 4 * * 0 admin python3 -u {user_update_script} &>> {user_update_log}" | sudo tee -a /etc/crontab')
|
|
||||||
|
|
||||||
root_update_script = file_dir / "root_update.py"
|
|
||||||
root_update_log = LOGS_DIR / "root_update.log"
|
|
||||||
# Every Sunday at 04:15
|
|
||||||
run(f'echo "15 4 * * 0 root python3 -u {root_update_script} &>> {root_update_log}" | sudo tee -a /etc/crontab')
|
|
||||||
|
|
||||||
step("Install latest Poetry packages")
|
|
||||||
poetry_update()
|
|
||||||
|
|
||||||
step("Deactivate the 'root' user")
|
step("Deactivate the 'root' user")
|
||||||
run("sudo passwd -l root")
|
run("sudo passwd -l root")
|
||||||
|
|
||||||
|
|
|
@ -1,29 +0,0 @@
|
||||||
"""
|
|
||||||
No relative imports allowed in this file to be able to run server_setup.py without packages.
|
|
||||||
"""
|
|
||||||
|
|
||||||
import sys
|
|
||||||
from pathlib import Path
|
|
||||||
|
|
||||||
from shared import LOGS_DIR, REPO_DIR
|
|
||||||
|
|
||||||
sys.path.insert(0, str(Path(__file__).parent.parent.absolute()))
|
|
||||||
from terminal_utils import run
|
|
||||||
|
|
||||||
|
|
||||||
def main():
|
|
||||||
# Create logs directory
|
|
||||||
run(f"sudo mkdir -v -p {LOGS_DIR}")
|
|
||||||
run(f"sudo chown -R admin:admin {LOGS_DIR}")
|
|
||||||
|
|
||||||
log_file = LOGS_DIR / "server_setup.log"
|
|
||||||
|
|
||||||
# Start actual server setup script with logging
|
|
||||||
run(
|
|
||||||
f"python3 -u /home/admin/advlabdb/advlabdb/scripts/setup/logged_server_setup.py | tee {log_file}",
|
|
||||||
cwd=REPO_DIR,
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
|
||||||
main()
|
|
|
@ -1,22 +0,0 @@
|
||||||
"""
|
|
||||||
No relative imports allowed in this file to be able to run server_setup.py without packages.
|
|
||||||
"""
|
|
||||||
|
|
||||||
import sys
|
|
||||||
from pathlib import Path
|
|
||||||
|
|
||||||
sys.path.insert(0, str(Path(__file__).parent.parent.absolute()))
|
|
||||||
from terminal_utils import run
|
|
||||||
|
|
||||||
LOCAL_BIN = Path("/home/admin/.local/bin/")
|
|
||||||
LOGS_DIR = Path("/var/log/advlabdb")
|
|
||||||
REPO_DIR = Path("/home/admin/advlabdb")
|
|
||||||
|
|
||||||
|
|
||||||
def install_latest_pipx():
|
|
||||||
run("pip install --user --upgrade pipx")
|
|
||||||
|
|
||||||
|
|
||||||
def poetry_update():
|
|
||||||
poetry_bin = LOCAL_BIN / "poetry"
|
|
||||||
run(f"{poetry_bin} update --no-dev", cwd=REPO_DIR)
|
|
|
@ -106,7 +106,7 @@ env_file = ADVLABDB_REPO_DIR / ".env"
|
||||||
if ADVLABDB_REPO_DIR.is_dir():
|
if ADVLABDB_REPO_DIR.is_dir():
|
||||||
print("Pulling AdvLabDB repository.")
|
print("Pulling AdvLabDB repository.")
|
||||||
run(
|
run(
|
||||||
"git pull",
|
"git pull origin main",
|
||||||
cwd=ADVLABDB_REPO_DIR,
|
cwd=ADVLABDB_REPO_DIR,
|
||||||
check=True,
|
check=True,
|
||||||
)
|
)
|
||||||
|
|
Loading…
Add table
Reference in a new issue