system reboot

This commit is contained in:
Serghey Rodin 2013-10-23 14:01:43 +03:00
commit 465e8bfa18
6 changed files with 157 additions and 8 deletions

View file

@ -52,7 +52,7 @@ ARCH=$(arch)
# Check uptime # Check uptime
UPTIME=$(cat /proc/uptime |cut -f 1 -d ' '|cut -f 1 -d .) UPTIME=$(cat /proc/uptime |cut -f 1 -d ' '|cut -f 1 -d .)
UPTIME="$(echo $UPTIME / 3600 | bc)" UPTIME="$(echo $UPTIME / 60 | bc)"
# Check LoadAverage # Check LoadAverage
LOADAVERAGE=$(cat /proc/loadavg |cut -f 1 -d ' ') LOADAVERAGE=$(cat /proc/loadavg |cut -f 1 -d ' ')
@ -61,21 +61,22 @@ LOADAVERAGE=$(cat /proc/loadavg |cut -f 1 -d ' ')
tmp_file=$(mktemp) tmp_file=$(mktemp)
# Define key/value pairs # Define key/value pairs
str="HOSTNAME='$HOSTNAME' OS='$OS' VERSION='$VERSION' ARCH='$ARCH'" str="SYS='sysinfo' HOSTNAME='$HOSTNAME' OS='$OS' VERSION='$VERSION'"
str="$str UPTIME='$UPTIME' LOADAVERAGE='$LOADAVERAGE'" str="$str ARCH='$ARCH' UPTIME='$UPTIME' LOADAVERAGE='$LOADAVERAGE'"
# Defining config # Defining config
echo -e "$str" > $tmp_file echo -e "$str" > $tmp_file
conf=$tmp_file conf=$tmp_file
# Defining fileds to select # Defining fileds to select
fields="\$HOSTNAME \$OS \$VERSION \$ARCH \$UPTIME \$LOADAVERAGE" fields="\$SYS \$HOSTNAME \$OS \$VERSION \$ARCH \$UPTIME \$LOADAVERAGE"
# Listing services # Listing services
case $format in case $format in
json) json_list ;; json) json_list ;;
plain) nohead=1; shell_list ;; plain) nohead=1; shell_list ;;
shell) shell_list | column -t ;; shell) fields="\$HOSTNAME \$OS \$VERSION \$ARCH \$UPTIME \$LOADAVERAGE"
shell_list | column -t ;;
*) check_args '1' '0' 'USER [FORMAT]' *) check_args '1' '0' 'USER [FORMAT]'
esac esac

39
bin/v-restart-system Executable file
View file

@ -0,0 +1,39 @@
#!/bin/bash
# info: restart operating system
# options: restart
#
# The function restarts operating system.
#----------------------------------------------------------#
# Variable&Function #
#----------------------------------------------------------#
# Argument defenition
restart=$1
# Includes
source $VESTA/func/main.sh
#----------------------------------------------------------#
# Verifications #
#----------------------------------------------------------#
check_args '1' "$#" 'RESTART'
#----------------------------------------------------------#
# Action #
#----------------------------------------------------------#
if [ "$restart" = 'yes' ]; then
/sbin/reboot
fi
#----------------------------------------------------------#
# Vesta #
#----------------------------------------------------------#
exit

View file

