7 | 7 |
use Cwd 'abs_path';
|
8 | 8 |
require 5.008001; # Supporting 5.8.1+
|
9 | 9 |
|
10 | |
our $VERSION = '0.001005'; # 0.1.5
|
|
10 |
our $VERSION = '0.001006'; # 0.1.6
|
11 | 11 |
$VERSION = eval $VERSION;
|
12 | 12 |
|
13 | 13 |
my @accessors = qw(
|
|
15 | 15 |
uid path gid scan_name stdout_file stderr_file pid_file fork data
|
16 | 16 |
lsb_start lsb_stop lsb_sdesc lsb_desc redirect_before_fork init_config
|
17 | 17 |
kill_timeout umask resource_dir help init_code
|
18 | |
prereq_no_process foreground
|
|
18 |
prereq_no_process foreground reload_signal stop_signals
|
19 | 19 |
);
|
20 | 20 |
|
21 | 21 |
my $cmd_opt = "[start|stop|restart|reload|status|show_warnings|get_init_file|help]";
|
|
73 | 73 |
quiet => 0,
|
74 | 74 |
umask => 0,
|
75 | 75 |
foreground => 0,
|
|
76 |
reload_signal => 'HUP',
|
|
77 |
stop_signals => [ qw(TERM TERM INT KILL) ],
|
76 | 78 |
}, $class;
|
77 | 79 |
|
78 | 80 |
for my $accessor ( @accessors ) {
|
|
450 | 452 |
|
451 | 453 |
if ( $self->pid_running($start_pid) ) {
|
452 | 454 |
SIGNAL:
|
453 | |
foreach my $signal ( qw(TERM TERM INT KILL) ) {
|
|
455 |
foreach my $signal (@{ $self->stop_signals }) {
|
454 | 456 |
$self->trace( "Sending $signal signal to pid $start_pid..." );
|
455 | 457 |
kill $signal => $start_pid;
|
456 | 458 |
|
|
512 | 514 |
$self->read_pid;
|
513 | 515 |
|
514 | 516 |
if ( $self->pid && $self->pid_running ) {
|
515 | |
kill "SIGHUP", $self->pid;
|
|
517 |
kill $self->reload_signal, $self->pid;
|
516 | 518 |
$self->pretty_print( "Reloaded" );
|
517 | 519 |
return 0;
|
518 | 520 |
} else {
|
|
690 | 692 |
use strict;
|
691 | 693 |
use Daemon::Control;
|
692 | 694 |
|
693 | |
Daemon::Control->new(
|
|
695 |
exit Daemon::Control->new(
|
694 | 696 |
name => "My Daemon",
|
695 | 697 |
lsb_start => '$syslog $remote_fs',
|
696 | 698 |
lsb_stop => '$syslog',
|
|
712 | 714 |
By default C<run> will use @ARGV for the action, and exit with an LSB compatible
|
713 | 715 |
exit code. For finer control, you can use C<run_command>, which will return
|
714 | 716 |
the exit code, and accepts the action as an argument. This enables more programatic
|
715 | |
control, as well as running multiple instances of M<Daemon::Control> from one script.
|
|
717 |
control, as well as running multiple instances of L<Daemon::Control> from one script.
|
716 | 718 |
|
717 | 719 |
my $daemon = Daemon::Control->new(
|
718 | 720 |
...
|
|
851 | 853 |
redirecting before a double fork. This is useful when you are using a code
|
852 | 854 |
reference and would like to leave the filehandles alone until you're in control.
|
853 | 855 |
|
854 | |
Call C<->redirect_filehandles> on the Daemon::Control instance your coderef is
|
|
856 |
Call C<< ->redirect_filehandles >> on the Daemon::Control instance your coderef is
|
855 | 857 |
passed to redirect the filehandles.
|
856 | 858 |
|
857 | 859 |
=head2 stdout_file
|
|
982 | 984 |
|
983 | 985 |
$daemon->quiet( 1 );
|
984 | 986 |
|
|
987 |
=head2 reload_signal
|
|
988 |
|
|
989 |
The signal to send to the daemon when reloading it.
|
|
990 |
Default signal is C<HUP>.
|
|
991 |
|
|
992 |
=head2 stop_signals
|
|
993 |
|
|
994 |
An array ref of signals that should be tried (in order) when
|
|
995 |
stopping the daemon.
|
|
996 |
Default signals are C<TERM>, C<TERM>, C<INT> and C<KILL> (yes, C<TERM>
|
|
997 |
is tried twice).
|
|
998 |
|
985 | 999 |
=head1 METHODS
|
986 | 1000 |
|
987 | 1001 |
=head2 run_command
|
|
1012 | 1026 |
Is called when B<foreground> is given as an argument. Starts the
|
1013 | 1027 |
program or code reference and stays in the foreground -- no forking
|
1014 | 1028 |
is done, regardless of the compile-time arguments. Additionally,
|
1015 | |
turns C<quiet> on to avoid showing M<Daemon::Control> output.
|
|
1029 |
turns C<quiet> on to avoid showing L<Daemon::Control> output.
|
1016 | 1030 |
|
1017 | 1031 |
/usr/bin/my_program_launcher.pl foreground
|
1018 | 1032 |
|
|
1032 | 1046 |
|
1033 | 1047 |
=head2 do_reload
|
1034 | 1048 |
|
1035 | |
Is called when reload is given as an argument. Sends a HUP signal to the
|
1036 | |
daemon.
|
|
1049 |
Is called when reload is given as an argument. Sends the signal
|
|
1050 |
C<reload_signal> to the daemon.
|
1037 | 1051 |
|
1038 | 1052 |
/usr/bin/my_program_launcher.pl reload
|
1039 | 1053 |
|