Restart piktc_svc

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
Developer's Notes | Licensing | Authors | Pikt-Users | Pikt-Workers | Related Projects | Site Index | Privacy Policy | Contact Us
Page best viewed at 1024x768 or greater.   Page last updated 2019-01-12.   This site is PIKT® powered.
Copyright © 1998-2019 Robert Osterlund. All rights reserved.
Home FAQ News Intro Samples Tutorial Reference Software
PIKT Logo
PIKT Page Title
Learn about the
PIKT macros.cfg
config file