update user logic

This commit is contained in:
zack 2024-10-21 20:12:15 -04:00
parent ddad66dda4
commit c0d6ee9e8b
No known key found for this signature in database
GPG key ID: 5F873416BCF59F35

View file

@ -143,30 +143,27 @@
in {
wantedBy = ["multi-user.target"];
after = ["network.target" "postgresql.service"];
# note that if you are connecting to a postgres instance on a different host
# postgresql.service should not be included in the requires.
requires = ["network-online.target" "postgresql.service"];
description = "zoey computer";
environment = {
# RELEASE_TMP is used to write the state of the
# VM configuration when the system is running
# it needs to be a writable directory
RELEASE_TMP = working_directory;
# can be generated in an elixir console with
# Base.encode32(:crypto.strong_rand_bytes(32))
PORT = "${toString cfg.phx.port}";
PORT = toString cfg.phx.port;
PHX_HOST = cfg.domain;
PHX_SERVER = toString cfg.phx.enableServer;
};
preStart = optionalString (cfg.phx.database.passwordFile != null) ''
# Set the password for the database user
export PGPASSWORD=$(cat ${cfg.phx.database.passwordFile})
echo "ALTER USER ${cfg.phx.database.user} WITH PASSWORD '$PGPASSWORD'" | \
runuser -u ${config.services.postgresql.superUser} -- ${config.services.postgresql.package}/bin/psql
'';
serviceConfig = {
Type = "exec";
DynamicUser = true;
WorkingDirectory = working_directory;
# Implied by DynamicUser, but just to emphasize due to RELEASE_TMP
PrivateTmp = true;
ExecStart = pkgs.writeShellScript "start-zoeycomputer" ''
export SECRET_KEY_BASE=$(cat ${cfg.phx.secret_key_file})
# If a password file is specified, construct DATABASE_URL with password
${
if cfg.phx.database.passwordFile != null
then ''
@ -178,8 +175,11 @@
''
}
# Run migrations
${cfg.phx.package}/bin/${release_name} eval "ZoeysComputer.Release.migrate"
${cfg.phx.package}/bin/${release_name} start
# Start the application
exec ${cfg.phx.package}/bin/${release_name} start
'';
ExecStop = ''
${cfg.phx.package}/bin/${release_name} stop
@ -192,8 +192,7 @@
StartLimitBurst = 3;
StartLimitInterval = 10;
};
# disksup requires bash
path = [pkgs.bash pkgs.coreutils];
path = with pkgs; [bash util-linux];
};
};
};