forked from engineerOfLies/rabbitmqphp_example
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmonitor.php
More file actions
executable file
·34 lines (27 loc) · 855 Bytes
/
monitor.php
File metadata and controls
executable file
·34 lines (27 loc) · 855 Bytes
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
#!/usr/bin/php
<?php
$watchDir = '/home/markcgv/git/Builds';
$apacheRestartCmd = 'sudo systemctl restart apache2';
$inotifyCmd = "inotifywait -m -e create '$watchDir'";
echo "Monitoring directory: $watchDir for new files...\n";
echo "Press [Ctrl+C] to stop.\n";
$handle = popen($inotifyCmd, 'r');
if ($handle) {
while (!feof($handle)) {
$line = fgets($handle);
if ($line) {
echo "New file detected: $line";
echo "Restarting Apache...\n";
exec($apacheRestartCmd, $output, $returnVar);
if ($returnVar === 0) {
echo "Apache restarted successfully!\n";
} else {
echo "Failed to restart Apache. Check permissions or system logs.\n";
}
}
}
pclose($handle);
} else {
echo "Failed to start inotifywait.\n";
}
?>