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