diff options
author | Rory& <root@rory.gay> | 2024-02-19 11:49:49 +0100 |
---|---|---|
committer | Rory& <root@rory.gay> | 2024-06-05 17:25:16 +0200 |
commit | c773e646bd47067d41708944b4c6d29a469b7005 (patch) | |
tree | 2c1b732107bd81c80f71d5911cd7d5359eec8822 /host | |
parent | Fix container folder name (diff) | |
download | Spacebar-Open-Infrastructure-c773e646bd47067d41708944b4c6d29a469b7005.tar.xz |
Better service definition
Squashed 13 commits
Diffstat (limited to 'host')
-rwxr-xr-x | host/Spacebar-nginx/containers/spacebar-server/services/spacebar-server.nix | 169 |
1 files changed, 105 insertions, 64 deletions
diff --git a/host/Spacebar-nginx/containers/spacebar-server/services/spacebar-server.nix b/host/Spacebar-nginx/containers/spacebar-server/services/spacebar-server.nix index aaa1396..9a6cdd6 100755 --- a/host/Spacebar-nginx/containers/spacebar-server/services/spacebar-server.nix +++ b/host/Spacebar-nginx/containers/spacebar-server/services/spacebar-server.nix @@ -1,74 +1,115 @@ { config, pkgs, lib, spacebar-server, ... }: - +let + services = [ + { name = "api"; description = "Spacebar Server API"; } + { name = "gateway"; description = "Spacebar Server Gateway"; } + { name = "cdn"; description = "Spacebar Server CDN"; } + ]; +in { services.rabbitmq.enable = true; - systemd.tmpfiles.rules = [ "d /var/lib/spacebar-server 0750 spacebar spacebar" ]; - users.users.spacebar = { - isSystemUser = true; - group = "spacebar"; - home = "/var/lib/spacebar-server"; - createHome = true; - shell = "/bin/false"; - }; + #systemd.tmpfiles.rules = [ "d /var/lib/spacebar-server 0750 spacebar spacebar" ]; + #users.users.spacebar = { + # isSystemUser = true; + # group = "spacebar"; + # home = "/var/lib/spacebar-server"; + # createHome = true; + # shell = "/bin/false"; + #}; - users.groups.spacebar = { - #isSystemGroup = true; - }; + #users.groups.spacebar = { + # #isSystemGroup = true; + #}; - systemd.services = { - "spacebar-server-api" = { - wantedBy = [ "multi-user.target" ]; - after = [ "resolvconf.target" "postgresql.service" "rabbitmq.service" ]; - serviceConfig = { - ExecStart = '' - ${spacebar-server.packages.${pkgs.system}.default}/bin/start-api - ''; - #Restart = "never"; - User = "spacebar"; - WorkingDirectory = "/var/lib/spacebar-server"; - Environment = [ - "DATABASE=postgres://spacebar:spacebar@127.0.0.1/spacebar" - "LOG_REQUESTS='-'" - #"DB_LOGGING='true'" - ]; - }; - }; - "spacebar-server-gateway" = { - wantedBy = [ "multi-user.target" ]; - after = [ "resolvconf.target" "postgresql.service" "rabbitmq.service" "spacebar-server-api.service" ]; - serviceConfig = { - ExecStart = '' - ${spacebar-server.packages.${pkgs.system}.default}/bin/start-gateway - ''; - #Restart = "never"; - User = "spacebar"; - WorkingDirectory = "/var/lib/spacebar-server"; - Environment = [ - "DATABASE=postgres://spacebar:spacebar@127.0.0.1/spacebar" - "LOG_REQUESTS='-'" - #"DB_LOGGING='true'" - ]; - }; - }; - "spacebar-server-cdn" = { - wantedBy = [ "multi-user.target" ]; - after = [ "resolvconf.target" "postgresql.service" "rabbitmq.service" "spacebar-server-api.service" ]; - serviceConfig = { - ExecStart = '' - ${spacebar-server.packages.${pkgs.system}.default}/bin/start-cdn - ''; - #Restart = "never"; - User = "spacebar"; - WorkingDirectory = "/var/lib/spacebar-server"; - Environment = [ - "DATABASE=postgres://spacebar:spacebar@127.0.0.1/spacebar" - "LOG_REQUESTS='-'" - #"DB_LOGGING='true'" - ]; + #systemd.services = { + # "spacebar-server-api" = { + # description = "Spacebar Server API"; + # wantedBy = [ "multi-user.target" ]; + # requires = [ "resolvconf.target" "postgresql.service" "rabbitmq.service" ]; + # serviceConfig = { + # ExecStart = "${spacebar-server.packages.${pkgs.system}.default}/bin/start-api"; + # + # WorkingDirectory = "/var/lib/spacebar-server"; + # StateDirectory = "spacebar"; + # StateDirectoryMode = "0700"; + # ProtectSystem = "strict"; + # ProtectHome = true; + # PrivateTmp = true; + # NoNewPrivileges = true; + # PrivateDevices = true; + # Restart = "on-failure"; + # Environment = [ + # "DATABASE=postgres://spacebar:spacebar@127.0.0.1/spacebar" + # "LOG_REQUESTS='-'" + # #"DB_LOGGING='true'" + # ]; + # }; + # }; + # "spacebar-server-gateway" = { + # wantedBy = [ "multi-user.target" ]; + # requires = [ "resolvconf.target" "postgresql.service" "rabbitmq.service" "spacebar-server-api.service" ]; + # serviceConfig = { + # ExecStart = '' + # ${spacebar-server.packages.${pkgs.system}.default}/bin/start-gateway + # ''; + # #Restart = "never"; + # User = "spacebar"; + # WorkingDirectory = "/var/lib/spacebar-server"; + # Environment = [ + # "DATABASE=postgres://spacebar:spacebar@127.0.0.1/spacebar" + # "LOG_REQUESTS='-'" + # #"DB_LOGGING='true'" + # ]; + # }; + # }; + # "spacebar-server-cdn" = { + # wantedBy = [ "multi-user.target" ]; + # requires = [ "resolvconf.target" "postgresql.service" "rabbitmq.service" "spacebar-server-api.service" ]; + # serviceConfig = { + # ExecStart = '' + # ${spacebar-server.packages.${pkgs.system}.default}/bin/start-cdn + # ''; + # #Restart = "never"; + # User = "spacebar"; + # WorkingDirectory = "/var/lib/spacebar-server"; + # Environment = [ + # "DATABASE=postgres://spacebar:spacebar@127.0.0.1/spacebar" + # "LOG_REQUESTS='-'" + # #"DB_LOGGING='true'" + # ]; + # }; + # }; + #}; + + # use some kind of foreach loop to generate the services, with proper casing for descriptions + # and service names + + systemd.services = lib.attrsets.genAttrs + (map (service: "spacebar-server-${service.name}") services) + (serviceName: { + description = serviceName; + wantedBy = [ "multi-user.target" ]; + requires = [ "postgresql.service" "rabbitmq.service" ] + ++ (if serviceName != "spacebar-server-api" then [ "spacebar-server-api.service" ] else []); + serviceConfig = { + ExecStart = "${spacebar-server.packages.${pkgs.system}.default}/bin/start-${builtins.substring 16 30 serviceName}"; + WorkingDirectory = "/var/lib/spacebar-server"; + StateDirectory = "spacebar"; + StateDirectoryMode = "0700"; + ProtectSystem = "strict"; + ProtectHome = true; + PrivateTmp = true; + NoNewPrivileges = true; + PrivateDevices = true; + Restart = "on-failure"; + Environment = [ + "DATABASE=postgres://spacebar:spacebar@127.0.0.1/spacebar" + "LOG_REQUESTS='-'" + #"DB_LOGGING='true'" + ]; }; - }; - }; + }); system.stateVersion = "22.11"; # DO NOT EDIT! } |