mirror of
https://github.com/NixOS/nixpkgs.git
synced 2024-10-31 22:51:22 +00:00
Merge pull request #81292 from hercules-ci/fix-service-runner-quotes
nixos/service-runner.nix: Allow quotes in commands + test
This commit is contained in:
commit
6734e58da3
@ -12,7 +12,10 @@ let
|
||||
|
||||
sub run {
|
||||
my ($cmd) = @_;
|
||||
my @args = split " ", $cmd;
|
||||
my @args = ();
|
||||
while ($cmd =~ /([^ \t\n']+)|(\'([^'])\')\s*/g) {
|
||||
push @args, $1;
|
||||
}
|
||||
my $prog;
|
||||
if (substr($args[0], 0, 1) eq "@") {
|
||||
$prog = substr($args[0], 1);
|
||||
@ -48,15 +51,20 @@ let
|
||||
'') service.environment)}
|
||||
|
||||
# Run the ExecStartPre program. FIXME: this could be a list.
|
||||
my $preStart = '${service.serviceConfig.ExecStartPre or ""}';
|
||||
if ($preStart ne "") {
|
||||
my $preStart = <<END_CMD;
|
||||
${service.serviceConfig.ExecStartPre or ""}
|
||||
END_CMD
|
||||
if (defined $preStart && $preStart ne "\n") {
|
||||
print STDERR "running ExecStartPre: $preStart\n";
|
||||
my $res = run_wait $preStart;
|
||||
die "$0: ExecStartPre failed with status $res\n" if $res;
|
||||
};
|
||||
|
||||
# Run the ExecStart program.
|
||||
my $cmd = '${service.serviceConfig.ExecStart}';
|
||||
my $cmd = <<END_CMD;
|
||||
${service.serviceConfig.ExecStart}
|
||||
END_CMD
|
||||
|
||||
print STDERR "running ExecStart: $cmd\n";
|
||||
my $mainPid = run $cmd;
|
||||
$ENV{'MAINPID'} = $mainPid;
|
||||
@ -70,8 +78,10 @@ let
|
||||
$SIG{'QUIT'} = \&intHandler;
|
||||
|
||||
# Run the ExecStartPost program.
|
||||
my $postStart = '${service.serviceConfig.ExecStartPost or ""}';
|
||||
if ($postStart ne "") {
|
||||
my $postStart = <<END_CMD;
|
||||
${service.serviceConfig.ExecStartPost or ""}
|
||||
END_CMD
|
||||
if (defined $postStart && $postStart ne "\n") {
|
||||
print STDERR "running ExecStartPost: $postStart\n";
|
||||
my $res = run_wait $postStart;
|
||||
die "$0: ExecStartPost failed with status $res\n" if $res;
|
||||
@ -82,8 +92,10 @@ let
|
||||
my $mainRes = $?;
|
||||
|
||||
# Run the ExecStopPost program.
|
||||
my $postStop = '${service.serviceConfig.ExecStopPost or ""}';
|
||||
if ($postStop ne "") {
|
||||
my $postStop = <<END_CMD;
|
||||
${service.serviceConfig.ExecStopPost or ""}
|
||||
END_CMD
|
||||
if (defined $postStop && $postStop ne "\n") {
|
||||
print STDERR "running ExecStopPost: $postStop\n";
|
||||
my $res = run_wait $postStop;
|
||||
die "$0: ExecStopPost failed with status $res\n" if $res;
|
||||
|
@ -263,6 +263,7 @@ in
|
||||
samba = handleTest ./samba.nix {};
|
||||
sanoid = handleTest ./sanoid.nix {};
|
||||
sddm = handleTest ./sddm.nix {};
|
||||
service-runner = handleTest ./service-runner.nix {};
|
||||
shiori = handleTest ./shiori.nix {};
|
||||
signal-desktop = handleTest ./signal-desktop.nix {};
|
||||
simple = handleTest ./simple.nix {};
|
||||
|
36
nixos/tests/service-runner.nix
Normal file
36
nixos/tests/service-runner.nix
Normal file
@ -0,0 +1,36 @@
|
||||
import ./make-test-python.nix ({ pkgs, ... }: {
|
||||
name = "service-runner";
|
||||
meta = with pkgs.stdenv.lib.maintainers; {
|
||||
maintainers = [ roberth ];
|
||||
};
|
||||
|
||||
nodes = {
|
||||
machine = { pkgs, lib, ... }: {
|
||||
services.nginx.enable = true;
|
||||
services.nginx.virtualHosts.machine.root = pkgs.runCommand "webroot" {} ''
|
||||
mkdir $out
|
||||
echo 'yay' >$out/index.html
|
||||
'';
|
||||
systemd.services.nginx.enable = false;
|
||||
};
|
||||
|
||||
};
|
||||
|
||||
testScript = { nodes, ... }: ''
|
||||
url = "http://localhost/index.html"
|
||||
|
||||
with subtest("check systemd.services.nginx.runner"):
|
||||
machine.fail(f"curl {url}")
|
||||
machine.succeed(
|
||||
"""
|
||||
mkdir -p /run/nginx /var/spool/nginx/logs
|
||||
${nodes.machine.config.systemd.services.nginx.runner} &
|
||||
echo $!>my-nginx.pid
|
||||
"""
|
||||
)
|
||||
machine.wait_for_open_port(80)
|
||||
machine.succeed(f"curl {url}")
|
||||
machine.succeed("kill -INT $(cat my-nginx.pid)")
|
||||
machine.wait_for_closed_port(80)
|
||||
'';
|
||||
})
|
Loading…
Reference in New Issue
Block a user