This repository has been archived by the owner on May 21, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 43
/
Copy pathdev-server
executable file
·113 lines (96 loc) · 2.69 KB
/
dev-server
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
#!/usr/bin/perl
use local::lib;
use v5.10;
use strict;
use warnings;
use List::Util qw( any );
use Mojo::Server::Morbo ();
use Time::HiRes qw( sleep );
$| = 1;
my @switches = grep {/^-/} @ARGV;
$ENV{DEBUG} = 1;
$ENV{LOGBOT_CONFIG} = join(',', grep { !/^-/ } @ARGV) || '_development';
$ENV{LOGBOT_STATUS_PASSWORD} = '';
# asset watch
{
my $pid = fork();
if (defined($pid) && $pid == 0) {
my $make = Make->new();
while (1) {
$make->execute() if $make->updated();
sleep(0.25);
}
}
}
# memcached
if (!any { $_ eq '--no-cache' } @switches) {
my $pid = fork();
if (defined($pid) && $pid == 0) {
my $verbose = any { $_ eq '-v' || $_ eq '--verbose' } @switches;
## no critic (InputOutput::RequireBriefOpen)
open(my $mc, '-|', 'memcached -vv 2>&1') || die "failed to start memcached: $!\n";
say 'memcached listening on :11211' unless $verbose;
while (<$mc>) {
next unless $verbose;
next
if /^slab class/
|| /^<\d+ new auto-negotiating/
|| /^<\d+ connection closed/
|| /^\d+: Client using/;
print 'memcached: ', $_;
}
close($mc) || die $!;
## use critic
exit;
}
}
# web server
my $morbo = Mojo::Server::Morbo->new();
$morbo->backend->watch(['web/templates/', 'web/templates/layouts/', 'lib/LogBot', 'lib/Logbot/Web']);
$morbo->run('logbot-web');
package Make;
use strict;
use v5.10;
use warnings;
use FindBin qw( $RealBin );
use lib "$RealBin/lib";
use LogBot::Util qw( file_time run );
sub new {
my ($class) = @_;
return bless({ make => "$RealBin/dev-make", ts => 0, first => 1 }, $class);
}
sub execute {
my ($self) = @_;
run($self->{make}, delete $self->{first} ? '-q' : '', delete $self->{all} ? '-B' : '');
}
sub updated {
my ($self) = @_;
if (file_time($self->{make}) != $self->{ts}) {
$self->{all} = $self->{ts} != 0;
$self->{ts} = file_time($self->{make});
$self->{files} = $self->_prerequisites();
$self->{files_ts} = {};
}
my $updated = 0;
foreach my $file (@{ $self->{files} }) {
if (!-e $file) {
$self->{ts} = 0;
$updated = 1;
} else {
my $ts = file_time($file);
if ($ts != ($self->{files_ts}->{$file} // 0)) {
$updated = 1;
}
$self->{files_ts}->{$file} = $ts;
}
}
return $updated;
}
sub _prerequisites {
my ($self) = @_;
open(my $dm, '-|', $self->{make}, 'deps') or die $!;
chomp(my @files = <$dm>);
close($dm) or die $!;
return \@files;
}
1;