@ -19,6 +19,15 @@ if ($_SESSION['user'] == 'admin') {
break; break;
default: header("Location: /list/services/"); exit; default: header("Location: /list/services/"); exit;
} }
if ((!empty($_POST['system'])) && ($action == 'restart')) {
exec (VESTA_CMD."v-restart-system yes", $output, $return_var);
$_SESSION['error_srv'] = 'The system is going down for reboot NOW!';
unset($output);
header("Location: /list/services/");
exit;
}
foreach ($service as $value) { foreach ($service as $value) {
$value = escapeshellarg($value); $value = escapeshellarg($value);
exec (VESTA_CMD.$cmd." ".$value, $output, $return_var); exec (VESTA_CMD.$cmd." ".$value, $output, $return_var);

View file

@ -13,6 +13,9 @@ top_panel($user,$TAB);
// Data // Data
if ($_SESSION['user'] == 'admin') { if ($_SESSION['user'] == 'admin') {
exec (VESTA_CMD."v-list-sys-info json", $output, $return_var);
$sys = json_decode(implode('', $output), true);
unset($output);
exec (VESTA_CMD."v-list-sys-services json", $output, $return_var); exec (VESTA_CMD."v-list-sys-services json", $output, $return_var);
$data = json_decode(implode('', $output), true); $data = json_decode(implode('', $output), true);
unset($output); unset($output);

View file

@ -0,0 +1,17 @@
<?php
// Init
error_reporting(NULL);
ob_start();
session_start();
include($_SERVER['DOCUMENT_ROOT']."/inc/main.php");
if ($_SESSION['user'] == 'admin') {
if (!empty($_GET['hostname'])) {
exec (VESTA_CMD."v-restart-system yes", $output, $return_var);
$_SESSION['error_srv'] = 'The system is going down for reboot NOW!';
}
unset($output);
}
header("Location: /list/services/");
exit;

View file

@ -35,7 +35,7 @@
}); });
}); });
</script> </script>
<div id="dialog-message" title="Error"> <div id="dialog-message" title="">
<p><?php echo $_SESSION['error_srv'] ?></p> <p><?php echo $_SESSION['error_srv'] ?></p>
</div> </div>
</div> </div>
@ -50,6 +50,86 @@
<div id="vstobjects"> <div id="vstobjects">
<table class='data'> <table class='data'>
<tr class="data-row"">
<td class="data-dotted" width="150">
<table class="data-col1">
<tr><td><input type="checkbox" class="ch-toggle" name="system[]" value="<?php echo $sys['sysinfo']['HOSTNAME'] ?>" ></td></tr>
<tr><td class="data-active"><b><?php echo 'running' ?></b></td></tr>
</table>
</td>
<td class="data-dotted" width="830px">
<a href="/restart/system/?hostname=<?php echo $sys['sysinfo']['HOSTNAME'] ?>" class="data-controls">
<span>
<img src="/images/reload.png" width="6px" height="7px">
<?php print __('restart'); ?>
</span>
</a>
<table class="data-col2" width="830px">
<tr>
<td colspan=4 class="domain" style="padding: 0 0 0 4px;">
<b><?php echo $sys['sysinfo']['HOSTNAME'] ?></b>
</td>
</tr>
<tr>
<td style="vertical-align:top;" width="354px">
<table>
<tr>
<td>
<a class="counter-name">
<?php print __('Operating System'); ?>:
</a>
</td>
<td>
<a class="counter-value">
<?php echo $sys['sysinfo']['OS'] ?>
<?php echo $sys['sysinfo']['VERSION'] ?>
(<?php echo $sys['sysinfo']['ARCH'] ?>)
</a>
</td>
</tr>
</table>
</td>
<td style="vertical-align:top;" width="142px">
<table>
<tr>
<td class="counter-name">
<?php print __('LoadAverage');?>:
</td>
<td>
<a class="counter-value"> <?php echo $sys['sysinfo']['LOADAVERAGE'] ?></a>
</td>
</tr>
</table>
</td>
<td style="vertical-align:top;" width="34px">
<table>
<tr>
<td class="counter-name">
</td>
<td>
</td>
</tr>
</table>
</td>
<td style="vertical-align:top;" widht="280px">
<table>
<tr>
<td class="counter-name">
<?php print __('Uptime');?>:
</td>
<td>
<a class="counter-value"><?php echo humanize_time($sys['sysinfo']['UPTIME']) ?> </a>
</td>
</tr>
</table>
</td>
</tr>
</table>
</td>
</tr>
<?php <?php
foreach ($data as $key => $value) { foreach ($data as $key => $value) {
@ -107,7 +187,7 @@
<td style="vertical-align:top;" width="150px"> <td style="vertical-align:top;" width="150px">
<table> <table>
<tr> <tr>
<td class="counter-name"> <td class="counter-name" widht="">
<?php print __('CPU');?>: <?php print __('CPU');?>:
</td> </td>
<td> <td>
@ -128,7 +208,7 @@
</tr> </tr>
</table> </table>
</td> </td>
<td style="vertical-align:top;" > <td style="vertical-align:top;">
<table> <table>
<tr> <tr>
<td class="counter-name"> <td class="counter-name">