]> git.proxmox.com Git - pve-manager.git/blob - PVE/Service/pvedaemon.pm
remove base_handler_class - directly use PVE::API2 instead
[pve-manager.git] / PVE / Service / pvedaemon.pm
1 package PVE::Service::pvedaemon;
2
3 use strict;
4 use warnings;
5
6 use PVE::SafeSyslog;
7 use PVE::Daemon;
8 use PVE::API2;
9 use PVE::APIServer::Formatter::Standard;
10 use PVE::APIServer::Formatter::HTML;
11 use PVE::HTTPServer;
12
13 use base qw(PVE::Daemon);
14
15 my $cmdline = [$0, @ARGV];
16
17 my %daemon_options = (
18 max_workers => 3,
19 restart_on_error => 5,
20 stop_wait_time => 15,
21 leave_children_open_on_reload => 1,
22 );
23
24 my $daemon = __PACKAGE__->new('pvedaemon', $cmdline, %daemon_options);
25
26 sub init {
27 my ($self) = @_;
28
29 my $accept_lock_fn = "/var/lock/pvedaemon.lck";
30
31 my $lockfh = IO::File->new(">>${accept_lock_fn}") ||
32 die "unable to open lock file '${accept_lock_fn}' - $!\n";
33
34 my $socket = $self->create_reusable_socket(85, '127.0.0.1');
35
36 $self->{server_config} = {
37 keep_alive => 100,
38 max_conn => 500,
39 max_requests => 1000,
40 lockfile => $accept_lock_fn,
41 socket => $socket,
42 lockfh => $lockfh,
43 debug => $self->{debug},
44 trusted_env => 1,
45 };
46 }
47
48 sub run {
49 my ($self) = @_;
50
51 my $server = PVE::HTTPServer->new(%{$self->{server_config}});
52 $server->run();
53 }
54
55 $daemon->register_start_command();
56 $daemon->register_restart_command(1);
57 $daemon->register_stop_command();
58 $daemon->register_status_command();
59
60 our $cmddef = {
61 start => [ __PACKAGE__, 'start', []],
62 restart => [ __PACKAGE__, 'restart', []],
63 stop => [ __PACKAGE__, 'stop', []],
64 status => [ __PACKAGE__, 'status', [], undef, sub { print shift . "\n";} ],
65 };
66
67 1;