-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathinstall.php
104 lines (95 loc) · 2.53 KB
/
install.php
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
<?php
require_once("vendor/autoload.php");
$climate = new League\CLImate\CLImate;
if (trim(shell_exec("whoami")) != "root")
{
$climate->shout("Please run this installer as root.");
return;
}
$climate->white("Creating sonarpoller user... ");
try {
if (!file_exists("/home/sonarpoller"))
{
execCommand("/usr/sbin/useradd -m -d /home/sonarpoller sonarpoller");
}
}
catch (RuntimeException $e)
{
$climate->shout("FAILED!");
return;
}
$climate->lightGreen("OK!");
$climate->white("Installing to /opt/poller... ");
try {
if (!file_exists("/opt/poller"))
{
execCommand("/bin/mkdir /opt/poller");
}
execCommand("/bin/cp -R " . dirname(__FILE__) ."/. /opt/poller/");
execCommand("/bin/chown -R sonarpoller:sonarpoller /opt/poller/.");
}
catch (RuntimeException $e)
{
$climate->shout("FAILED!");
return;
}
$climate->lightGreen("OK!");
$climate->white("Setting up scheduler... ");
try {
execCommand("/bin/cp " . dirname(__FILE__) . "/sonar_poll_scheduler /etc/cron.d/");
execCommand("/bin/chmod 0644 /etc/cron.d/sonar_poll_scheduler");
}
catch (RuntimeException $e)
{
$climate->shout("FAILED!");
return;
}
$climate->lightGreen("OK!");
$climate->white("Configuring queue listeners... ");
try {
execCommand("/bin/cp conf/monitrc /etc/monit/");
execCommand("/bin/cp " . dirname(__FILE__) . "/conf/default /etc/monit/conf.d/");
execCommand("/usr/sbin/service monit reload");
sleep(3);
execCommand("/usr/bin/monit start defaultQueue");
}
catch (RuntimeException $e)
{
$climate->shout("Failed, but this may be due to a bug in monit (https://bugs.launchpad.net/ubuntu/+source/monit/+bug/1786910) - continuing anyway.");
}
$climate->lightGreen("OK!");
$climate->white("Configuring SNMP MIBs... ");
try {
execCommand("/bin/sed -i 's/^mibs :/#mibs :/g' /etc/snmp/snmp.conf");
}
catch (RuntimeException $e)
{
$climate->shout("FAILED!");
return;
}
$climate->lightGreen("OK!");
$climate->white("Setting up log file... ");
try {
execCommand("/usr/bin/touch /var/log/sonar_poller.log");
execCommand("/bin/chown sonarpoller:sonarpoller /var/log/sonar_poller.log");
execCommand("/bin/cp conf/sonarpoller /etc/logrotate.d/");
}
catch (RuntimeException $e)
{
$climate->shout("FAILED!");
return;
}
$climate->lightGreen("OK!");
/**
* @param $command
* @return mixed
*/
function execCommand($command)
{
exec($command,$output,$returnVar);
if ($returnVar !== 0)
{
throw new RuntimeException("Failed to execute $command");
}
return $output;
}