| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package XAS::Lib::App::Service; |
|
2
|
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
our $VERSION = '0.01'; |
|
4
|
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
my $mixin; |
|
6
|
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
BEGIN { |
|
8
|
1
|
|
|
1
|
|
573
|
$mixin = 'XAS::Lib::App::Service::Unix'; |
|
9
|
1
|
50
|
|
|
|
25
|
$mixin = 'XAS::Lib::App::Service::Win32' if ($^O eq 'MSWin32'); |
|
10
|
|
|
|
|
|
|
} |
|
11
|
|
|
|
|
|
|
|
|
12
|
1
|
|
|
1
|
|
4
|
use Try::Tiny; |
|
|
1
|
|
|
|
|
1
|
|
|
|
1
|
|
|
|
|
46
|
|
|
13
|
1
|
|
|
1
|
|
494
|
use Pod::Usage; |
|
|
1
|
|
|
|
|
32043
|
|
|
|
1
|
|
|
|
|
140
|
|
|
14
|
1
|
|
|
1
|
|
470
|
use XAS::Lib::Pidfile; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
24
|
|
|
15
|
1
|
|
|
1
|
|
388
|
use XAS::Lib::Service; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
45
|
|
|
16
|
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
use XAS::Class |
|
18
|
1
|
|
|
|
|
4
|
debug => 0, |
|
19
|
|
|
|
|
|
|
version => $VERSION, |
|
20
|
|
|
|
|
|
|
base => 'XAS::Lib::App', |
|
21
|
|
|
|
|
|
|
mixin => $mixin, |
|
22
|
|
|
|
|
|
|
constants => 'TRUE FALSE', |
|
23
|
|
|
|
|
|
|
filesystem => 'File', |
|
24
|
|
|
|
|
|
|
utils => 'dotid', |
|
25
|
|
|
|
|
|
|
accessors => 'daemon service pid', |
|
26
|
1
|
|
|
1
|
|
4
|
; |
|
|
1
|
|
|
|
|
2
|
|
|
27
|
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
# ---------------------------------------------------------------------- |
|
29
|
|
|
|
|
|
|
# Public Methods |
|
30
|
|
|
|
|
|
|
# ---------------------------------------------------------------------- |
|
31
|
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
sub define_signals { |
|
33
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
|
34
|
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
} |
|
36
|
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
sub define_pidfile { |
|
38
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
|
39
|
|
|
|
|
|
|
|
|
40
|
0
|
|
|
|
|
|
my $script = $self->env->script; |
|
41
|
|
|
|
|
|
|
|
|
42
|
0
|
|
|
|
|
|
$self->log->debug('entering define_pidfile()'); |
|
43
|
|
|
|
|
|
|
|
|
44
|
0
|
|
|
|
|
|
$self->{pid} = XAS::Lib::Pidfile->new(-pid => $$); |
|
45
|
|
|
|
|
|
|
|
|
46
|
0
|
0
|
|
|
|
|
if (my $num = $self->pid->is_running()) { |
|
47
|
|
|
|
|
|
|
|
|
48
|
0
|
|
|
|
|
|
$self->throw_msg( |
|
49
|
|
|
|
|
|
|
dotid($self->class). '.define_pidfile.runerr', |
|
50
|
|
|
|
|
|
|
'pid_run_error', |
|
51
|
|
|
|
|
|
|
$script, $num |
|
52
|
|
|
|
|
|
|
); |
|
53
|
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
} |
|
55
|
|
|
|
|
|
|
|
|
56
|
0
|
0
|
|
|
|
|
$self->pid->write() or |
|
57
|
|
|
|
|
|
|
$self->throw_msg( |
|
58
|
|
|
|
|
|
|
dotid($self->class) . '.define_pidfile.wrterr', |
|
59
|
|
|
|
|
|
|
'pid_write_error', |
|
60
|
|
|
|
|
|
|
$self->pid->file |
|
61
|
|
|
|
|
|
|
); |
|
62
|
|
|
|
|
|
|
|
|
63
|
0
|
|
|
|
|
|
$self->log->debug('leaving define_pidfile()'); |
|
64
|
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
} |
|
66
|
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
sub run { |
|
68
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
|
69
|
|
|
|
|
|
|
|
|
70
|
0
|
|
|
|
|
|
my $rc = $self->SUPER::run(); |
|
71
|
|
|
|
|
|
|
|
|
72
|
0
|
0
|
|
|
|
|
if (my $pid = $self->{'pid'}) { |
|
73
|
|
|
|
|
|
|
|
|
74
|
0
|
|
|
|
|
|
$pid->remove(); |
|
75
|
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
} |
|
77
|
|
|
|
|
|
|
|
|
78
|
0
|
|
|
|
|
|
return $rc; |
|
79
|
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
} |
|
81
|
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
# ---------------------------------------------------------------------- |
|
83
|
|
|
|
|
|
|
# Private Methods |
|
84
|
|
|
|
|
|
|
# ---------------------------------------------------------------------- |
|
85
|
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
sub init { |
|
87
|
0
|
|
|
0
|
1
|
|
my $class = shift; |
|
88
|
|
|
|
|
|
|
|
|
89
|
0
|
|
|
|
|
|
my $self = $class->SUPER::init(@_); |
|
90
|
|
|
|
|
|
|
|
|
91
|
0
|
|
|
|
|
|
$self->{'service'} = XAS::Lib::Service->new(); |
|
92
|
|
|
|
|
|
|
|
|
93
|
0
|
|
|
|
|
|
return $self; |
|
94
|
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
} |
|
96
|
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
sub _default_options { |
|
98
|
0
|
|
|
0
|
|
|
my $self = shift; |
|
99
|
|
|
|
|
|
|
|
|
100
|
0
|
|
|
|
|
|
my $options = $self->SUPER::_default_options(); |
|
101
|
|
|
|
|
|
|
|
|
102
|
0
|
|
|
|
|
|
$self->env->log_type('file'); |
|
103
|
0
|
|
|
|
|
|
$self->{'daemon'} = FALSE; |
|
104
|
|
|
|
|
|
|
|
|
105
|
0
|
|
|
|
|
|
$options->{'daemon'} = \$self->{'daemon'}; |
|
106
|
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
$options->{'install'} = sub { |
|
108
|
0
|
|
|
0
|
|
|
$self->install_service(); |
|
109
|
0
|
|
|
|
|
|
exit 0; |
|
110
|
0
|
|
|
|
|
|
}; |
|
111
|
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
$options->{'deinstall'} = sub { |
|
113
|
0
|
|
|
0
|
|
|
$self->remove_service(); |
|
114
|
0
|
|
|
|
|
|
exit 0; |
|
115
|
0
|
|
|
|
|
|
}; |
|
116
|
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
$options->{'pid-file=s'} = sub { |
|
118
|
0
|
|
|
0
|
|
|
my $pidfile = File($_[1]); |
|
119
|
0
|
|
|
|
|
|
$self->env->pid_file($pidfile); |
|
120
|
0
|
|
|
|
|
|
}; |
|
121
|
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
$options->{'cfg-file=s'} = sub { |
|
123
|
0
|
|
|
0
|
|
|
my $cfgfile = File($_[1]); |
|
124
|
0
|
|
|
|
|
|
$self->env->cfg_file($cfgfile); |
|
125
|
0
|
|
|
|
|
|
}; |
|
126
|
|
|
|
|
|
|
|
|
127
|
0
|
|
|
|
|
|
return $options; |
|
128
|
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
} |
|
130
|
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
1; |
|
132
|
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
__END__ |
|
134
|
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
=head1 NAME |
|
136
|
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
XAS::Lib::App::Service - The base class to write services within the XAS environment |
|
138
|
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
=head1 SYNOPSIS |
|
140
|
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
use XAS::Lib::App::Service; |
|
142
|
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
my $service = XAS::Lib::App::Service->new(); |
|
144
|
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
$service->run(); |
|
146
|
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
=head1 DESCRIPTION |
|
148
|
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
This module defines an operating environment for Services. A service is a |
|
150
|
|
|
|
|
|
|
managed daemon. They behave differently depending on what platform they |
|
151
|
|
|
|
|
|
|
are running on. On Windows, they will run under the SCM, on Unix like boxes, |
|
152
|
|
|
|
|
|
|
they may be standalone daemons. These differences are handled by mixins. |
|
153
|
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
The proper mixin is loaded when the process starts, so all the interaction |
|
155
|
|
|
|
|
|
|
happens in the background. It inherits from L<XAS::Lib::App|XAS::Lib::App>. Please see |
|
156
|
|
|
|
|
|
|
that module for additional documentation. |
|
157
|
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
=head1 OPTIONS |
|
159
|
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
This module handles these additional options. |
|
161
|
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
=head2 B<--cfg-file> |
|
163
|
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
This defines a configuration file. |
|
165
|
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
=head2 B<--pid-file> |
|
167
|
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
This defines the pid file to use. |
|
169
|
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
=head2 B<--install> |
|
171
|
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
This will install the service with the Win32 SCM. |
|
173
|
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
=head2 B<--deinstall> |
|
175
|
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
This will deinstall the service from the Win32 SCM. |
|
177
|
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
=head1 SEE ALSO |
|
179
|
|
|
|
|
|
|
|
|
180
|
|
|
|
|
|
|
=over 4 |
|
181
|
|
|
|
|
|
|
|
|
182
|
|
|
|
|
|
|
=item L<XAS::Lib::App::Service::Unix|XAS::Lib::App::Service::Unix> |
|
183
|
|
|
|
|
|
|
|
|
184
|
|
|
|
|
|
|
=item L<XAS::Lib::App::Service::Win32|XAS::Lib::App::Service::Win32> |
|
185
|
|
|
|
|
|
|
|
|
186
|
|
|
|
|
|
|
=item L<XAS::Lib::App|XAS::Lib::App> |
|
187
|
|
|
|
|
|
|
|
|
188
|
|
|
|
|
|
|
=item L<XAS|XAS> |
|
189
|
|
|
|
|
|
|
|
|
190
|
|
|
|
|
|
|
=back |
|
191
|
|
|
|
|
|
|
|
|
192
|
|
|
|
|
|
|
=head1 AUTHOR |
|
193
|
|
|
|
|
|
|
|
|
194
|
|
|
|
|
|
|
Kevin L. Esteb, E<lt>kevin@kesteb.usE<gt> |
|
195
|
|
|
|
|
|
|
|
|
196
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
|
197
|
|
|
|
|
|
|
|
|
198
|
|
|
|
|
|
|
Copyright (c) 2012-2015 Kevin L. Esteb |
|
199
|
|
|
|
|
|
|
|
|
200
|
|
|
|
|
|
|
This is free software; you can redistribute it and/or modify it under |
|
201
|
|
|
|
|
|
|
the terms of the Artistic License 2.0. For details, see the full text |
|
202
|
|
|
|
|
|
|
of the license at http://www.perlfoundation.org/artistic_license_2_0. |
|
203
|
|
|
|
|
|
|
|
|
204
|
|
|
|
|
|
|
=cut |