Skip to content

Instantly share code, notes, and snippets.

@omega
Created January 8, 2009 12:39
Show Gist options
  • Save omega/44711 to your computer and use it in GitHub Desktop.
Save omega/44711 to your computer and use it in GitHub Desktop.
has 'user' => (is => 'ro', isa => 'Str', default => 'nobody');
has 'group' => (is => 'ro', isa => 'Str', default => 'nogroup');
after 'daemonize' => sub {
my $self = shift;
return unless $self->is_daemon;
return unless (defined $self->user and defined $self->group);
my $uid = getpwnam($self->user) or $self->log->error( "cannot find uid for username: " . $self->user);
my $gid = getgrnam($self->group) or $self->log->error("cannot find gid for group: " . $self->group);
# EGID, set twice to remove inherited groups
$) = "$gid $gid";
# GID change
$( = $gid;
# EUID change, leave UID alone
$> = $uid;
};
before 'stop' => sub {
my $self = shift;
$self->log->info("stopping");
};
before 'remove_pid' => sub {
# Regain EUID
$> = $<;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment