Repository navigation
Expand file tree
/
Copy pathrun-local.php
More file actions
executable file
·85 lines (75 loc) · 2.99 KB
/
Copy pathrun-local.php
File metadata and controls
executable file
·85 lines (75 loc) · 2.99 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
#!/usr/bin/env php
<?php
if (PHP_SAPI !== 'cli') {
fwrite(STDERR, "run-local.php must be run from the command line.\n");
exit(1);
}
$host = $argv[1] ?? 'localhost';
$port = (int)($argv[2] ?? 2525);
$docroot = __DIR__ . DIRECTORY_SEPARATOR . 'storm-web';
if (!is_dir($docroot)) {
fwrite(STDERR, "storm-web directory not found at: {$docroot}\n");
exit(1);
}
if ($port < 1 || $port > 65535) {
fwrite(STDERR, "Invalid port: {$port}\n");
exit(1);
}
// Preflight: verify writable directories exist and are accessible.
// After a full deploy.sh run these are owned by the service user
// (stormbreaker), so a regular user can't write to them.
$writable_dirs = ['data', 'targets', 'log'];
$issues = [];
foreach ($writable_dirs as $name) {
$dir = $docroot . DIRECTORY_SEPARATOR . $name;
if (!is_dir($dir)) {
@mkdir($dir, 0755, true);
}
if (!is_dir($dir)) {
$issues[] = " {$name}/ — cannot create directory";
} elseif (!is_writable($dir)) {
$owner = function_exists('posix_getpwuid') ? (posix_getpwuid(fileowner($dir))['name'] ?? '?') : '?';
$issues[] = " {$name}/ — not writable (owned by {$owner})";
}
}
if (!empty($issues)) {
fwrite(STDERR, "WARNING: some directories are not writable by the current user:\n");
foreach ($issues as $line) {
fwrite(STDERR, $line . "\n");
}
fwrite(STDERR, "\nThis usually happens after running deploy.sh (which locks\n");
fwrite(STDERR, "permissions for the systemd service user). Fix with:\n\n");
fwrite(STDERR, " sudo chown -R \$(whoami) storm-web/data storm-web/targets storm-web/log\n\n");
}
// Check that config.php exists (needed for login).
$config = $docroot . DIRECTORY_SEPARATOR . 'config.php';
if (!is_file($config)) {
fwrite(STDERR, "NOTE: storm-web/config.php not found — you'll need to\n");
fwrite(STDERR, "run deploy.sh first, or create it manually.\n\n");
} elseif (!is_readable($config)) {
fwrite(STDERR, "WARNING: storm-web/config.php is not readable by the current user.\n");
fwrite(STDERR, "Fix with: sudo chmod o+r storm-web/config.php\n\n");
}
echo "Storm-Breaker — local development server\n";
echo "URL: http://{$host}:{$port}\n";
echo "Docroot: {$docroot}\n";
echo "Stop: Ctrl+C\n\n";
$router = $docroot . DIRECTORY_SEPARATOR . 'router.php';
if (!is_file($router)) {
fwrite(STDERR, "router.php not found at: {$router}\n");
exit(1);
}
// -d display_errors=stderr → PHP warnings go to the terminal, not into
// HTTP response bodies (which would corrupt JSON API responses).
// -d html_errors=off → if a fatal error leaks into the response despite
// the above, it comes as plain text, not <br /><b> tags that break JSON.
// -d log_errors=1 → errors are always logged.
$cmd = sprintf(
'php -d display_errors=stderr -d html_errors=off -d log_errors=1 -S %s:%d -t %s %s',
escapeshellarg($host),
$port,
escapeshellarg($docroot),
escapeshellarg($router)
);
passthru($cmd, $code);
exit($code);