-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathepindexer.in
executable file
·169 lines (143 loc) · 3.99 KB
/
epindexer.in
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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
#!@PERL_PATH@ -T -w
### BEGIN INIT INFO
# Provides: epindexer
# Required-Start: $local_fs $remote_fs $network $syslog $named
# Required-Stop: $local_fs $remote_fs $network $syslog $named
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: EPrints indexer
# Description: Start the EPrints indexer daemon as the correct user.
### END INIT INFO
my $user = "@INSTALL_USER@";
my $group = "@INSTALL_GROUP@";
my $prefix = "@PREFIX@";
######################################################################
#
# chkconfig: - 85 15
# description: Start the eprints indexer daemon as the correct user
#
######################################################################
#
#
######################################################################
use Config::General qw( ParseConfig );
use English;
use POSIX;
use strict;
if( $REAL_USER_ID != 0 )
{
print "This script is intended to start the eprints indexer as a service.\nIt should only be run as root.\nExiting.\n";
exit 1;
}
if( !defined $ARGV[0] || $ARGV[0] !~ m/^(start|stop|status)$/ )
{
print "Usage: $0 {start|stop|status}\n";
exit 1;
}
my $opt = $1;
# These are not going via Platform, but this is a UNIX script, so meh.
my $uid = (getpwnam($user))[2];
my $gid = (getgrnam($group))[2];
my @sgroups = ($gid); # gid + supplementary groups
while(my( undef, undef, $gid, $members ) = getgrent())
{
push @sgroups, $gid if $members =~ /\b$user\b/;
}
$REAL_GROUP_ID = $EFFECTIVE_GROUP_ID = "@sgroups";
$REAL_USER_ID = $EFFECTIVE_USER_ID = $uid;
# Read the configuration file
my $confname = "$prefix/cfg/epindexer.conf";
my %conf;
if ( -f $confname )
{
%conf = ParseConfig( $confname );
}
# Configure verbosity
my $noise = 0;
if( defined $conf{'verbose'} and $conf{'verbose'} =~ m/^(\d+)$/ )
{
$noise = $1;
}
# Set up the environment
if ( exists $conf{'Environment'} )
{
foreach my $k ( keys %{$conf{'Environment'}} )
{
# regex capture groups don't inherit the source's taint
$conf{'Environment'}{$k} =~ m/(.*)/;
$ENV{$k} = $1;
if ( $noise > 0 )
{
print $k . '=' . $ENV{$k} . "\n";
}
}
}
# Build the command line for the indexer
my @indexer_cmd = ( "$prefix/bin/indexer" );
# logfile must be non-empty string
if ( defined $conf{'logfile'} and $conf{'logfile'} =~ m/(.+)/ )
{
push @indexer_cmd, '--logfile', $1;
}
# loglevel is a number from 0 to 6
if ( defined $conf{'loglevel'} and $conf{'loglevel'} =~ m/^([0-6])$/ )
{
push @indexer_cmd, '--loglevel', $1;
}
# rollcount is a number
if ( defined $conf{'rollcount'} and $conf{'rollcount'} =~ m/^(\d+)$/ )
{
push @indexer_cmd, '--rollcount', $1;
}
# respawn is a number (of seconds)
if ( defined $conf{'respawn'} and $conf{'respawn'} =~ m/(\d+)/ )
{
push @indexer_cmd, '--respawn', $1;
}
push @indexer_cmd, $opt;
if ( $noise > 0 )
{
print 'Executing ' . join( ' ', @indexer_cmd ) . "\n";
}
# Go!
$| = 0;
if( $opt eq 'start' )
{
print 'Starting EPrints Indexer: ';
}
if( $opt eq 'stop' )
{
print 'Stopping EPrints Indexer: ';
}
delete $ENV{'PATH'};
my $rv = system( @indexer_cmd );
$rv = $rv >> 8;
if( $opt eq 'start' || $opt eq 'stop' )
{
if( $rv == 0 )
{
print ' [ OK ]'."\n";
}
else
{
print ' [FAILED]'."\n";
}
}
exit $rv;
=head1 COPYRIGHT
=for COPYRIGHT BEGIN
Copyright 2000-2011 University of Southampton.
=for COPYRIGHT END
=for LICENSE BEGIN
This file is part of EPrints L<http://www.eprints.org/>.
EPrints is free software: you can redistribute it and/or modify it
under the terms of the GNU General Public License as published
by the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
EPrints is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
License for more details.
You should have received a copy of the GNU General Public License
along with EPrints. If not, see L<http://www.gnu.org/licenses/>.
=for LICENSE END