nixos/beanstalkd: new service for existing package (#55953)
This commit is contained in:
parent
b6c82183be
commit
e5405f9ae8
|
@ -91,6 +91,11 @@
|
|||
in <literal>nixos/modules/virtualisation/google-compute-config.nix</literal>.
|
||||
</para>
|
||||
</listitem>
|
||||
<listitem>
|
||||
<para>
|
||||
<literal>./services/misc/beanstalkd.nix</literal>
|
||||
</para>
|
||||
</listitem>
|
||||
</itemizedlist>
|
||||
</section>
|
||||
|
||||
|
|
|
@ -361,6 +361,7 @@
|
|||
./services/misc/apache-kafka.nix
|
||||
./services/misc/autofs.nix
|
||||
./services/misc/autorandr.nix
|
||||
./services/misc/beanstalkd.nix
|
||||
./services/misc/bees.nix
|
||||
./services/misc/bepasty.nix
|
||||
./services/misc/canto-daemon.nix
|
||||
|
|
52
nixos/modules/services/misc/beanstalkd.nix
Normal file
52
nixos/modules/services/misc/beanstalkd.nix
Normal file
|
@ -0,0 +1,52 @@
|
|||
{ config, lib, pkgs, ... }:
|
||||
|
||||
with lib;
|
||||
|
||||
let
|
||||
cfg = config.services.beanstalkd;
|
||||
pkg = pkgs.beanstalkd;
|
||||
in
|
||||
|
||||
{
|
||||
# interface
|
||||
|
||||
options = {
|
||||
services.beanstalkd = {
|
||||
enable = mkEnableOption "Enable the Beanstalk work queue.";
|
||||
|
||||
listen = {
|
||||
port = mkOption {
|
||||
type = types.int;
|
||||
description = "TCP port that will be used to accept client connections.";
|
||||
default = 11300;
|
||||
};
|
||||
|
||||
address = mkOption {
|
||||
type = types.str;
|
||||
description = "IP address to listen on.";
|
||||
default = "127.0.0.1";
|
||||
example = "0.0.0.0";
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
# implementation
|
||||
|
||||
config = mkIf cfg.enable {
|
||||
|
||||
environment.systemPackages = [ pkg ];
|
||||
|
||||
systemd.services.beanstalkd = {
|
||||
description = "Beanstalk Work Queue";
|
||||
after = [ "network.target" ];
|
||||
wantedBy = [ "multi-user.target" ];
|
||||
serviceConfig = {
|
||||
DynamicUser = true;
|
||||
Restart = "always";
|
||||
ExecStart = "${pkg}/bin/beanstalkd -l ${cfg.listen.address} -p ${toString cfg.listen.port}";
|
||||
};
|
||||
};
|
||||
|
||||
};
|
||||
}
|
|
@ -25,6 +25,7 @@ in
|
|||
atd = handleTest ./atd.nix {};
|
||||
avahi = handleTest ./avahi.nix {};
|
||||
bcachefs = handleTestOn ["x86_64-linux"] ./bcachefs.nix {}; # linux-4.18.2018.10.12 is unsupported on aarch64
|
||||
beanstalkd = handleTest ./beanstalkd.nix {};
|
||||
beegfs = handleTestOn ["x86_64-linux"] ./beegfs.nix {}; # beegfs is unsupported on aarch64
|
||||
bind = handleTest ./bind.nix {};
|
||||
bittorrent = handleTest ./bittorrent.nix {};
|
||||
|
|
43
nixos/tests/beanstalkd.nix
Normal file
43
nixos/tests/beanstalkd.nix
Normal file
|
@ -0,0 +1,43 @@
|
|||
import ./make-test.nix ({ pkgs, lib, ... }:
|
||||
|
||||
let
|
||||
produce = pkgs.writeScript "produce.py" ''
|
||||
#!${pkgs.python2.withPackages (p: [p.beanstalkc])}/bin/python
|
||||
import beanstalkc
|
||||
|
||||
queue = beanstalkc.Connection(host='localhost', port=11300, parse_yaml=False);
|
||||
queue.put('this is a job')
|
||||
queue.put('this is another job')
|
||||
'';
|
||||
|
||||
consume = pkgs.writeScript "consume.py" ''
|
||||
#!${pkgs.python2.withPackages (p: [p.beanstalkc])}/bin/python
|
||||
import beanstalkc
|
||||
|
||||
queue = beanstalkc.Connection(host='localhost', port=11300, parse_yaml=False);
|
||||
|
||||
job = queue.reserve(timeout=0)
|
||||
print job.body
|
||||
job.delete()
|
||||
'';
|
||||
|
||||
in
|
||||
{
|
||||
name = "beanstalkd";
|
||||
meta.maintainers = [ lib.maintainers.aanderse ];
|
||||
|
||||
machine =
|
||||
{ ... }:
|
||||
{ services.beanstalkd.enable = true;
|
||||
};
|
||||
|
||||
testScript = ''
|
||||
startAll;
|
||||
|
||||
$machine->waitForUnit('beanstalkd.service');
|
||||
|
||||
$machine->succeed("${produce}");
|
||||
$machine->succeed("${consume}") eq "this is a job\n" or die;
|
||||
$machine->succeed("${consume}") eq "this is another job\n" or die;
|
||||
'';
|
||||
})
|
Loading…
Reference in a new issue