Tags:

ackermann   Amateurfunk   angola   assembler   basic   bewiso   c programmierung   coding   digitale Signatur   gdbinit   informatik   krypto   linux   Lockpicking   lustig   mathematik   mobile   modern   netzwerk   perl   phreaking   pointer   politik   programmierung   radio   ratten   security   sha-1   sicherheit   smartcard   tunnel  

Last update
(Nov 10 2007)

yapssd



Yet another perl start stop daemon

#!/usr/bin/perl
#
# Copyright by Sven Tantau
#
# This lines are under the GNU General Public License.
# http://www.gnu.org/copyleft/gpl.html
#
# I know this could be written better, _saver_ and cleaner..
# Face one problem of free software:
#  some people do a 'it works for me' solution
#
#
#
 
use warnings;
use strict;
use strict "vars";
 
# easy to replace if you do some hard coding of paths..
# i use it cause i want to execute something in the same path
use FindBin;
 
my $pidfile = '/tmp/bewiso_wrapped.pid';
my $exec = 'bewiso_wrapped';
 
 
sub start_it {
 if(-f $pidfile) {
  print $exec." is already running\n";
  print "if this is not the case, please rm $pidfile\n";
  exit;
 }
 defined(my $pid = fork()) or die "can not fork!";
 if($pid != 0){
  open LOG, ">$pidfile" or die "Cannot open $pidfile";
  print LOG "$pid\n";
  close LOG;
 } else {
  exec $FindBin::Bin.'/'.$exec;
 }
  print "started\n";
 }
 
 
sub stop_it {
 if(! open LOG, '<'.$pidfile) {
  print "I can not see ".$exec." running\n";
  exit;
 }
 my $pid = <LOG>;
 close LOG;
 
 if(! kill 0, $pid) {
  print $exec." is already stopped\n";
  unlink $pidfile or die "Cannot unlink pid file";
  exit;
 }
 kill "SIGTERM", $pid;
 
 if(! kill 0, $pid) {
  print $exec." stopped\n";
  unlink $pidfile or die "Cannot unlink pid file";
  exit;
 }
 print "I can not stop ".$exec."\n";
}
 
 
sub get_status {
 if(-f $pidfile) {
  print $exec." is running\n";
  exit;
 } else {
  print $exec." is not running\n";
  exit;
 }
}
 
 
if (@ARGV != 1){
 print "usage: ".[[CONTENT]]." <start|stop|status>\n";
 exit;
}
 
if($ARGV[0] eq "start") {
 start_it();
} elsif ($ARGV[0] eq "stop") {
 stop_it();
} else {
 get_status();
}
 


perl