-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmdaemon
More file actions
executable file
·59 lines (39 loc) · 1.13 KB
/
mdaemon
File metadata and controls
executable file
·59 lines (39 loc) · 1.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#!/usr/bin/env perl
BEGIN {
unless ((exists $ENV{MUTATE_HOME}) and (-d $ENV{MUTATE_HOME})) {
die
"You must set MUTATE_HOME to the directory where Mutate is located.\n";
}
}
use 5.018_000;
use strict;
use warnings;
no if $] >= 5.018, warnings => "experimental::smartmatch";
no if $] >= 5.018, warnings => "experimental::lexical_subs";
use IO::File;
use DateTime;
use Mojolicious::Lite;
use IO::Async::Loop::Mojo;
plugin 'JSONConfig' => {file => "$ENV{MUTATE_HOME}/presets/mdaemon.settings"};
our $LOOP = IO::Async::Loop::Mojo->new();
get '/' => sub { my $self = shift; };
get '/:command' => sub {
my $self = shift;
my $tx = $self->req->json;
my $command = $self->param('command');
my $event =
IO::File->new("/tmp/.mutate/events/$command." . DateTime->now . "", "w");
$LOOP->add(
open my $shell, "$ENV{MUTATE_HOME}/$command $tx->{arguments} |";
my @output;
for (<$shell>) {
push @output, chomp $_;
}
close $shell;
if (defined $event) {
print $event "@output";
undef $event;
}
);
};
app->start;