use Scalar::Util 'refaddr';
use YAML::XS qw (/./);
use URI::Escape;
+use File::Pid;
use feature qw/switch/;
import docbot::config;
import docbot::db;
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();