-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathrunserver.pl
executable file
·68 lines (50 loc) · 2.54 KB
/
runserver.pl
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
#!/usr/bin/env perl
# vim: set ft=perl:
## this file is part of sylspace, released under the AGPL, 2016, authored by ivo welch, ucla.
## one additional condition requires the prominent posting of the name (sylspace) and the author.
use strict;
use warnings;
use common::sense;
use utf8;
use feature ':5.20';
use warnings FATAL => qw{ uninitialized };
use autodie;
use File::Which;
my $isproduction= (`hostname` =~ /syllabus/m);
my $isosx= (-d "/Users/ivo");
my @apphome;
if ($isosx) {
($isproduction && $isosx) and die "iaw: please do not run the $ENV{MOJO_DOMAINNAME} domain on an osx host.\n";
((-e 'SylSpace') && (-x 'SylSpace')) or die "on macos, you must be in the local directory in which SylSpace lives!";
@apphome= (`pwd`);
} else {
@apphome= grep { $_ =~ /SylSpace$/ } `locate SylSpace/SylSpace`; ## locate sylspace/SylSpace works on linux, but not macos
@apphome = grep { $_ !~ m{\/\.[a-z]}i } @apphome; ## a hidden directory in path, e.g., .sync or .git
@apphome = grep { $_ !~ m{\bold\b}i } @apphome; ## an "old" somewhere
## @apphome = grep { $_ =~ m{sylspace\/SylSpace$} } @apphome; ## we have very specific ideas of how we like this one
((scalar @apphome)>1) and die "Ambiguous SylSpace locations:\n\t".join(" ", @apphome).
"\nPlease test on non-production servers, not on the same server.\n";
((scalar @apphome)<1) and die "Cannot locate executable SylSpace on $^O:: '".`locate sylspace/SylSpace`."'. did you run updatedb? \n";
}
chomp($apphome[0]);
(my $workdir= $apphome[0]) =~ s{\/SylSpace$}{};
print STDERR "running $apphome[0] in $workdir\n";
(-e $workdir) or die "$0: internal weird error. no $workdir!\n";
(-d $workdir) or die "$0: internal weird error. no $workdir!\n";
chdir($workdir) or die "failed to change directory to $workdir: $!\n";
if ($isproduction) {
print STDERR "$0: Running full production hypnotoad server for sylspace. To stop:
kill -QUIT `cat hypnotoad.pid` gracefully (or -TERM), or
/usr/local/bin/hypnotoad -s ./SylSpace)\n\t\tPS: morbo -v -m production ./SylSpace for testing\n";
echosystem("/usr/local/bin/hypnotoad -f ./SylSpace"); ## do not '&', or it fails in systemd SylSpace.service !
} else {
my $mode= ((@ARGV) && (defined($ARGV[0])) && ($ARGV[0] =~ /^p/i)) ? "production" : "development";
print STDERR "$0: running morbo for lvh.me in $mode mode.\n";
my $executable = which 'morbo';
(-x $executable) or die "cannot find suitable morbo executable.\n";
echosystem("$executable -v -m $mode ./SylSpace");
}
sub echosystem {
print STDERR "\nEXECUTING SYSTEM: '$_[0]'\n";
system $_[0];
}