Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[inferno-ml] Move inferno-ml-server to system service #152

Merged
merged 3 commits into from
Jan 16, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion nix/inferno-ml/images/common/cpu.nix
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
configuration = {
port = 8080;
cache = {
path = "/home/inferno/.cache/inferno-ml-server/models";
path = "/home/inferno/.cache/models";
max-size = 10 * 1073741824;
};
# NOTE This should be overridden for real deployments
Expand Down
2 changes: 1 addition & 1 deletion nix/inferno-ml/images/common/gpu.nix
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
configuration = {
port = 8080;
cache = {
path = "/home/inferno/.cache/inferno-ml-server/models";
path = "/home/inferno/.cache/models";
max-size = 10 * 1073741824;
};
# NOTE This should be overridden for real deployments
Expand Down
4 changes: 2 additions & 2 deletions nix/inferno-ml/images/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ in
{
imports = [ ./common/gpu.nix ];
# The big one
amazonImage.sizeMB = 107374;
amazonImage.sizeMB = 53687;
}
];
};
Expand All @@ -63,7 +63,7 @@ in
{
imports = [ ./common/cpu.nix ];
# The big one
amazonImage.sizeMB = 107374;
amazonImage.sizeMB = 53687;
}
];
};
Expand Down
2 changes: 1 addition & 1 deletion nix/inferno-ml/images/qcow2.nix
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
# Ten minute timeout
timeout = 600;
cache = {
path = "/home/inferno/.cache/inferno-ml-server/models";
path = "/home/inferno/.cache/models";
max-size = 10 * 1073741824;
};
# NOTE This can be overridden, unless you plan on running the VM and
Expand Down
17 changes: 12 additions & 5 deletions nix/inferno-ml/modules/inferno-ml-server.nix
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,13 @@ in
}.${builtins.typeOf cfg.configuration};
in
{
systemd.user.services.inferno-ml-server = {
# FIXME Ideally we should have a system user to run this. However,
# we are doing some urgent testing and that would require more work.
# We will fix having this run as `inferno` once we finalize the image
# config
#
# See https://github.com/plow-technologies/inferno/issues/151
systemd.services.inferno-ml-server = {
description = "Start `inferno-ml-server` server";
wantedBy = [ "default.target" ];
after = [ "network-online.target" ];
Expand All @@ -153,6 +159,11 @@ in
ExecStart = "${cfg.package}/bin/inferno-ml-server --config ${configFile}";
Restart = "always";
RestartSec = 5;
User = "inferno";
Group = "inferno";
PrivateTmp = "yes";
ProtectDevices = "yes";
NoNewPrivileges = "yes";
};
};

Expand All @@ -171,10 +182,6 @@ in
mkdir -p ${path}
chown -R ${cfg.user}:${cfg.group} ${path}
chmod u+rwx ${path}

mkdir -p /home/${cfg.user}/.cache/bridge
chown -R ${cfg.user}:${cfg.group} /home/${cfg.user}/.cache/bridge
chmod u+rwx /home/${cfg.user}/.cache/bridge
'';
};
}
Expand Down
22 changes: 9 additions & 13 deletions nix/inferno-ml/tests/server.nix
Original file line number Diff line number Diff line change
Expand Up @@ -151,13 +151,13 @@ pkgs.nixosTest {
};

systemd = {
user.services.inferno-ml-server = {
# Silences logs
serviceConfig.StandardOutput = pkgs.lib.mkForce "null";
serviceConfig.StandardError = pkgs.lib.mkForce "null";
};

services = {
inferno-ml-server = {
# Silences logs
serviceConfig.StandardOutput = pkgs.lib.mkForce "null";
serviceConfig.StandardError = pkgs.lib.mkForce "null";
};

dummy-bridge = {
description = "Run dummy bridge server";
wantedBy = [ "default.target" ];
Expand All @@ -177,12 +177,6 @@ pkgs.nixosTest {
};
# See https://github.com/NixOS/nixpkgs/issues/183629
system.activationScripts = {
enableLingering = ''
rm -rf /var/lib/systemd/linger
mkdir -p /var/lib/systemd/linger
touch /var/lib/systemd/linger/inferno
'';

setupDummyDir = ''
mkdir /tmp/dummy
chmod a+rwx /tmp/dummy
Expand Down Expand Up @@ -225,9 +219,11 @@ pkgs.nixosTest {
'psql -U inferno -d inferno -f ${../migrations/v1-create-tables.sql}'
)
node.succeed('insert-mnist-model')
node.wait_for_unit("inferno-ml-server.service")
node.succeed('curl --fail localhost:8080/status')

node.succeed('sudo -HE -u inferno parse-scripts-and-save-params')

node.systemctl("start inferno-ml-server.service", user="inferno")
node.succeed('sudo -HE -u inferno run-db-test >&2')

# `tests/scripts/ones.inferno`
Expand Down
Loading