#------------------------------------------------------------------- # WebGUI is Copyright 2001-2006 Plain Black Corporation. #------------------------------------------------------------------- # Please read the legal notices (docs/legal.txt) and the license # (docs/license.txt) that came with this distribution before using # this software. #------------------------------------------------------------------- # http://www.plainblack.com info@plainblack.com #------------------------------------------------------------------- use strict; use warnings; use lib '../lib'; use Getopt::Long; use POE::Component::IKC::ClientLite; use Spectre::Admin; use WebGUI::Config; $|=1; # disable output buffering my $help; my $shutdown; my $ping; my $daemon; my $run; my $debug; GetOptions( 'help'=>\$help, 'ping'=>\$ping, 'shutdown'=>\$shutdown, 'daemon'=>\$daemon, 'debug' =>\$debug, 'run' => \$run ); if ($help || !($ping||$shutdown||$daemon||$run)) { print <new("..","spectre.conf",1); unless (defined $config) { print <$config->get("port"), ip=>'127.0.0.1', name=>rand(100000), timeout=>10 ); die $POE::Component::IKC::ClientLite::error unless $remote; my $result = $remote->post('admin/shutdown'); die $POE::Component::IKC::ClientLite::error unless defined $result; undef $remote; } elsif ($ping) { my $res = ping(); print "Spectre is Alive!\n" unless $res; print "Spectre is not responding.\n".$res if $res; } elsif ($run) { Spectre::Admin->new($config, $debug); } elsif ($daemon) { my $res = ping(); print "Spectre is already running.\n" unless $res; exit unless $res; #fork and exit(sleep(1) and print((ping())?"Spectre failed to start!\n":"Spectre started successfully!\n")); #Can't have right now. fork and exit; Spectre::Admin->new($config, $debug); } sub ping { my $remote = create_ikc_client( port=>$config->get("port"), ip=>'127.0.0.1', name=>rand(100000), timeout=>10 ); return $POE::Component::IKC::ClientLite::error unless $remote; my $result = $remote->post_respond('admin/ping'); return $POE::Component::IKC::ClientLite::error unless defined $result; undef $remote; return 0 if ($result eq "pong"); return 1; }