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

experimental/multiple-mysqld-instances #5542

Closed

Conversation

MarcWeber
Copy link
Contributor

Allow instantiating multiple mysql instances.

Usage example of most current patch version:

  services.mysql.enable = true; // traditional

  // add another instance:
  service.mysql.services.mysql_on_tmp = {
    enable = true;
    port = 3307;
    package = pkgs.mysql55;
    dataDir = "/tmp/mysql";
    socketDir = "/tmp/mysql_tmpfs.socket";
    uid = 20000;
    gid = 20000;
  };

@lucabrunox
Copy link
Contributor

I think it's better to avoid this kind of import, it's hard to be accepted in nixos. I'm long thinking about multiple services, however right now I'm on vacation :) So this is my suggestion:

services.mysql.instances.<name> = ...

You can do this without the need for that kind of import. See nixos containers as an example. So services.mysql would be the default instance. In addition there will be also services.mysql.instances.<name>.

Not only, we can think of an helper function multipleInstances = options: ... which takes the service options, and creates a default instance plus the .instances thing.

@MarcWeber
Copy link
Contributor Author

I've sent a message to nix-dev so that it can be discussed. My patch is least invasive, your proposal is nicer in the long run so I agree on your idea.

@lucabrunox
Copy link
Contributor

My proposal is not more invasive. Importing modules like in your approach is less declarative and probably more invasive. I think it's widely accepted that modules should not accept other arguments like that.

@jagajaga
Copy link
Member

jagajaga commented Jan 3, 2015

Why won't you use nixos-containers?

@lucabrunox
Copy link
Contributor

@jagajaga because one doesn't always need a container? I'm also interested in multiple services on the same machine without using containers. Containers are probably a good solution for distros like debian, but in nixos we have the possibility to run multiple services, and that's sometimes better in certain setups.

@jagajaga
Copy link
Member

jagajaga commented Jan 3, 2015

@lethalman yeah, you are right, thx.
Maybe I will say something weird, but maybe it's better (in future ofc) to create more general solution? Not only for mysql, but for every service add a possibility to run multiply instances of it.

@lucabrunox
Copy link
Contributor

@jagajaga I just proposed it, and it's a simple helper function multipleInstances if you read my comment above.

@jagajaga
Copy link
Member

jagajaga commented Jan 3, 2015

@lethalman oops, missed it :)

@offlinehacker
Copy link
Contributor

@lethalman can you give example how this would work, i'm trying to
implement something like this in service abstractio layer i'm working on.
At the same time i don't want that service definitions becomes too
complicated.
On Jan 3, 2015 2:42 PM, "Arseniy Seroka" notifications@github.com wrote:

@lethalman https://github.com/lethalman oops, missed it :)


Reply to this email directly or view it on GitHub
#5542 (comment).

@lucabrunox
Copy link
Contributor

@offlinehacker much like this PR, except that instead of importing the module you have services.mysql.instances.<name>, so the name is taken from that. I don't have any implementation atm, I count on working on it in a week when I go back home. But should be a simple config = mkMerge (map makeMysqlConfig services.mysql.instances), or such, where makeMysqlConfig is the current config for one mysql instance.

@MarcWeber
Copy link
Contributor Author

What about services.mysqls.? Then we could stay backward compatible (services.mysql)

@MarcWeber
Copy link
Contributor Author

This is related #5271

@MarcWeber MarcWeber force-pushed the submit/multiple-mysqld-instances branch from f806c26 to 896f6ef Compare January 15, 2015 20:53
@MarcWeber
Copy link
Contributor Author

This update implements .instances as supported by pierron, me, Eelco. Now that I understood that there is a use case for mysql.systemPackage I dropped the idea of using the shorter services.mysqls.name version.

This also introduces resource tracking so that two mysql instances don't use same port or socket by accident.

@offlinehacker
Copy link
Contributor

I will handle everything in service abstraction layer i'm working on.
Resource tracking is alrerady implemented. I've not yet decide how to
implement support for multiple services in simple way, but will figure out,
i am open for ideas.
On Jan 15, 2015 9:57 PM, "Marc Weber" notifications@github.com wrote:

