~percona-toolkit-dev/percona-toolkit/fix-change-master-bug-932614

« back to all changes in this revision

Viewing changes to t/lib/samples/daemonizes.pl

  • Committer: Daniel Nichter
  • Date: 2011-06-24 17:22:06 UTC
  • Revision ID: daniel@percona.com-20110624172206-c7q4s4ad6r260zz6
Add lib/, t/lib/, and sandbox/.  All modules are updated and passing on MySQL 5.1.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/env perl
 
2
 
 
3
# This script is used by Daemon.t because that test script
 
4
# cannot daemonize itself.
 
5
 
 
6
BEGIN {
 
7
   die "The MAATKIT_WORKING_COPY environment variable is not set.  See http://code.google.com/p/maatkit/wiki/Testing"
 
8
      unless $ENV{MAATKIT_WORKING_COPY} && -d $ENV{MAATKIT_WORKING_COPY};
 
9
   unshift @INC, "$ENV{MAATKIT_WORKING_COPY}/common";
 
10
};
 
11
 
 
12
use strict;
 
13
use warnings FATAL => 'all';
 
14
 
 
15
use English qw(-no_match_vars);
 
16
use constant MKDEBUG => $ENV{MKDEBUG};
 
17
 
 
18
use Daemon;
 
19
use OptionParser;
 
20
use MaatkitTest;
 
21
 
 
22
my $o = new OptionParser(file => "$trunk/common/t/samples/daemonizes.pl");
 
23
$o->get_specs();
 
24
$o->get_opts();
 
25
 
 
26
if ( scalar @ARGV < 1 ) {
 
27
   $o->save_error('No SLEEP_TIME specified');
 
28
}
 
29
 
 
30
$o->usage_or_errors();
 
31
 
 
32
my $daemon;
 
33
if ( $o->get('daemonize') ) {
 
34
   $daemon = new Daemon(o=>$o);
 
35
   $daemon->daemonize();
 
36
 
 
37
   print "STDOUT\n";
 
38
   print STDERR "STDERR\n";
 
39
 
 
40
   sleep $ARGV[0];
 
41
}
 
42
 
 
43
exit;
 
44
 
 
45
# ############################################################################
 
46
# Documentation.
 
47
# ############################################################################
 
48
 
 
49
=pod
 
50
 
 
51
=head1 SYNOPSIS
 
52
 
 
53
Usage: daemonizes.pl SLEEP_TIME [ARGS]
 
54
 
 
55
daemonizes.pl daemonizes, prints to STDOUT and STDERR, sleeps and exits.
 
56
 
 
57
=head1 OPTIONS
 
58
 
 
59
This tool accepts additional command-line arguments.  Refer to the
 
60
L<"SYNOPSIS"> and usage information for details.
 
61
 
 
62
=over
 
63
 
 
64
=item --daemonize
 
65
 
 
66
Fork to background and detach (POSIX only).  This probably doesn't work on
 
67
Microsoft Windows.
 
68
 
 
69
=item --help
 
70
 
 
71
Show help and exit.
 
72
 
 
73
=item --log
 
74
 
 
75
type: string
 
76
 
 
77
Print all output to this file when daemonized.
 
78
 
 
79
=item --pid
 
80
 
 
81
type: string 
 
82
 
 
83
Create the given PID file when daemonized.
 
84
 
 
85
=back