PIKT

Samples: Restart piktc_svc

PIKT Logo
Home FAQ News Intro Samples Tutorial Reference Software Authors Licensing SiteSearch


svcstart_programs.cfg defines a simple Perl script to restart piktc_svc.  Note how the #if directives customize the script for different operating systems.

///////////////////////////////////////////////////////////////////////////////
//
// svcstart_programs.cfg
//
///////////////////////////////////////////////////////////////////////////////

svcstart.pl     // kill/restart the piktc_svc daemon

        #!=perl
        
        # svcstart.pl -- kill/restart the piktc_svc daemon
        
        die "Usage:  svcstart.pl [-kr]\n" if $#ARGV != 0;

        use Getopt::Std;
        die "Usage:  svcstart.pl [-kr]\n" if !getopts('kr');
        $KILL = $opt_k;
        $RESTART = $opt_r;

#if solaris
        $pscmd = "=ps -el |
                  =awk '/pikt/ {printf(\"%s %s %s\\n\", \$4, \$5, \$NF)}'";
#elif redhat | debian
        $pscmd = "=ps axcl |
                  =awk '/pikt/ {printf(\"%s %s %s\\n\", \$3, \$4, \$NF)}'";
#endif
        
        if ($KILL || $RESTART) {
                # kill any running piktc_svc
                open(PSCMD, "$pscmd |");
                while (<PSCMD>) {
                        chop;
#fix
                        if (/^(\d+)\s+\d+\s+piktc_sv/) {
#unfix
                                $pid = $1;
                                if (kill('SIGTERM', $pid)) {
                                        printf "killed piktc_svc pid %d\n", $pid;
                                }
                        }
                }
                close(PSCMD);
        }
        
        if ($RESTART) {
                # delete any piktc_svc.lock file
                if (-e "=etcdir/piktc_svc.lock") {
                        system("=rm =etcdir/piktc_svc.lock 2>/dev/null");
                }
                # restart piktc_svc
                $cmd = "=bindir/piktc_svc";
#if linux
                $cmd .= " &";
#endif
                system($cmd);
        
                # find new piktc_svc
                open(PSCMD, "$pscmd |");
                while (<PSCMD>) {
                        chop;
#fix
                        if (/^(\d+)\s+\d+\s+piktc_sv/) {
#unfix
                                $pid = $1;
                                printf "new piktc_svc pid %d\n", $pid;
                        }
                }
                close(PSCMD);
        }

///////////////////////////////////////////////////////////////////////////////
On the piktmaster system, we would install the svcstart.pl script to itself with the command:
# piktc -iv +P svcstart.pl +H piktmaster

[For more examples, see Samples.]

Home | FAQ | News | Intro | Samples | Tutorial | Reference | Software | Authors | Licensing | SiteSearch
Links | SiteIndex | Pikt-Users | Pikt-Workers | Contribute | ContactUs | Top of Page
Page best viewed at 1024x768.   Page last updated 2005-06-22.
This site is PIKT® powered.
PIKT® is a registered trademark of the University of Chicago.
Copyright © 1998-2005 Robert Osterlund.  All rights reserved.

Computer Books at Amazon.com

CGI Programming with Perl
CGI Programming with Perl

Programming Perl
Programming Perl

Setting Up LAMP
Setting Up LAMP

Randal Schwartz's Perls of Wisdom
Randal Schwartz's Perls of Wisdom

Perl 6 and Parrot Essentials
Perl 6 and Parrot Essentials