Debian Codegraph @

debian/systemd-memcached-wrapper

raw
1 #!/usr/bin/perl -w
2
3 # systemd-memcached-wrapper
4 # 2014 - Christos Trochalakis <[email protected]>
5 #
6 # Heavily based on start-memcached script by Jay Bonci
7 # <[email protected]>
8 #
9 # This script handles the parsing of the /etc/memcached.conf file
10 # and was originally created for the Debian distribution.
11 # Anyone may use this little script under the same terms as
12 # memcached itself.
13
14 use strict;
15
16 if($> != 0 and $< != 0)
17 {
18 print STDERR "Only root wants to run systemd-memcached-wrapper.\n";
19 exit;
20 }
21
22 my $params; my $etchandle; my $etcfile = "/etc/memcached.conf";
23
24 # This script assumes that memcached is located at /usr/bin/memcached
25 my $memcached = "/usr/bin/memcached";
26
27 if (scalar(@ARGV) == 1) {
28 $etcfile = shift(@ARGV);
29 }
30
31 # systemd capture stdout by default
32 my $ignore_directives = ("logfile");
33
34 if(open $etchandle, $etcfile)
35 {
36 foreach my $line (<$etchandle>)
37 {
38 $line ||= "";
39 $line =~ s/(?<!\\)\#[^\#]*//g;
40 $line =~ s/\s+$//g;
41 $line =~ s/^\s+//g;
42 next unless $line;
43 next if $line =~ /^\-[dh]/;
44
45 if($line =~ /^[^\-]/)
46 {
47 my ($directive, $arg) = $line =~ /^(.*?)\s+(.*)/;
48 next if(grep $directive, $ignore_directives);
49 }
50
51 push @$params, $line;
52 }
53
54 }else{
55 $params = [];
56 }
57
58 push @$params, "-u root" unless(grep "-u", @$params);
59 $params = join " ", @$params;
60
61 exec "$memcached $params";
62 exit(0);