diff --git a/README.md b/README.md index df923db..0cfb880 100644 --- a/README.md +++ b/README.md @@ -22,14 +22,20 @@ The main thing that differs SSVP from other status pages is that it's designed f **Full installation guide**: https://ssvp.docs.amyip.net/installing.html +You need to initialize a database software - either mysql, postgres, or sqlite (can be done by the installer). + +### NixOS (23.11/unstable or later) + +Read the [NixOS section](https://ssvp.docs.amyip.net/installing.html#NixOS) of the documentation. + +### Other Distributions + - Clone the repostiory: ```sh git clone --depth=1 https://github.com/amyipdev/ssvp ``` -- Set up a database service (sqlite3, mysql, mariadb, or postgres) - Run the installer: ```sh cd ssvp diff --git a/docs/installing.rst b/docs/installing.rst index 1fe421c..1e79133 100644 --- a/docs/installing.rst +++ b/docs/installing.rst @@ -1,20 +1,69 @@ Installation ============ -Installation of SSVP is usually simple, thanks to the easy installer (:code:`./install.sh`). +Installation of SSVP is usually simple, thanks to the +easy installer (:code:`./install.sh`). Supported Operating Systems --------------------------- -Right now, we're currently focusing on just supporting Linux. \*BSD and macOS support may come in the future; Windows support is unlikely. - -Theoretically, any Linux distribution should work. We currently only officially support **Debian 12** and **Fedora 38**. - -Our dependency installer currently has support for most **apt**-based and **dnf/yum**-based distributions. Support for other package managers is a `planned feature `_. -The dependency verifier works on all systems, **but cannot check the presence of libpq and its headers**. +Support has a few main levels: + +- Level 0: **Great Support**. Every commit is thoroughly tested on these + levels, usually due to developers running this on their own machines. + Support on these should be perfect. It is not necessary for a platform + to be level 0 for SSVP to be production-ready on it; however, level 0 + platforms are the least likely to have bugs. +- Level 1: **Good Support**. These are environments known to work well. + No workarounds should be required. These platforms should survive major + changes to SSVP with ease, are tested in pipelines, and will always be + tested before any `"minor" `_ releases. + They should be perfectly fine for production. +- Level 2: **Decent Support**. These environments should work just fine. + Minimal to no workarounds should be required. It is recommended to run + a release version of SSVP on these platforms, instead of running main. + Minor releases will have changes tested; however, testing may not be + as thorough. These are still fine to use in production, but a level 1 + platform is recommended. +- Level 3: **Theoretical Support**. In theory, this platform should work + fine; it might have even been tested once. However, it's unknown whether + it works for sure. These platforms may require workarounds, and are not + recommended. +- Level 4: **Unknown Support**. These platforms have completely unknown + support. They have never been tested. Workarounds will likely be required. +- Level -1: **Borked**. These platforms are known not to work. If you'd like + to help make them work, feel free to `contribute `_. + +.. + TODO: alphabetize + +.. list-table:: + + * - Operating System + - Support Level + - Required OS Version + - Packaging Info + * - Fedora + - 0 + - unknown + - + * - Debian + - 0 + - unknown + - + * - NixOS + - 1 + - 23.11/unstable + - + * - Ubuntu + - 3 + - unknown + - If you have to install dependencies manually, be aware that you need all of the packages list `here `_. +If you're on **NixOS**, jump to the :ref:`NixOS instructions`. + Downloading SSVP ---------------- @@ -70,4 +119,43 @@ The "enable on boot" option for systemd will take care of everything. OpenRC is You're now done with the installation. You can run the server by running `srv/tmux.sh`. It should print :code:`no current client` when done. You can check on the server by running `tmux attach`, and disconnect from it by pressing `CTRL-b d`. -If you need to change settings in your configuration file, please see the `configuration guide `_. \ No newline at end of file +If you need to change settings in your configuration file, please see the `configuration guide `_. + +NixOS +----- + +.. _NixOS: + +This section is only necessary for those using NixOS. + +Because the Nix installer can't create a configuration file of its own, you need to create one. +See `the configuration manual `_ for how to do this. + +First, you need to open up your configuration file (either a local one, or `/etc/nixos/configuration.nix`). Locate the :code:`let` list, and add: + +.. code-block:: nix + + ssvp = builtins.fetchTarball "https://github.com/amyipdev/ssvp/archive/nix-shell-distrib.tar.gz"; + +Then, locate the :code:`imports` list, and add: + +.. code-block:: nix + + "${ssvp}/service.nix" + +Below the end of the imports list, then add: + +.. code-block:: nix + + services.ssvp = { + enable = true; + configFile = "/path/to/ssvp-config-file"; + } + +Save and exit the file. Then, reload your nix config: + +.. code-block:: bash + + nixos-reload switch + +SSVP is now up and running. \ No newline at end of file diff --git a/install.sh b/install.sh index 351d4ab..9c656f1 100755 --- a/install.sh +++ b/install.sh @@ -1,4 +1,3 @@ -#!/usr/bin/bash # SPDX-License-Identifier: AGPL-3.0-or-later # # ssvp: server statistics viewer project diff --git a/requirements.txt b/requirements.txt index 9bb7408..e7cace0 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,9 +1,9 @@ -Flask -mysql-connector-python -ping3 -requests -psycopg2 -pyopenssl -gunicorn -sphinx -sphinx_rtd_theme \ No newline at end of file +Flask==2.3.2 +mysql-connector-python==8.1.0 +ping3==4.8.4 +requests==2.31.0 +psycopg2==2.9.6 +pyopenssl==23.2.0 +gunicorn==21.2.0 +sphinx==6.2.1 +sphinx_rtd_theme==1.2.2 \ No newline at end of file diff --git a/service.nix b/service.nix new file mode 100644 index 0000000..2244ab9 --- /dev/null +++ b/service.nix @@ -0,0 +1,78 @@ +{ pkgs, config, lib, ... }: + +with lib; + +let + python3 = pkgs.python311.withPackages (ps: with ps; [ + flask + mysql-connector + ping3 + requests + psycopg2 + gunicorn + ]); + + cfg = config.services.ssvp; + npmlock2nix = import (builtins.fetchTarball + "https://github.com/nix-community/npmlock2nix/archive/9197bbf.tar.gz" + ) {}; + nodeModules = npmlock2nix.v2.node_modules { + src = ./.; + installPhase = "mv node_modules $out/"; + }; + ins = pkgs.runCommand "ssvp" {src = ./.; buildInputs = with pkgs; [ nodejs ];} '' + cp -r --no-preserve=all $src $out + cd $out + cp -r ${nodeModules} node_modules + make + ''; + +in { + options.services.ssvp = { + enable = mkEnableOption "SSVP Production Environment"; + configFile = mkOption { + type = types.str; + description = "Configuration file"; + }; + }; + config = mkIf cfg.enable { + systemd.services.ssvp-gunicorn = { + path = with pkgs; [ + python3 + which + jq + bash + ]; + wantedBy = [ "multi-user.target" ]; + after = [ "network.target" ]; + script = '' + cd ${ins} + ${pkgs.bash}/bin/bash srv/gunicorn.sh + ''; + environment = { SSVP_CONFIG = cfg.configFile; }; + }; + systemd.timers.ssvp-interval = { + wantedBy = [ "timers.target" ]; + timerConfig = { + OnUnitActiveSec = "5m"; + Unit = "ssvp-interval.service"; + }; + }; + systemd.services.ssvp-interval = { + path = with pkgs; [ + python3 + bash + ]; + wantedBy = [ "multi-user.target" ]; + after = [ "network.target" ]; + script = '' + cd ${ins} + ${python3}/bin/python3 srv/interval.py + ''; + serviceConfig = { + Type = "oneshot"; + }; + environment = { SSVP_CONFIG = cfg.configFile; }; + }; + }; +} diff --git a/srv/app.py b/srv/app.py index cfa154d..df4a59a 100644 --- a/srv/app.py +++ b/srv/app.py @@ -31,7 +31,7 @@ app = Flask(__name__, template_folder="../web") cd = os.path.dirname(__file__) -config = json.load(open(f"{cd}/ssvp-config.json", "r")) +config = json.load(open(x if (x := os.getenv("SSVP_CONFIG")) else f"{cd}/ssvp-config.json", "r")) db = getdb.get_handler(config["database"]) diff --git a/srv/gunicorn.sh b/srv/gunicorn.sh index 4c29a24..a40181b 100755 --- a/srv/gunicorn.sh +++ b/srv/gunicorn.sh @@ -30,8 +30,12 @@ set -e cd "$(dirname "$0")" -SSL=$(jq -j .ssl ssvp-config.json) -PORT=$(jq -j .port ssvp-config.json) +if [ "$SSVP_CONFIG" == "" ]; then + SSVP_CONFIG=ssvp-config.json +fi + +SSL=$(jq -j .ssl $SSVP_CONFIG) +PORT=$(jq -j .port $SSVP_CONFIG) if [ $PORT == "null" ]; then if [ $SSL != "null" ]; then diff --git a/srv/interval.py b/srv/interval.py index 1724050..60fe264 100644 --- a/srv/interval.py +++ b/srv/interval.py @@ -28,7 +28,7 @@ import test_modules cd = os.path.dirname(__file__) -config = json.load(open(f"{cd}/ssvp-config.json", "r")) +config = json.load(open(x if (x := os.getenv("SSVP_CONFIG")) else f"{cd}/ssvp-config.json", "r")) db = getdb.get_handler(config["database"]) diff --git a/uninstall.sh b/uninstall.sh index f343373..023c9a4 100755 --- a/uninstall.sh +++ b/uninstall.sh @@ -1,4 +1,3 @@ -#!/usr/bin/bash # SPDX-License-Identifier: AGPL-3.0-or-later # # ssvp: server statistics viewer project