File: systemd-memcached-wrapper

package info (click to toggle)
memcached 1.6.18-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 5,020 kB
  • sloc: ansic: 50,279; perl: 7,513; sh: 4,546; makefile: 461; python: 402; xml: 59
file content (62 lines) | stat: -rw-r--r-- 1,423 bytes parent folder | download | duplicates (6)
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
#!/usr/bin/perl -w

# systemd-memcached-wrapper
# 2014 - Christos Trochalakis <yatiohi@idepolis.gr>
#
# Heavily based on start-memcached script by Jay Bonci
# <jaybonci@debian.org>
#
# This script handles the parsing of the /etc/memcached.conf file
# and was originally created for the Debian distribution.
# Anyone may use this little script under the same terms as
# memcached itself.

use strict;

if($> != 0 and $< != 0)
{
    print STDERR "Only root wants to run systemd-memcached-wrapper.\n";
    exit;
}

my $params; my $etchandle; my $etcfile = "/etc/memcached.conf";

# This script assumes that memcached is located at /usr/bin/memcached
my $memcached = "/usr/bin/memcached";

if (scalar(@ARGV) == 1) {
    $etcfile = shift(@ARGV);
}

# systemd capture stdout by default
my $ignore_directives = ("logfile");

if(open $etchandle, $etcfile)
{
    foreach my $line (<$etchandle>)
    {
        $line ||= "";
        $line =~ s/(?<!\\)\#[^\#]*//g;
        $line =~ s/\s+$//g;
        $line =~ s/^\s+//g;
        next unless $line;
        next if $line =~ /^\-[dh]/;

        if($line =~ /^[^\-]/)
        {
            my ($directive, $arg) = $line =~ /^(.*?)\s+(.*)/;
	    next if(grep $directive, $ignore_directives);
        }

        push @$params, $line;
    }

}else{
    $params = [];
}

push @$params, "-u root" unless(grep "-u", @$params);
$params = join " ", @$params;

exec "$memcached $params";
exit(0);