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

nixos/seaweedfs: init #353890

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

nixos/seaweedfs: init #353890

wants to merge 1 commit into from

Conversation

liberodark
Copy link
Contributor

Things done

  • Built on platform(s)
    • x86_64-linux
    • aarch64-linux
    • x86_64-darwin
    • aarch64-darwin
  • For non-Linux: Is sandboxing enabled in nix.conf? (See Nix manual)
    • sandbox = relaxed
    • sandbox = true
  • Tested, as applicable:
  • Tested compilation of all packages that depend on this change using nix-shell -p nixpkgs-review --run "nixpkgs-review rev HEAD". Note: all changes have to be committed, also see nixpkgs-review usage
  • Tested basic functionality of all binary files (usually in ./result/bin/)
  • 24.11 Release Notes (or backporting 23.11 and 24.05 Release notes)
    • (Package updates) Added a release notes entry if the change is major or breaking
    • (Module updates) Added a release notes entry if the change is significant
    • (Module addition) Added a release notes entry if adding a new NixOS module
  • Fits CONTRIBUTING.md.

Add a 👍 reaction to pull requests you find important.

@github-actions github-actions bot added 6.topic: nixos Issues or PRs affecting NixOS modules, or package usability issues specific to NixOS 8.has: module (update) This PR changes an existing module in `nixos/` labels Nov 5, 2024
@liberodark liberodark force-pushed the seawedfs branch 2 times, most recently from f984c57 to ed49f65 Compare November 5, 2024 19:25
Copy link
Member

@BonusPlay BonusPlay left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks quite ok, some initial feedback.

nixos/modules/services/network-filesystems/seaweedfs.nix Outdated Show resolved Hide resolved
nixos/modules/services/network-filesystems/seaweedfs.nix Outdated Show resolved Hide resolved
nixos/modules/services/network-filesystems/seaweedfs.nix Outdated Show resolved Hide resolved
nixos/modules/services/network-filesystems/seaweedfs.nix Outdated Show resolved Hide resolved
nixos/modules/services/network-filesystems/seaweedfs.nix Outdated Show resolved Hide resolved
@liberodark liberodark force-pushed the seawedfs branch 3 times, most recently from 017e2f1 to ebed001 Compare November 5, 2024 21:11
@liberodark liberodark marked this pull request as ready for review November 5, 2024 21:38
@liberodark
Copy link
Contributor Author

liberodark commented Nov 5, 2024

image

Some information in how to use :

This is for single Node use :

# Configuration master
  services.seaweedfs.master = {
    enable = true;
    ip = "192.168.0.185";  # IP locale
    ipBind = "0.0.0.0";
    port = 9333;
    peers = [
      "192.168.0.185:9333"  # Local IP
    ];
  };

  # Configuration volume
  services.seaweedfs.volume = {
    enable = true;
    ip = "192.168.0.185";  # IP locale
    ipBind = "0.0.0.0";
    port = 8080;
    master =  [
      "192.168.0.185:9333"  # Local IP
    ];
  };

  # Configuration filer
  services.seaweedfs.filer = {
    enable = true;
    ip = "192.168.0.185";  # IP locale
    ipBind = "0.0.0.0";
    port = 8888;
    master =  [
      "192.168.0.185:9333"  # Local IP
    ];
  };

This is for multi Node use :

# In the other node (192.168.0.186)
services.seaweedfs = {
  master = {
    enable = true;
    ip = "192.168.0.186";
    ipBind = "0.0.0.0";
    port = 9333;
    peers = [
      "192.168.0.185:9333"  # First node
      "192.168.0.186:9333"  # 2 node
      "192.168.0.187:9333"  # 3 node
    ];
  };

  volume = {
    enable = true;
    ip = "192.168.0.186";
    ipBind = "0.0.0.0";
    port = 8080;
    master = [
      "192.168.0.185:9333"  # First node
      "192.168.0.186:9333"  # 2 node
      "192.168.0.187:9333"  # 3 node
    ];
  };

  filer = {
    enable = true;
    ip = "192.168.0.186";
    ipBind = "0.0.0.0";
    port = 8888;
    master = [
      "192.168.0.185:9333"  # First node
      "192.168.0.186:9333"  # 2 node
      "192.168.0.187:9333"  # 3 node
    ];
  };
};

and add in first node :

services.seaweedfs.master = {
  peers = [
    "192.168.0.185:9333"
    "192.168.0.186:9333"
    "192.168.0.187:9333"
  ];
};

For mount seaweedfs :

systemd.services.mount-seaweedfs = {
    description = "Mount SeaweedFS";
    wantedBy = [ "multi-user.target" ];
    after = [ "network-online.target" ];
    wants = [ "network-online.target" ];
    
    serviceConfig = {
      Type = "simple";
      ExecStartPre = ''
        ${pkgs.coreutils}/bin/mkdir -p /mnt/seaweedfs
        ${pkgs.coreutils}/bin/mkdir -p /var/cache/weedfs-cache
      '';
      ExecStart = ''
        ${pkgs.seaweedfs}/bin/weed mount \
          -filer=192.168.0.185:8888,192.168.0.186:8888,192.168.0.187:8888 \
          -dir=/mnt/seaweedfs \
          -allowOthers \
          -cacheDir=/var/cache/weedfs-cache \
          -cacheCapacityMB=1000
      '';
      ExecStop = "${pkgs.fuse}/bin/fusermount -u /mnt/seaweedfs";
      Restart = "always";
      RestartSec = "10s";
      User = "root";  # needed for mount
    };
  };

  # create persistant cache
  systemd.tmpfiles.rules = [
    "d /var/cache/weedfs-cache 0755 root root -"
    ];

