A few notes:
LANG=en_US. Rasberries to RedHat.apt-get. Perhaps the fine folks
running debian might consider shipping a 2.4 kernel before the 2.6 comes out.
Woody ships with a 2.2 kernel from 2002.File: setup_jjohn
#!/usr/bin/env perl
# -*-cperl-*-
#
# start|stop processes that I need
#
use strict;
use warnings;
use File::Basename;
use Getopt::Std;
our $HOME = "/home/jjohn";
our $LASTRUN = "$HOME/etc/.jjohn_setup";
our %PROCS = ( '01 SSH tunnels' => { start => "$HOME/etc/ssh_mail_tunnel start",
stop => "$HOME/etc/ssh_mail_tunnel stop",
},
'02 MON' => { start => "$HOME/etc/mon/start_mon",
stop => "killall mon",
},
'99 VNC' => { start => "$HOME/bin/start_vnc",
stop => "/usr/bin/vncserver -kill:1",
},
'04 Fetchmail' => { start => "/usr/bin/fetchmail",
stop => "killall fetchmail",
},
'03 Apache'=> { start => "/usr/bin/sudo $HOME/src/apache-current/bin/apachectl start",
stop => "/usr/bin/sudo $HOME/src/apache-current/bin/apachectl stop",
},
);
my $opts = {};
getopts('h?fv', $opts);
$|++;
my $action = (lc pop @ARGV) || 'start';
my %dispatch = ( 'stop' => \&stop,
'start' => \&start,
'usage' => \&usage,
'status' => \&status,
);
$action = 'usage' if $opts->{'?'} || $opts->{'h'};
if (exists $dispatch{$action}) {
$dispatch{$action}->($opts);
} else {
start($opts);
}
exit;
#-------------------------------------------------- -------------------
sub start {
my ($opts) = @_;
# Skip the LASTRUN check if the force flag is set
unless ($opts->{f}) {
# compare the boot time (/var/lock/subsys/local) to our last runtime
if (-e $LASTRUN) {
my $sysboot = (stat "/var/lock/subsys/local")[9];
my $lastrun = (stat $LASTRUN)[9];
# if we have run after system boot, bail
if ($lastrun > $sysboot) {
warn "Already ran since boot. Halting.\n" if $opts->{v};
return;
}
}
}
for my $proc (sort keys %PROCS) {
printf "Starting %-25s:", $proc if $opts->{v};
my $ok = "OK";
if (system("$PROCS{$proc}->{start} 2>&1 >/dev/null")) {
$ok = "FAILED";
}
printf "%15s\n", $ok if $opts->{v};
}
# print out PID to LASTRUN
open my $pid, ">$LASTRUN" or die "can't open '$LASTRUN': $!\n";
select(((select $pid) => $|++)[0]);
print $pid $$;
close $pid;
}
# stop the services above
sub stop {
my ($opts) = @_;
for my $proc (reverse sort keys %PROCS) {
printf "Stopping %-25s:", $proc if $opts->{v};
my $ok = "OK";
if (system("$PROCS{$proc}->{stop} 2>&1 >/dev/null")) {
$ok = "FAILED";
}
printf "%15s\n",$ok if $opts->{v};
}
unlink $LASTRUN;
}
sub usage {
my $name = basename $0;
print "$name - control services for jjohn
USAGE:
$name [OPTIONS] [ACTION]
\$ $name -v start # start services with verbosity
\$ $name stop # stop services silently
\$ $name status # show boot time vs. last run of this program
OPTIONS:
h print this screen
? print this screen
f force start, regardless of LASTRUN file
v turn on verbose messages
";
}
sub status {
my ($opts) = @_;
my $lastrun = (stat $LASTRUN)[9];
my $boot = (stat "/var/lock/subsys/local")[9];
my $name = basename $0;
my $ltime = (defined $lastrun)
? scalar localtime($lastrun)
: "NEVER RUN";
my $btime = scalar localtime($boot);
printf "%16s: %-20s\n%16s: %-20s\n",
"system boot", $btime,
"$name ran", $ltime;
}
newegg (Score:2)
Re:newegg (Score:1)