~yolanda.robla/ubuntu/trusty/memcached/add_distribution

« back to all changes in this revision

Viewing changes to scripts/start-memcached

  • Committer: Bazaar Package Importer
  • Author(s): Jay Bonci
  • Date: 2004-05-05 17:25:25 UTC
  • Revision ID: james.westby@ubuntu.com-20040505172525-ullh634q1xce88jl
Tags: upstream-1.1.11
ImportĀ upstreamĀ versionĀ 1.1.11

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/perl -w
 
2
 
 
3
# start-memcached
 
4
# 2003 - Jay Bonci <jaybonci@debian.org>
 
5
# This script handles the parsing of the /etc/memcached.conf file
 
6
# and was originally created for the Debian distribution.
 
7
# Anyone may use this little script under the same terms as
 
8
# memcached itself.
 
9
 
 
10
use strict;
 
11
 
 
12
if($> != 0 and $< != 0)
 
13
{
 
14
        print STDERR "Only root wants to run start-memcached.\n";
 
15
        exit;
 
16
}
 
17
 
 
18
my $params; my $etchandle; my $etcfile = "/etc/memcached.conf";
 
19
my $memcached = "/usr/bin/memcached";
 
20
my $pidfile = "/var/run/memcached.pid";
 
21
 
 
22
if(open $etchandle, $etcfile)
 
23
{
 
24
        foreach my $line (<$etchandle>)
 
25
        {
 
26
                $line ||= "";
 
27
                $line =~ s/\#.*//g;
 
28
                $line =~ s/\s+$//g;
 
29
                $line =~ s/^\s+//g;
 
30
                next unless $line;
 
31
                next if $line =~ /\-[dvh]/;
 
32
 
 
33
                push @$params, $line;           
 
34
        }
 
35
 
 
36
}else{
 
37
        $params = [];
 
38
}
 
39
 
 
40
        push @$params, "-u root" unless(grep "-u", @$params);
 
41
        $params = join " ", @$params;
 
42
 
 
43
if(-e $pidfile)
 
44
{
 
45
        open PIDHANDLE, "$pidfile";
 
46
        my $localpid = <PIDHANDLE>;
 
47
        close PIDHANDLE;
 
48
 
 
49
        chomp $localpid;
 
50
        if(-d "/proc/$localpid")
 
51
        {
 
52
                print STDERR "memcached is already running.\n"; 
 
53
                exit;           
 
54
        }else{
 
55
                `rm -f $localpid`;
 
56
        }
 
57
 
 
58
}
 
59
 
 
60
my $pid = fork();
 
61
 
 
62
if($pid == 0)
 
63
{
 
64
                exec "$memcached $params";
 
65
                exit(0);
 
66
 
 
67
}else{
 
68
        if(open PIDHANDLE,">$pidfile")
 
69
        {
 
70
                print PIDHANDLE $pid;
 
71
                close PIDHANDLE;
 
72
        }else{
 
73
 
 
74
                print STDERR "Can't write pidfile to $pidfile.\n";
 
75
        }
 
76
}
 
77