From: Andreas Scherbaum Date: Sun, 18 Nov 2012 10:39:16 +0000 (+0100) Subject: - add pidfile handling (required for automatic startup/shutdown) X-Git-Url: http://git.postgresql.org/gitweb/static/gitweb.js?a=commitdiff_plain;h=dd5e1c8e2b9098f2875f1f20192d7fd12db45660;p=docbot.git - add pidfile handling (required for automatic startup/shutdown) --- diff --git a/docbot.conf b/docbot.conf index 0a4386b..28f3ad2 100644 --- a/docbot.conf +++ b/docbot.conf @@ -59,3 +59,5 @@ translations: file: 'docbot.translations' monitoring: file: 'docbot.monitoring' +system: + pidfile: 'docbot.pid' diff --git a/docbot.pl b/docbot.pl index 23d2acb..459206d 100755 --- a/docbot.pl +++ b/docbot.pl @@ -51,6 +51,7 @@ use POSIX ":sys_wait_h"; use Scalar::Util 'refaddr'; use YAML::XS qw (/./); use URI::Escape; +use File::Pid; use feature qw/switch/; import docbot::config; import docbot::db; @@ -158,6 +159,28 @@ if (length($main::config_file) > 0) { init_translations(); read_translations($main::translations_file); + +# create pid file +my $pidfile_name = config_get_key2('system', 'pidfile'); +my ($pidfile); +if (defined($pidfile_name)) { + my $pidfile = File::Pid->new({ file => $pidfile_name, pid => $$ }); + my $pid_running = $pidfile->running; + if (defined($pid_running)) { + print_msg("Another docbot instance is running!", ERROR); + print_msg("PID of the other instance: $pid_running", INFO); + exit(1); + } + if (!defined($pidfile->write)) { + my $error_msg = $!; + print_msg("Not able to write PID file!", ERROR); + print_msg("Error: $error_msg", INFO); + exit(1); + } + print_msg("Wrote PID " . $pidfile->pid . " to file " . $pidfile_name . "", DEBUG); +} + + init_database(); init_sessions();