Introduction link
I used this kind of script because it’s simpler to open a small web page to view VM activity rather than launching a bunch of commands.
You need sudo because by default Apache doesn’t have the necessary rights to execute these commands:
Then edit /etc/sudoers
and add the following:
1
| www-data ALL=NOPASSWD: /usr/sbin/vserver-stat,/usr/sbin/xm list
|
Php and script link
You obviously need to have Apache and PHP installed for this to work:
1
| apt-get install apache2 php5
|
Additionally, there’s a small JavaScript that refreshes the page every 60 seconds.
Then create a folder and copy this into an index file:
1
| mkdir /var/www/virtual && vi /var/www/virtual/index.php
|
Here’s the content of index.php:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
| <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<script language="javascript" type="text/javascript">
setTimeout("location.reload();", 600000);
</script>
<head>
<meta content="text/html; charset=ISO-8859-1" http-equiv="content-type" />
<title>Informations for Virtual Machines</title>
</head>
<body>
<?php
system("date +%c") ;
echo("<BR><br />--- Vservers informations ---<br />") ;
echo("<syntaxhighlight lang="text"
>\n") ; system("sudo /usr/sbin/vserver-stat") ; echo("</syntaxhighlight
>\n") ; echo("<br />") ; echo("--- Xen informations ---<br />") ;
echo("<syntaxhighlight lang="text"
>\n") ; system("sudo /usr/sbin/xm list") ; echo("</syntaxhighlight
>") ; ?>
</body>
</html>
|
Now set the proper permissions:
1
| chown -Rf www-data. /var/www/virtual
|
All that’s left is to access it :-)
Last updated
14 May 2007, 10:09 CEST. history