This update implements .instances as supported by pierron, me, Eelco. Now
that I understood that there is a use case for mysql.systemPackage I
dropped the idea of using the shorter services.mysqls.name version.

This also introduces resource tracking so that two mysql instances don't
use same port or socket by accident.


Reply to this email directly or view it on GitHub
#5542 (comment).

@offlinehacker
Copy link
Contributor

I also don't like proposed solution, because it handles only very limited use case...

@offlinehacker
Copy link
Contributor

Thing that bothers me the most is that interface for MySQL is now changed. I think it could be done without changing old interface.

@MarcWeber MarcWeber force-pushed the submit/multiple-mysqld-instances branch from 896f6ef to 364e9f1 Compare January 15, 2015 23:15
@MarcWeber
Copy link
Contributor Author

@offlinehacker I have a problem now. If you're ready with something better I'me fine. Till then I'd like to solve my problem (importing huge databases which is done fastest on tmpfs).

@nbp I dropped the assertion. The case where it fails doesn't happen. I disagree though: I think assertions are just ways to make sure that below a line some properties hold.

@offlinehacker In which way does the interface change for you? If you have a close look at the patch it should preserve the old interface because it takes into account services.mysql as well as services.instances.*. It just happens that services.mysql will get the same name as instances.mysql - thus you can use either old or new - but you'll run into problems using old and instances.mysql - because both will try to create a mysql user.

@MarcWeber
Copy link
Contributor Author

@offlinehacker I think nixos doesn't solve all problems well - eg moving a live PHP project from one server to another cannot just be expressed in a configuration.nix file .. For this reason I wonder which is the most important task to work on. Still nixos/nixpkgs could be a starting point to get there. But that's a different story.

@offlinehacker
Copy link
Contributor

Yeah you are kinda right, i must admit that i'm sometimes kinda angry on
the way things are in nixos, especially because they are so nixos centric,
but i(and many other people) would like to use nixos services on anything
but nixos.

Actually your solution is pretty good, the only thing i don't like is how
resources are handled If you take a look into my service abstraction layer
approach, you can see i took a different approach, where services asks for
resources and they are handled and provided by some other abstraction.

@offlinehacker https://github.com/offlinehacker I think nixos doesn't
solve all problems well - eg moving a live PHP project from one server to
another cannot just be expressed in a configuration.nix file .. For this
reason I wonder which is the most important task to work on. Still
nixos/nixpkgs could be a starting point to get there. But that's a
different story.


Reply to this email directly or view it on GitHub
#5542 (comment).

@lucabrunox
Copy link
Contributor

I've opened an issue here with a proposal of mkMultiInstance and also a problem: #6784

…e times by

accident.

Example usage:

  config.resources.tcp-ports.80.required_by = "httpd Apache";
  config.resources.tcp-ports.443.required_by = "httpd Apache SSL";

  config.resources.uids.2000.required_by = "mysql user";
  config.resources.gids.2000.required_by = "mysql user";

  # you might have two mysql instances running using the same gid/uids:
  config.resources.uids.2000.allowCollisions = true;
  config.resources.gids.2000.allowCollisions = true;
Usage example:

  # traditional:
  services.mysql.enable = true;
  services.mysql.package = pkgs.mysql57;

  # add additional instance, eg on tmpfs mounted /tmp for developping:
  service.mysql.services.mysql_on_tmp = {
    enable = true;
    port = 3307;
    package = pkgs.mysql57;
    dataDir = "/tmp/mysql";
    socketDir = "/tmp/mysql_tmpfs.socket";
    uid = 20000;
    gid = 20000;
  };
@MarcWeber MarcWeber force-pushed the submit/multiple-mysqld-instances branch from 364e9f1 to dd1df4c Compare June 11, 2016 13:26
@grahamc
Copy link
Member

grahamc commented Aug 26, 2016

In case people are interested in a more immediate solution to this, you can use NixOS containers out of the box already and configure mysql instances inside of that, using the host networking, listening on a different port. I did that today and ran about 30 instances locally.

@domenkozar
Copy link
Member

As noted by @grahamc we just can't support running multiple services of everything we have in nixos modules, but you can do that using containers today.

@domenkozar domenkozar closed this Jun 20, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants