-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathentrypoint
executable file
·106 lines (82 loc) · 2.98 KB
/
entrypoint
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
#!/usr/bin/env php
<?php
empty(getenv('DB_CONNECTION')) && putenv("DB_CONNECTION=sqlite");
# Workers settings
empty(getenv('HTTP_NUM_WORKERS')) && putenv("HTTP_NUM_WORKERS=4");
if (getenv('DB_CONNECTION') == 'sqlite') {
$databaseFile = getenv('DB_DATABASE');
if (empty($databaseFile)) {
$databaseFile = "database.sqlite";
putenv("DB_DATABASE=database.sqlite");
}
if (!file_exists($databaseFile) || filesize($databaseFile) == 0) {
system('touch ' . $databaseFile);
system('php artisan migrate --force');
system('php artisan db:seed --class=ClientCertificatesTableSeeder');
system('php artisan db:seed --class=GamesTableSeeder');
system('php artisan db:seed --class=GameModsTableSeeder');
system('php artisan db:seed --class=UsersTableSeeder');
system('php artisan db:seed --class=PermissionsSeeder');
} else {
system('php artisan migrate');
}
}
else if (getenv('DB_CONNECTION') == 'mysql') {
$connectTries = 5;
$sleepTime = 5;
while ($connectTries > 0) {
$connectTries--;
try {
$pdo = new PDO(
'mysql:host=' . getenv('DB_HOST') . ';dbname=' . getenv('DB_DATABASE'),
getenv('DB_USERNAME'),
getenv('DB_PASSWORD')
);
break;
} catch (PDOException $e) {
echo "Waiting mysql...\n";
sleep($sleepTime);
$sleepTime *= 2;
if ($connectTries <= 0) {
echo "Error: " . $e->getMessage() . "\n";
exit(1);
}
}
}
system('php artisan migrate --force');
$count = $pdo->query("SELECT COUNT(*) as count FROM users;")->fetch(PDO::FETCH_ASSOC)['count'];
if ($count == 0) {
system('php artisan db:seed --class=ClientCertificatesTableSeeder');
system('php artisan db:seed --class=GamesTableSeeder');
system('php artisan db:seed --class=GameModsTableSeeder');
system('php artisan db:seed --class=UsersTableSeeder');
system('php artisan db:seed --class=PermissionsSeeder');
}
}
$adminPassword = !empty(getenv('ADMIN_PASSWORD'))
? getenv('ADMIN_PASSWORD')
: base64_encode(random_bytes(12));
system("php artisan user:change-password admin {$adminPassword}");
$rrConfigNumWorkers = getenv('HTTP_NUM_WORKERS');
$rrConfig = <<<YAML
rpc:
listen: tcp://127.0.0.1:6001
server:
command: "php ./vendor/bin/rr-worker start --relay-dsn unix:///var/www/gameap/rr-relay.sock"
relay: "unix:///var/www/gameap/rr-relay.sock"
http:
address: 0.0.0.0:8080
static:
dir: public
forbid: [".php", ".htaccess"]
YAML;
file_put_contents('.rr.yaml', $rrConfig);
echo "\n--------------------------------------\n";
echo "GameAP starting...\n";
if (isset($adminPassword)) {
echo "Admin login: admin\n";
echo "Admin password: {$adminPassword}\n";
}
echo "\n--------------------------------------\n";
echo "\n\n";
system('./rr -c .rr.yaml serve -d');