-
Notifications
You must be signed in to change notification settings - Fork 80
Expand file tree
/
Copy pathdockerrun.pl
More file actions
executable file
·113 lines (89 loc) · 3.58 KB
/
dockerrun.pl
File metadata and controls
executable file
·113 lines (89 loc) · 3.58 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
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 -w
# Run CloudCoder, and mysql, and apache2 in Docker, attempting to
# shut each down gracefully when a SIGTERM is received.
use strict;
use POSIX qw(pause);
use IO::Handle;
my $DATA_DIR = "/usr/local/share/cloudcoder";
STDOUT->autoflush(1);
STDERR->autoflush(1);
# ----------------------------------------------------------------------
# Main script
# ----------------------------------------------------------------------
print "Starting CloudCoder docker container...\n";
my $done = 0;
$SIG{TERM} = \&SigtermHandler;
my $version = `cat $DATA_DIR/CLOUDCODER_VERSION`;
chomp $version;
# Check to see whether a keystore has been generated for
# webapp/builder communiction.
CheckKeystore();
# Check to see whether we are still using the default
# initial snakeoil SSL cert, and if so, generate a
# new one.
CheckSnakeoilSSL();
# Start mysqld, CloudCoder, and apache2.
Run("service", "mysql", "start");
Run("sudo", "-u", "cloud", "/bin/bash", "-c",
"cd /home/cloud/webapp && java -jar cloudcoderApp-$version.jar start");
Run("service", "apache2", "start");
# Start integrated CloudCoder builder
Run("sudo", "-u", "builder", "/bin/bash", "-c",
"cd /home/builder/builder && java -jar cloudcoderBuilder-$version.jar start");
print "mysqld, CloudCoder webapp, apache2, and integrated CloudCoder builder are running...\n";
# Wait for SIGTERM.
# Note that there is a race here if SIGTERM arrives
# after $done is checked but before pause() is executed.
if (!$done) {
pause();
}
print "SIGTERM received, shutting down...\n";
# Shut down integrated CloudCoder builder
Run("sudo", "-u", "builder", "/bin/bash", "-c",
"cd /home/builder/builder && java -jar cloudcoderBuilder-$version.jar shutdown");
# Shut down apache2, CloudCoder webapp, and mysqld.
Run("service", "apache2", "stop");
Run("sudo", "-u", "cloud", "/bin/bash", "-c",
"cd /home/cloud/webapp && java -jar cloudcoderApp-$version.jar shutdown");
Run("service", "mysql", "stop");
print "Done\n";
# ----------------------------------------------------------------------
# Subroutines
# ----------------------------------------------------------------------
sub SigtermHandler {
$done = 1;
}
sub Run {
system(@_)/256 == 0 || die "Command $_[0] failed\n";
}
# Check the CloudCoder webapp jarfile to see if a keystore
# has been configured. If not, generate one and add it
# to the webapp and builder jarfiles.
sub CheckKeystore {
print "Checking keystore...\n";
my $keystoreSize = `fastjar tvf /home/cloud/webapp/cloudcoderApp-$version.jar | grep '/keystore\.jks' | tr -s ' ' | sed -e 's/^ *//' | cut -d ' ' -f 1`;
chomp $keystoreSize;
print "Keystore size is $keystoreSize\n";
if (!($keystoreSize =~ /^\d+$/) || $keystoreSize == 0) {
print "No keystore found in webapp/builder jarfiles, generating them.\n";
print "This is expected when CloudCoder is run (in a Docker container)\n";
print "for the first time.\n";
Run("cp", "bootstrap.pl", "/tmp");
Run("chmod", "755", "/tmp/bootstrap.pl");
Run("sudo", "-u", "cloud", "/tmp/bootstrap.pl", "generate-keystore");
}
}
# Check to see whether the initial "snakeoil" SSL certificate
# needs to be regenerated. It would be really bad for anyone
# to use the one that comes with the image, since the
# private key used for the initial one would then be known.
sub CheckSnakeoilSSL {
print "Checking snakeoil SSL cert...\n";
if (! -e "$DATA_DIR/SNAKEOIL_CERT_GENERATED") {
print "Regenerating snakeoil cert...\n";
$ENV{'DEBIAN_FRONTEND'} = 'noninteractive';
Run("make-ssl-cert", "generate-default-snakeoil", "--force-overwrite");
Run("touch", "$DATA_DIR/SNAKEOIL_CERT_GENERATED");
}
}
# vim:ts=2: