]> git.proxmox.com Git - pve-manager.git/blob - bin/pvedaemon
remove class APIDaemon
[pve-manager.git] / bin / pvedaemon
1 #!/usr/bin/perl -T
2
3 $ENV{'PATH'} = '/sbin:/bin:/usr/sbin:/usr/bin';
4
5 delete @ENV{qw(IFS CDPATH ENV BASH_ENV)};
6
7 use strict;
8 use warnings;
9
10 use PVE::SafeSyslog;
11 use PVE::Daemon;
12 use PVE::API2;
13 use PVE::API2::Formatter::Standard;
14 use PVE::API2::Formatter::HTML;
15 use PVE::HTTPServer;
16
17 use base qw(PVE::Daemon);
18
19 $SIG{'__WARN__'} = sub {
20 my $err = $@;
21 my $t = $_[0];
22 chomp $t;
23 print STDERR "$t\n";
24 syslog('warning', "%s", $t);
25 $@ = $err;
26 };
27
28 my $cmdline = [$0, @ARGV];
29
30 my %daemon_options = (
31 max_workers => 3,
32 restart_on_error => 5,
33 stop_wait_time => 15,
34 leave_children_open_on_reload => 1,
35 );
36
37 # create dir for dtach sockets
38 mkdir "/var/run/dtach";
39
40 my $daemon = __PACKAGE__->new('pvedaemon', $cmdline, %daemon_options);
41
42 sub init {
43 my ($self) = @_;
44
45 my $accept_lock_fn = "/var/lock/pvedaemon.lck";
46
47 my $lockfh = IO::File->new(">>${accept_lock_fn}") ||
48 die "unable to open lock file '${accept_lock_fn}' - $!\n";
49
50 my $socket = $self->create_reusable_socket(85, '127.0.0.1');
51
52 $self->{server_config} = {
53 base_handler_class => 'PVE::API2',
54 keep_alive => 100,
55 max_conn => 500,
56 max_requests => 1000,
57 lockfile => $accept_lock_fn,
58 socket => $socket,
59 lockfh => $lockfh,
60 debug => $self->{debug},
61 trusted_env => 1,
62 };
63 }
64
65 sub run {
66 my ($self) = @_;
67
68 my $server = PVE::HTTPServer->new(%{$self->{server_config}});
69 $server->run();
70 }
71
72 $daemon->register_start_command();
73 $daemon->register_restart_command(1);
74 $daemon->register_stop_command();
75 $daemon->register_status_command();
76
77 my $cmddef = {
78 start => [ __PACKAGE__, 'start', []],
79 restart => [ __PACKAGE__, 'restart', []],
80 stop => [ __PACKAGE__, 'stop', []],
81 status => [ __PACKAGE__, 'status', [], undef, sub { print shift . "\n";} ],
82 };
83
84 my $cmd = shift;
85
86 PVE::CLIHandler::handle_cmd($cmddef, $0, $cmd, \@ARGV, undef, $0);
87
88 exit (0);
89
90 __END__
91
92 =head1 NAME
93
94 pvedaemon - the PVE configuration server
95
96 =include synopsis
97
98 =head1 DESCRIPTION
99
100 All configuration is done using this Server. The Server only
101 listens to a local address 127.0.0.1 port 85 for security
102 reasons.
103
104 =include pve_copyright