@liberodark liberodark marked this pull request as draft November 5, 2024 22:23
@liberodark liberodark marked this pull request as ready for review November 5, 2024 22:26
@liberodark liberodark force-pushed the seawedfs branch 3 times, most recently from b3fc391 to 319d5fa Compare November 6, 2024 07:00
@ofborg ofborg bot added 10.rebuild-darwin: 0 This PR does not cause any packages to rebuild 10.rebuild-linux: 1-10 labels Nov 6, 2024
@liberodark liberodark force-pushed the seawedfs branch 6 times, most recently from ff92140 to 0c2343f Compare November 6, 2024 19:24
@adamcstephens
Copy link
Contributor

While I haven’t reviewed the module, I’d recommend writing a nixos test for this and linking it to the package.

@liberodark
Copy link
Contributor Author

You can test module with :

import ./default.nix {
  pkgs = import <nixpkgs> {};
  lib = import <nixpkgs/lib>;
}:

let
  pkgs = import <nixpkgs> {};
  lib = import <nixpkgs/lib>;
in
pkgs.nixosTest {
  name = "seaweedfs";

  nodes = {
    master = { config, pkgs, ... }: {
      imports = [ ./seaweedfs.nix ];
      services.seaweedfs = {
        master = {
          enable = true;
          ip = "192.168.1.1";
          ipBind = "0.0.0.0";
          port = 9333;
          peers = [ "192.168.1.1:9333" ];
        };
      };
      networking.firewall.allowedTCPPorts = [ 9333 19333 ];
    };

    volume = { config, pkgs, ... }: {
      imports = [ ./seaweedfs.nix ];
      services.seaweedfs = {
        volume = {
          enable = true;
          ip = "192.168.1.2";
          ipBind = "0.0.0.0";
          port = 8080;
          master = [ "192.168.1.1:9333" ];
        };
      };
      networking.firewall.allowedTCPPorts = [ 8080 18080 ];
    };

    filer = { config, pkgs, ... }: {
      imports = [ ./seaweedfs.nix ];
      services.seaweedfs = {
        filer = {
          enable = true;
          ip = "192.168.1.3";
          ipBind = "0.0.0.0";
          port = 8888;
          master = [ "192.168.1.1:9333" ];
          tomlConfig = ''
            [redis2]
            enabled = true
            address = "192.168.1.4:6379"
          '';
        };
      };
      networking.firewall.allowedTCPPorts = [ 8888 18888 ];
    };
  };

  testScript = ''
    start_all()

    # Wait for services to start
    master.wait_for_unit("seaweedfs-master.service")
    volume.wait_for_unit("seaweedfs-volume.service")
    filer.wait_for_unit("seaweedfs-filer.service")

    # Test master status
    master.wait_for_open_port(9333)
    master.succeed("curl -f http://localhost:9333/cluster/status")

    # Test volume status
    volume.wait_for_open_port(8080)
    volume.succeed("curl -f http://localhost:8080/status")

    # Test filer status
    filer.wait_for_open_port(8888)
    filer.succeed("curl -f http://localhost:8888/")

    # Test file operations
    with subtest("File operations"):
        filer.succeed(
            "echo 'test content' > /tmp/test.txt",
            "curl -F file=@/tmp/test.txt http://localhost:8888/",
            "curl -f http://localhost:8888/test.txt"
        )
  '';
}

@SuperSandro2000 SuperSandro2000 changed the title nixosModules.seaweedfs: Add Seaweedfs Module nixos/seaweedfs: init Nov 7, 2024
Copy link
Member

@SuperSandro2000 SuperSandro2000 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've fixed the PR title, please update the commit to match it.

StateDirectory = "seaweedfs";
RuntimeDirectory = "seaweedfs";
Restart = "always";
RestartSec = "60s";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we really increase the default?

nixos/modules/services/network-filesystems/seaweedfs.nix Outdated Show resolved Hide resolved
nixos/modules/services/network-filesystems/seaweedfs.nix Outdated Show resolved Hide resolved
nixos/modules/services/network-filesystems/seaweedfs.nix Outdated Show resolved Hide resolved
nixos/modules/services/network-filesystems/seaweedfs.nix Outdated Show resolved Hide resolved
description = "Prometheus metrics listen port.";
};

tomlConfig = lib.mkOption {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
tomlConfig = lib.mkOption {
config = lib.mkOption {

nixos/modules/services/network-filesystems/seaweedfs.nix Outdated Show resolved Hide resolved

defaultReplicaPlacement = lib.mkOption {
type = lib.types.str;
default = "";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
default = "";
default = cfg.<...>;

should we make this clear like that?

@adamcstephens
Copy link
Contributor

You can test module with :

Why not add this test to the tree in this PR?

@liberodark liberodark force-pushed the seawedfs branch 4 times, most recently from 5f245c5 to fcc4be8 Compare November 7, 2024 12:30
@liberodark
Copy link
Contributor Author

You can test module with :

Why not add this test to the tree in this PR?

Because I am not accustomed to the practice of nixos with regard to tests.

@liberodark liberodark force-pushed the seawedfs branch 2 times, most recently from 8f8883e to fd1c0db Compare November 7, 2024 18:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
6.topic: nixos Issues or PRs affecting NixOS modules, or package usability issues specific to NixOS 8.has: module (update) This PR changes an existing module in `nixos/` 10.rebuild-darwin: 0 This PR does not cause any packages to rebuild 10.rebuild-linux: 1-10
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants