#!/usr/bin/perl #=============================================================================== # called by init.d script to control ./hilis4.fcgi fastcgiexternalserver script #=============================================================================== use strict; use warnings; BEGIN { use FindBin qw($Bin); # warn 'BIN:'.$Bin; exit; # set lib paths for app: use lib ( "$Bin/../lib", '/home/raj/perl5/lib/perl5', ); } use Daemon::Control; use Data::Dumper; use User::pwent; # getpwnam() # APACHE_USER & CENTRE vars set in init.d: my $CENTRE = $ENV{CENTRE} || die 'no CENTRE env var set'; # warn $CENTRE; my $USER = $ENV{APACHE_USER} || die 'no APACHE_USER env var set'; # warn $USER; #------------------------------------------------------------------------------- my $program = $Bin . '/hilis4.fcgi'; # fastcgiexternalserver script my $run_dir = '/var/run/hilis4'; # location of pid file, socket, stderr # get uid of apache user using User::pwent::getpwnam: my $uid = getpwnam($USER)->uid; # warn Dumper $uid; exit; my $self = $0; # warn $self; # this script #------------------------------------------------------------------------------- my %args = ( name => 'HILIS4_' . $CENTRE, # lsb_start => '$syslog $remote_fs', # lsb_stop => '$syslog', lsb_sdesc => 'HILIS4 daemon', lsb_desc => 'Controls the hilis4 daemon script', path => $self, # this script program => $program, program_args => [ ], pid_file => "$run_dir/$CENTRE.pid", stderr_file => $run_dir . '/stderr.out', stdout_file => $run_dir . '/stderr.out', fork => 2, uid => $uid, ); Daemon::Control->new(\%args)->run; __END__ #!/bin/sh # typical init.d script export APACHE_USER=www-data SCRIPT_DIR=/home/raj/apps/HILIS4/script CONTROL=hilis4_daemon_control.pl if [ -x $SCRIPT_DIR/$CONTROL ]; then $SCRIPT_DIR/$CONTROL $1 else echo "Required program $SCRIPT_DIR/$CONTROL not found!" exit 1; fi