]> git.proxmox.com Git - pve-manager.git/blob - bin/pvedaemon
new html formatter PVE::API2::Formatter::HTML
[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 use Getopt::Long;
10 use POSIX ":sys_wait_h";
11 use Socket;
12 use PVE::SafeSyslog;
13 use PVE::APIDaemon;
14 use PVE::API2;
15 use PVE::API2::Formatter::Standard;
16 use PVE::API2::Formatter::HTML;
17
18 my $pidfile = "/var/run/pvedaemon.pid";
19 my $lockfile = "/var/lock/pvedaemon.lck";
20
21 my $opt_debug;
22
23 initlog ('pvedaemon');
24
25 if (!GetOptions ('debug' => \$opt_debug)) {
26 die "usage: $0 [--debug]\n";
27 }
28
29 $SIG{'__WARN__'} = sub {
30 my $err = $@;
31 my $t = $_[0];
32 chomp $t;
33 syslog('warning', "WARNING: %s", $t);
34 $@ = $err;
35 };
36
37 $0 = "pvedaemon";
38
39 # create dir for dtach sockets
40 mkdir "/var/run/dtach";
41
42 my $cpid;
43 my $daemon;
44 eval {
45 $daemon = PVE::APIDaemon->new(
46 base_handler_class => 'PVE::API2',
47 host => "127.0.0.1",
48 port => 85,
49 trusted_env => 1, # partly trusted, because only local programs can connect
50 lockfile => $lockfile,
51 debug => $opt_debug,
52 keep_alive => 100,
53 max_conn => 500,
54 max_requests => 1000);
55 };
56
57 my $err = $@;
58
59 if ($err) {
60 syslog ('err' , "unable to start server: $err");
61 print STDERR $err;
62 exit (-1);
63 }
64
65 if ($opt_debug || !($cpid = fork ())) {
66
67 $SIG{PIPE} = 'IGNORE';
68 $SIG{INT} = 'IGNORE' if !$opt_debug;
69
70 $SIG{TERM} = $SIG{QUIT} = sub {
71 syslog ('info' , "server closing");
72
73 $SIG{INT} = 'DEFAULT';
74
75 unlink "$pidfile";
76
77 exit (0);
78 };
79
80 syslog ('info' , "starting server");
81
82 if (!$opt_debug) {
83 # redirect STDIN/STDOUT/SDTERR to /dev/null
84 open STDIN, '</dev/null' || die "can't read /dev/null [$!]";
85 open STDOUT, '>/dev/null' || die "can't write /dev/null [$!]";
86 open STDERR, '>&STDOUT' || die "can't open STDERR to STDOUT [$!]";
87 }
88
89 POSIX::setsid();
90
91 system ("echo > /var/lib/pve-manager/vmops"); # init vmops file
92
93 eval {
94 $daemon->start_server();
95 };
96 my $err = $@;
97
98 if ($err) {
99 syslog ('err' , "unexpected server error: $err");
100 print STDERR $err if $opt_debug;
101 exit (-1);
102 }
103
104 } else {
105
106 open (PIDFILE, ">$pidfile") ||
107 die "cant write '$pidfile' - $! :ERROR";
108 print PIDFILE "$cpid\n";
109 close (PIDFILE) ||
110 die "cant write '$pidfile' - $! :ERROR";
111 }
112
113 exit (0);
114
115 __END__
116
117 =head1 NAME
118
119 pvedaemon - the PVE configuration server
120
121 =head1 SYNOPSIS
122
123 pvedaemon [--debug]
124
125 =head1 DESCRIPTION
126
127 All configuration is done using this Server. The Server only
128 listens to a local address 127.0.0.1 port 85 for security
129 reasons.
130
131 =head1 COPYRIGHT AND DISCLAIMER
132
133 Copyright (C) 2007-2013 Proxmox Server Solutions GmbH
134
135 This program is free software: you can redistribute it and/or modify it
136 under the terms of the GNU Affero General Public License as published
137 by the Free Software Foundation, either version 3 of the License, or
138 (at your option) any later version.
139
140 This program is distributed in the hope that it will be useful, but
141 WITHOUT ANY WARRANTY; without even the implied warranty of
142 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
143 Affero General Public License for more details.
144
145 You should have received a copy of the GNU Affero General Public
146 License along with this program. If not, see
147 <http://www.gnu.org/licenses/>.
148