Last active
August 29, 2015 14:00
-
-
Save krimdomu/2b57df6a894452ada759 to your computer and use it in GitHub Desktop.
daemonize a script/programm
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/perl | |
# USAGE: daemonize --user root --group root --pid_file /var/run/mydaemon.pid --command /usr/local/bin/myscript | |
use strict; | |
use warnings; | |
use Net::Server::Daemonize 'daemonize'; | |
use Getopt::Long; | |
use File::Basename; | |
my ( $user, $group, $pid_file, $command, $bind_to ); | |
GetOptions( | |
"user=s" => \$user, | |
"group=s" => \$group, | |
"pid_file=s" => \$pid_file, | |
"command=s" => \$command | |
); | |
if ( !$user ) { | |
print "No user given.\n"; | |
exit 1; | |
} | |
if ( !$group ) { | |
print "No group given.\n"; | |
exit 1; | |
} | |
if ( !$pid_file ) { | |
print "No pid_file given.\n"; | |
exit 1; | |
} | |
if ( !$command ) { | |
print "No command given.\n"; | |
exit 1; | |
} | |
daemonize( $user, $group, $pid_file ); | |
exec $command; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment