Start/stop functions

This commit is contained in:
Jamie Cameron
2014-09-25 19:11:45 -07:00
parent 0153a70988
commit 85c9fb169d
12 changed files with 234 additions and 7 deletions

25
iscsi-tgtd/atboot.cgi Executable file
View File

@@ -0,0 +1,25 @@
#!/usr/local/bin/perl
# Change if the iscsi server is started at boot or not
use strict;
use warnings;
require './iscsi-tgtd-lib.pl';
&foreign_require("init");
our (%text, %config, %in);
&ReadParse();
&error_setup($text{'atboot_err'});
my $old = &init::action_status($config{'init_name'});
if ($old != 2 && $in{'boot'}) {
# Enable at boot
$old == 1 || &error(&text('atboot_einit',
"<tt>$config{'init_name'}</tt>"));
&init::enable_at_boot($config{'init_name'});
&webmin_log("atboot");
}
elsif ($old == 2 && !$in{'boot'}) {
# Disable at boot
&init::disable_at_boot($config{'init_name'});
&webmin_log("delboot");
}
&redirect("");

View File

@@ -1,4 +1,3 @@
config_file=/etc/tgt/tgtd.conf config_file=/etc/tgt/tgtd.conf
tgtadm=tgtadm tgtadm=tgtadm
pid_file=/var/run/tgtd.pid
init_name=tgtd init_name=tgtd

View File

@@ -1,4 +1,3 @@
config_file=iSCSI TGTD configuration file,0 config_file=iSCSI TGTD configuration file,0
tgtadm=Full path to tgtadm command,0 tgtadm=Full path to tgtadm command,0
pid_file=Full path to PID file(s),0
init_name=Bootup script name,0 init_name=Bootup script name,0

BIN
iscsi-tgtd/images/icon.gif Executable file

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.3 KiB

94
iscsi-tgtd/index.cgi Normal file
View File

@@ -0,0 +1,94 @@
#!/usr/local/bin/perl
# Display a list of iSCSI targets
use strict;
use warnings;
require './iscsi-tgtd-lib.pl';
our (%text, %config, $module_name);
&ui_print_header(undef, $text{'index_title'}, "", "intro", 1, 1, 0,
&help_search_link("tgtadm", "man", "doc", "google"));
my $err = &check_config();
if ($err) {
&ui_print_endpage(
$err." ".&text('index_clink', "../config.cgi?$module_name"));
}
# Find and show targets
my $conf = &get_tgtd_config();
my @targets = grep { $_->{'name'} eq 'target' } @$conf;
my @crlinks = ( &ui_link("edit_target.cgi?new=1",$text{'index_add'}) );
if (@targets) {
unshift(@crlinks, &select_all_link("d"), &select_invert_link("d"));
print &ui_form_start("delete_targets.cgi");
print &ui_links_row(\@crlinks);
my @tds = ( "width=5" );
print &ui_columns_start([
"", $text{'index_target'}, $text{'index_lun'},
$text{'index_size'}, $text{'index_users'},
], 100, 0, \@tds);
foreach my $t (@targets) {
my @luns;
my $size = 0;
foreach my $l (&find($t->{'members'}, "Lun")) {
if ($l->{'value'} =~ /Path=([^, ]+)/) {
push(@luns, &mount::device_name("$1"));
$size += &get_device_size("$1");
}
elsif ($l->{'value'} =~ /Sectors=(\d+)/) {
push(@luns, &text('index_nullio', "$1"));
}
}
my @users = map { $_->{'values'}->[0] }
&find($t->{'members'}, "IncomingUser");
if (@users > 5) {
@users = (@users[0 .. 4], "...");
}
print &ui_checked_columns_row([
"<a href='edit_target.cgi?name=".
&urlize($t->{'value'})."'>".$t->{'value'}."</a>",
join(" , ", @luns) || "<i>$text{'index_noluns'}</i>",
$size ? &nice_size($size) : "",
join(" , ", @users) || "<i>$text{'index_nousers'}</i>"
],
\@tds, "d", $t->{'value'});
}
print &ui_columns_end();
print &ui_links_row(\@crlinks);
print &ui_form_end([ [ undef, $text{'index_delete'} ] ]);
}
else {
print "<b>$text{'index_none'}</b><p>\n";
print &ui_links_row(\@crlinks);
}
print &ui_hr();
print &ui_buttons_start();
# Show start/stop/restart buttons
my $pid = &is_tgtd_running();
if ($pid) {
print &ui_buttons_row("restart.cgi", $text{'index_restart'},
$text{'index_restartdesc'});
print &ui_buttons_row("stop.cgi", $text{'index_stop'},
$text{'index_stopdesc'});
}
else {
print &ui_buttons_row("start.cgi", $text{'index_start'},
$text{'index_startdesc'});
}
# Show start at boot button
&foreign_require("init");
my $starting = &init::action_status($config{'init_name'});
print &ui_buttons_row("atboot.cgi",
$text{'index_atboot'},
$text{'index_atbootdesc'},
undef,
&ui_radio("boot", $starting == 2 ? 1 : 0,
[ [ 1, $text{'yes'} ], [ 0, $text{'no'} ] ]));
print &ui_buttons_end();
&ui_print_footer("/", $text{'index'});

