]> git.proxmox.com Git - pve-manager.git/blob - bin/pvedaemon
move preparations into prepare()
[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 my $daemon = __PACKAGE__->new('pvedaemon', $cmdline, %daemon_options);
38
39 sub prepare {
40 # create dir for dtach sockets
41 mkdir "/var/run/dtach";
42 }
43
44 sub init {
45 my ($self) = @_;
46
47 my $accept_lock_fn = "/var/lock/pvedaemon.lck";
48
49 my $lockfh = IO::File->new(">>${accept_lock_fn}") ||
50 die "unable to open lock file '${accept_lock_fn}' - $!\n";
51
52 my $socket = $self->create_reusable_socket(85, '127.0.0.1');
53
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,
64 };
65 }
66
67 sub run {
68 my ($self) = @_;
69
70 my $server = PVE::HTTPServer->new(%{$self->{server_config}});
71 $server->run();
72 }
73
74 $daemon->register_start_command();
75 $daemon->register_restart_command(1);
76 $daemon->register_stop_command();
77 $daemon->register_status_command();
78
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 };
85
86 my $cmd = shift;
87
88 PVE::CLIHandler::handle_cmd($cmddef, $0, $cmd, \@ARGV, undef, $0, \&prepare);
89
90 exit (0);
91
92 __END__
93
94 =head1 NAME
95
96 pvedaemon - the PVE configuration server
97
98 =include synopsis
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
106 =include pve_copyright