File: daemonizes.pl

package info (click to toggle)
percona-toolkit 3.2.1-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, forky, sid, trixie
  • size: 68,916 kB
  • sloc: perl: 241,287; sql: 22,868; sh: 19,746; javascript: 6,799; makefile: 353; awk: 38; python: 30; sed: 1
file content (94 lines) | stat: -rwxr-xr-x 1,933 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#!/usr/bin/env perl

# This script is used by Daemon.t because that test script
# cannot daemonize itself.

BEGIN {
   die "The PERCONA_TOOLKIT_BRANCH environment variable is not set.\n"
      unless $ENV{PERCONA_TOOLKIT_BRANCH} && -d $ENV{PERCONA_TOOLKIT_BRANCH};
   unshift @INC, "$ENV{PERCONA_TOOLKIT_BRANCH}/lib";
};

use strict;
use warnings FATAL => 'all';
use English qw(-no_match_vars);

use constant PTDEBUG    => $ENV{PTDEBUG}    || 0;
use constant PTDEVDEBUG => $ENV{PTDEVDEBUG} || 0;

use Time::HiRes qw(sleep);

use Daemon;
use OptionParser;
use PerconaTest;

my $o = new OptionParser(file => "$trunk/t/lib/samples/daemonizes.pl");
$o->get_specs();
$o->get_opts();

my ($sleep_time) = shift @ARGV;
if ( !defined $sleep_time ) {
   $o->save_error('No SLEEP_TIME specified');
}

$o->usage_or_errors();

my $daemon = Daemon->new(
   daemonize => $o->get('daemonize'),
   pid_file  => $o->get('pid'),
   log_file  => $o->get('log'),
);

$daemon->run();
PTDEVDEBUG && PerconaTest::_d('daemonized');

print "STDOUT\n";
print STDERR "STDERR\n";

PTDEVDEBUG && PerconaTest::_d('daemon sleep', $sleep_time);
sleep $sleep_time;

PTDEVDEBUG && PerconaTest::_d('daemon done');
exit;

# ############################################################################
# Documentation.
# ############################################################################

=pod

=head1 SYNOPSIS

Usage: daemonizes.pl SLEEP_TIME

daemonizes.pl daemonizes, prints to STDOUT and STDERR, sleeps and exits.

=head1 OPTIONS

This tool accepts additional command-line arguments.  Refer to the
L<"SYNOPSIS"> and usage information for details.

=over

=item --daemonize

Fork to background and detach (POSIX only).  This probably doesn't work on
Microsoft Windows.

=item --help

Show help and exit.

=item --log

type: string

Print all output to this file when daemonized.

=item --pid

type: string 

Create the given PID file when daemonized.

=back