15
iscsi-tgtd/install_check.pl Executable file
View File

@@ -0,0 +1,15 @@
# install_check.pl
do 'iscsi-tgtd-lib.pl';
# is_installed(mode)
# For mode 1, returns 2 if the server is installed and configured for use by
# Webmin, 1 if installed but not configured, or 0 otherwise.
# For mode 0, returns 1 if installed, 0 if not
sub is_installed
{
my ($mode) = @_;
my $err = &check_config();
return $err ? 0 : $mode + 1;
}

View File

@@ -102,4 +102,43 @@ foreach my $l (@$lref) {
return \@rv; return \@rv;
} }
# is_tgtd_running()
# Returns the PID if the server process is running, or 0 if not
sub is_tgtd_running
{
my $pid = &find_byname("tgtd");
return $pid;
}
# start_iscsi_tgtd()
# Run the init script to start the server
sub start_iscsi_tgtd
{
&foreign_require("init");
my ($ok, $out) = &init::start_action($config{'init_name'});
return $ok ? undef : $out;
}
# stop_iscsi_tgtd()
# Run the init script to stop the server
sub stop_iscsi_tgtd
{
&foreign_require("init");
my ($ok, $out) = &init::stop_action($config{'init_name'});
return $ok ? undef : $out;
}
# restart_iscsi_tgtd()
# Sends a HUP signal to re-read the configuration
sub restart_iscsi_tgtd
{
&stop_iscsi_tgtd();
# Wait for process to exit
for(my $i=0; $i<20; $i++) {
last if (!&is_tgtd_running());
sleep(1);
}
return &start_iscsi_tgtd();
}
1; 1;

View File

@@ -1,5 +1,25 @@
check_econfig=The iSCSI TGTD configuration file $1 was not found on your system. check_econfig=The iSCSI TGTd configuration file $1 was not found on your system.
check_etgtadm=The iSCSI TGTD administration command $1 was not found on your system. check_etgtadm=The iSCSI TGTd administration command $1 was not found on your system.
check_einit=Bootup action $1 does not exist check_einit=Bootup action $1 does not exist
index_title=iSCSI TGTD index_title=iSCSI TGTd
index_clink=Maybe it is not installed, or your <a href='$1'>module configuration</a> is incorrect.
index_stop=Stop iSCSI TGTd
index_stopdesc=Click this button to stop the running iSCSI target. All shared devices will no longer be accessible to clients.
index_start=Start iSCSI TGTd
index_startdesc=Click this button to start the iSCSI target, so that shared devices are accessible to clients.
index_restart=Restart iSCSI TGTd
index_restartdesc=Click this button to apply the current configuration by restarting the iSCSI target.
index_atboot=Start at boot?
index_atbootdesc=Change this option to control whether the iSCSI target is started at boot time or not. If it is not currently started at boot and Yes is chosen, a new init script will be created.
index_return=list of targets
index_none=No iSCSI targets to export have been defined yet.
index_add=Add a new iSCSI target.
index_target=Target name
index_delete=Delete Selected Targets
start_err=Failed to start iSCSI TGTd
stop_err=Failed to stop iSCSI TGTd
restart_err=Failed to restart iSCSI TGTd
atboot_err=Failed to enable at boot
atboot_einit=Init script $1 does not exist

View File

@@ -1,5 +1,5 @@
desc=iSCSI TGTD desc=iSCSI TGTd
category=hardware category=hardware
os_support=*-linux os_support=*-linux
depends=fdisk lvm raid init depends=fdisk lvm raid init
longdesc=Share disk devices across the network using the iSCSI protocol with the tgtd package. longdesc=Share disk devices across the network using the iSCSI protocol with the TGTd package.

12
iscsi-tgtd/restart.cgi Executable file
View File

@@ -0,0 +1,12 @@
#!/usr/local/bin/perl
# Stop and then re-start the iSCSI server process
use strict;
use warnings;
require './iscsi-tgtd-lib.pl';
our (%text);
&error_setup($text{'restart_err'});
my $err = &restart_iscsi_tgtd();
&error("<tt>".&html_escape($err)."</tt>") if ($err);
&webmin_log("restart");
&redirect("");

12
iscsi-tgtd/start.cgi Executable file
View File

@@ -0,0 +1,12 @@
#!/usr/local/bin/perl
# Start the iSCSI server process
use strict;
use warnings;
require './iscsi-tgtd-lib.pl';
our (%text);
&error_setup($text{'start_err'});
my $err = &start_iscsi_tgtd();
&error("<tt>".&html_escape($err)."</tt>") if ($err);
&webmin_log("start");
&redirect("");

12
iscsi-tgtd/stop.cgi Executable file
View File

@@ -0,0 +1,12 @@
#!/usr/local/bin/perl
# Kill the running iscsi server process
use strict;
use warnings;
require './iscsi-tgtd-lib.pl';
our (%text);
&error_setup($text{'stop_err'});
my $err = &stop_iscsi_tgtd();
&error($err) if ($err);
&webmin_log("stop");
&redirect("");