]> git.proxmox.com Git - pmg-api.git/commitdiff
install pmgdaemon service
authorDietmar Maurer <dietmar@proxmox.com>
Thu, 26 Jan 2017 09:56:15 +0000 (10:56 +0100)
committerDietmar Maurer <dietmar@proxmox.com>
Thu, 26 Jan 2017 09:56:15 +0000 (10:56 +0100)
Makefile
PMG/Service/pmgdaemon.pm [new file with mode: 0755]
bin/pmgdaemon [new file with mode: 0755]
debian/control
debian/pmgdaemon.service [new file with mode: 0644]
debian/rules

index da6fe1f3c1bb82f00b0164043944e33e6dfc057d..ba668d900244278719a57dd4a726e080ab943bc5 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -26,14 +26,19 @@ PMG/pmgcfg.pm: PMG/pmgcfg.pm.in
        mv $@.tmp $@
 
 install: ${BTDATA} PMG/pmgcfg.pm
-       install -d -m 755 ${PERL5DIR}/PMG
-       install -d -m 755 ${PERL5DIR}/PMG/API2
+       install -d -m 0755 ${PERL5DIR}/PMG
+       install -d -m 0755 ${PERL5DIR}/PMG/API2
+       install -d -m 0755 ${PERL5DIR}/PMG/Service
        install -m 0644 PMG/pmgcfg.pm ${PERL5DIR}/PMG
        install -m 0644 PMG/API2.pm ${PERL5DIR}/PMG
        install -m 0644 PMG/HTTPServer.pm ${PERL5DIR}/PMG
        install -m 0644 PMG/Ticket.pm ${PERL5DIR}/PMG
+       install -m 0644 PMG/AccessControl.pm ${PERL5DIR}/PMG
        install -m 0644 PMG/API2/Nodes.pm ${PERL5DIR}/PMG/API2
-
+       install -m 0644 PMG/API2/AccessControl.pm ${PERL5DIR}/PMG/API2
+       install -m 0644 PMG/Service/pmgdaemon.pm ${PERL5DIR}/PMG/Service
+       install -d -m 0755 ${DESTDIR}/usr/bin
+       install -m 0755 bin/pmgdaemon ${DESTDIR}/usr/bin
 
 .PHONY: upload
 upload: ${DEB}
diff --git a/PMG/Service/pmgdaemon.pm b/PMG/Service/pmgdaemon.pm
new file mode 100755 (executable)
index 0000000..b5bdfba
--- /dev/null
@@ -0,0 +1,69 @@
+package PMG::Service::pmgdaemon;
+
+use strict;
+use warnings;
+
+use PVE::SafeSyslog;
+use PVE::Daemon;
+use PMG::API2;
+use PVE::APIServer::Formatter::Standard;
+use PVE::APIServer::Formatter::HTML;
+use PMG::HTTPServer;
+
+use base qw(PVE::Daemon);
+
+my $cmdline = [$0, @ARGV];
+
+my %daemon_options = (
+    max_workers => 3,
+    restart_on_error => 5,
+    stop_wait_time => 15,
+    leave_children_open_on_reload => 1,
+);
+
+my $daemon = __PACKAGE__->new('pmgdaemon', $cmdline, %daemon_options);
+
+sub init {
+    my ($self) = @_;
+
+    my $accept_lock_fn = "/var/lock/pmgdaemon.lck";
+
+    my $lockfh = IO::File->new(">>${accept_lock_fn}") ||
+       die "unable to open lock file '${accept_lock_fn}' - $!\n";
+
+    my $socket = $self->create_reusable_socket(85, '127.0.0.1');
+
+    $self->{server_config} = {
+       title => 'PMG API Daemon',
+       cookie_name => 'PMG',
+       keep_alive => 100,
+       max_conn => 500,
+       max_requests => 1000,
+       lockfile => $accept_lock_fn,
+       socket => $socket,
+       lockfh => $lockfh,
+       debug => $self->{debug},
+       trusted_env => 1,
+    };
+}
+
+sub run {
+    my ($self) = @_;
+
+    my $server = PMG::HTTPServer->new(%{$self->{server_config}});
+    $server->run();
+}
+
+$daemon->register_start_command();
+$daemon->register_restart_command(1);
+$daemon->register_stop_command();
+$daemon->register_status_command();
+
+our $cmddef = {
+    start => [ __PACKAGE__, 'start', []],
+    restart => [ __PACKAGE__, 'restart', []],
+    stop => [ __PACKAGE__, 'stop', []],
+    status => [ __PACKAGE__, 'status', [], undef, sub { print shift . "\n";} ],
+};
+
+1;
diff --git a/bin/pmgdaemon b/bin/pmgdaemon
new file mode 100755 (executable)
index 0000000..a5e84f4
--- /dev/null
@@ -0,0 +1,26 @@
+#!/usr/bin/perl -T
+
+$ENV{'PATH'} = '/sbin:/bin:/usr/sbin:/usr/bin';
+
+delete @ENV{qw(IFS CDPATH ENV BASH_ENV)};  
+
+use strict;
+use warnings;
+
+use PVE::SafeSyslog;
+use PMG::Service::pmgdaemon;
+
+$SIG{'__WARN__'} = sub {
+    my $err = $@;
+    my $t = $_[0];
+    chomp $t;
+    print STDERR "$t\n";
+    syslog('warning', "%s", $t);
+    $@ = $err;
+};
+
+my $prepare = sub {
+    # create something?
+};
+
+PMG::Service::pmgdaemon->run_cli_handler(prepare => $prepare);
index ef8cab0f99e78180692ce5119f0daf1f2ee7a471..149902144c5a7a6866539f79b487af255c7544f6 100644 (file)
@@ -2,7 +2,7 @@ Source: proxmox-mailgateway-api
 Section: perl
 Priority: optional
 Maintainer: Proxmox Support Team <support@proxmox.com>
-Build-Depends: debhelper (>= 9), perl (>= 5.10.0-19)
+Build-Depends: debhelper (>= 9), perl (>= 5.10.0-19), dh-systemd
 Standards-Version: 3.9.5
 Homepage: http://www.proxmox.com
 
diff --git a/debian/pmgdaemon.service b/debian/pmgdaemon.service
new file mode 100644 (file)
index 0000000..3687e55
--- /dev/null
@@ -0,0 +1,17 @@
+[Unit]
+Description=PMG API Daemon
+ConditionPathExists=/usr/bin/pmgdaemon
+Wants=ssh.service
+Wants=remote-fs.target
+After=ssh.service
+After=remote-fs.target
+
+[Service]
+ExecStart=/usr/bin/pmgdaemon start
+ExecStop=/usr/bin/pmgdaemon stop
+ExecReload=/usr/bin/pmgdaemon restart
+PIDFile=/var/run/pmgdaemon.pid
+Type=forking
+
+[Install]
+WantedBy=multi-user.target
index 2a6e77daaef0a1144b4cb21a0e8f42690c9224aa..86898d2905e63d7813f9f88704bdee04351bdf7c 100755 (executable)
@@ -5,5 +5,7 @@
 
 
 %:
-       dh $@
+       dh $@ --with=systemd
 
+override_dh_installinit:
+       dh_systemd_enable --name=pmgdaemon pmgdaemon.service