Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
P
pve-manager
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Administrator
pve-manager
Commits
2927811f
Commit
2927811f
authored
Dec 18, 2014
by
Dietmar Maurer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
pvestatd: use new Daemon class from pve-common
parent
4dbb80bb
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
83 additions
and
157 deletions
+83
-157
Makefile
bin/Makefile
+3
-0
pvestatd
bin/init.d/pvestatd
+27
-29
pvestatd
bin/pvestatd
+53
-128
No files found.
bin/Makefile
View file @
2927811f
...
...
@@ -43,6 +43,9 @@ all: ${MANS} pvemailforward
%.1.pod
:
%
podselect
$*
>
$@
pvestatd.1.pod
:
pvestatd
perl
-I
.. ./pvestatd printmanpod
>
$@
pvectl.1.pod
:
pvectl
perl
-I
.. ./pvectl printmanpod
>
$@
...
...
bin/init.d/pvestatd
View file @
2927811f
...
...
@@ -18,38 +18,36 @@ DESC="PVE Status Daemon"
PIDFILE
=
/var/run/pvestatd.pid
# Exit if the package is not installed
test
-f
$DAEMON
||
exit
0
[
-e
/proxmox_install_mode
]
&&
exit
0
# avoid warnings about uninstalled locales
export
LC_ALL
=
"C"
case
"
$1
"
in
start
)
log_daemon_msg
"Starting
$DESC
"
"
$NAME
"
start-stop-daemon
--start
--quiet
--pidfile
$PIDFILE
--exec
$DAEMON
log_end_msg
$?
;;
stop
)
log_daemon_msg
"Stopping
$DESC
"
"
$NAME
"
start-stop-daemon
--stop
--quiet
--retry
TERM/5/TERM/10/KILL/2
--pidfile
$PIDFILE
log_end_msg
$?
;;
reload
)
log_daemon_msg
"Reloading
$DESC
"
"
$NAME
"
if
(
[
-e
$PIDFILE
]
&&
kill
-0
`
cat
$PIDFILE
`
)
then
start-stop-daemon
--stop
--quiet
--pidfile
$PIDFILE
--signal
HUP
else
start-stop-daemon
--start
--quiet
--pidfile
$PIDFILE
--exec
$DAEMON
fi
log_end_msg
$?
;;
restart|force-reload
)
log_daemon_msg
"Restarting
$DESC
"
"
$NAME
"
start-stop-daemon
--stop
--quiet
--retry
TERM/5/TERM/10/KILL/2
--pidfile
$PIDFILE
start-stop-daemon
--start
--quiet
--pidfile
$PIDFILE
--exec
$DAEMON
log_end_msg
$?
;;
*
)
N
=
/etc/init.d/
$NAME
echo
"Usage:
$N
{start|stop|reload|restart|force-reload}"
>
&2
exit
1
start
)
log_daemon_msg
"Starting
$DESC
"
"
$NAME
"
$DAEMON
start
log_end_msg
$?
;;
stop
)
log_daemon_msg
"Stopping
$DESC
"
"
$NAME
"
$DAEMON
stop
log_end_msg
$?
;;
status
)
$DAEMON
status
;;
reload|restart|force-reload
)
log_daemon_msg
"Restarting
$DESC
"
"
$NAME
"
$DAEMON
restart
log_end_msg
$?
;;
*
)
N
=
/etc/init.d/
$NAME
echo
"Usage:
$N
{start|stop|status|reload|restart|force-reload}"
>
&2
exit
1
;;
esac
...
...
bin/pvestatd
View file @
2927811f
...
...
@@ -3,9 +3,8 @@
use
strict
;
use
warnings
;
use
PVE::
SafeSyslog
;
use
POSIX
"
:sys_wait_h
";
use
Fcntl
'
:flock
';
use
Getopt::
Long
;
use
PVE::
Daemon
;
use
Time::
HiRes
qw (gettimeofday);
use
PVE::
Tools
qw(dir_glob_foreach file_read_firstline)
;
use
PVE::
ProcFSTools
;
...
...
@@ -19,120 +18,50 @@ use PVE::RPCEnvironment;
use
PVE::API2::
Subscription
;
use
PVE::
AutoBalloon
;
$SIG
{'
__WARN__
'}
=
sub
{
my
$err
=
$@
;
my
$t
=
$_
[
0
];
chomp
$t
;
syslog
('
warning
',
"
WARNING: %s
",
$t
);
$@
=
$err
;
};
initlog
('
pvestatd
');
$ENV
{'
PATH
'}
=
'
/sbin:/bin:/usr/sbin:/usr/bin
';
die
"
please run as root
\n
"
if
$>
!=
0
;
my
$nodename
=
PVE::INotify::
nodename
();
use
base
qw(PVE::Daemon)
;
my
$opt_debug
;
if
(
!
GetOptions
('
debug
'
=>
\
$opt_debug
))
{
die
"
USAGE: $0 [--debug]
\n
";
}
my
$opt_pidfile
=
"
/var/run/pvestatd.pid
";
my
$cmdline
=
[
$0
,
@ARGV
];
sub
lockpidfile
{
my
$pidfile
=
shift
;
my
$lkfn
=
"
$pidfile
.lock
";
my
%
daemon_options
=
(
restart_on_error
=>
5
,
stop_wait_time
=>
5
);
if
(
!
open
(
FLCK
,
"
>>
$lkfn
"))
{
my
$msg
=
"
can't aquire lock on file '
$lkfn
' - $!
";
syslog
('
err
',
$msg
);
die
"
ERROR:
$msg
\n
";
}
my
$daemon
=
__PACKAGE__
->
new
('
pvestatd
',
$cmdline
,
%
daemon_options
);
if
(
!
flock
(
FLCK
,
LOCK_EX
|
LOCK_NB
))
{
close
(
FLCK
);
my
$msg
=
"
can't aquire lock '
$lkfn
' - $!
";
syslog
('
err
',
$msg
);
die
"
ERROR:
$msg
\n
";
}
}
my
$rpcenv
=
PVE::
RPCEnvironment
->
init
('
cli
');
sub
writepidfile
{
my
$pidfile
=
shift
;
$rpcenv
->
init_request
();
$rpcenv
->
set_language
(
$ENV
{
LANG
});
$rpcenv
->
set_user
('
root@pam
');
if
(
!
open
(
PIDFH
,
"
>
$pidfile
"))
{
my
$msg
=
"
can't open pid file '
$pidfile
' - $!
";
syslog
('
err
',
$msg
);
die
"
ERROR:
$msg
\n
";
}
print
PIDFH
"
$$
\n
";
close
(
PIDFH
);
}
# try to get the lock
lockpidfile
(
$opt_pidfile
);
# run in background
my
$spid
;
my
$restart
=
$ENV
{
RESTART_PVESTATD
};
my
$nodename
=
PVE::INotify::
nodename
();
my
$restart_request
=
0
;
if
(
!
$opt_debug
)
{
open
STDIN
,
'
</dev/null
'
||
die
"
can't read /dev/null
";
open
STDOUT
,
'
>/dev/null
'
||
die
"
can't write /dev/null
";
}
sub
init
{
my
(
$self
)
=
@_
;
if
(
!
$restart
&&
!
$opt_debug
)
{
$spid
=
fork
();
if
(
!
defined
(
$spid
))
{
my
$msg
=
"
can't put server into background - fork failed
";
syslog
('
err
',
$msg
);
die
"
ERROR:
$msg
\n
";
}
elsif
(
$spid
)
{
#parent
exit
(
0
);
}
PVE::Cluster::
cfs_update
();
}
writepidfile
(
$opt_pidfile
);
open
STDERR
,
'
>&STDOUT
'
||
die
"
can't close STDERR
\n
";
sub
shutdown
{
my
(
$self
)
=
@_
;
sub
cleanup
{
unlink
"
$opt_pidfile
.lock
";
unlink
"
$opt_pidfile
";
}
$SIG
{
INT
}
=
$SIG
{
TERM
}
=
$SIG
{
QUIT
}
=
sub
{
syslog
('
info
'
,
"
server closing
");
$SIG
{
INT
}
=
'
DEFAULT
';
# wait for children
1
while
(
waitpid
(
-
1
,
POSIX::
WNOHANG
())
>
0
);
cleanup
();
exit
(
0
);
};
$self
->
exit_daemon
(
0
);
}
PVE::INotify::
inotify_init
();
sub
hup
{
my
(
$self
)
=
@_
;
my
$reload_config
;
syslog
('
info
'
,
"
received signal HUP
")
;
if
(
$restart
)
{
syslog
('
info
'
,
"
restarting server
");
}
else
{
syslog
('
info
'
,
"
starting server
");
$restart_request
=
1
;
}
$SIG
{
HUP
}
=
sub
{
$reload_config
=
1
;
};
sub
update_node_status
{
my
(
$avg1
,
$avg5
,
$avg15
)
=
PVE::ProcFSTools::
read_loadavg
();
...
...
@@ -272,6 +201,7 @@ sub find_vzctl_console_pids {
return
$res
;
}
sub
remove_stale_openvz_consoles
{
my
$vmstatus
=
PVE::OpenVZ::
vmstatus
();
...
...
@@ -383,36 +313,18 @@ my $next_update = 0;
my
$cycle
=
0
;
my
$updatetime
=
10
;
my
$commandline
=
[
$0
,
@ARGV
];
$0
=
"
pvestatd
";
sub
restart_server
{
my
$waittime
=
shift
;
syslog
('
info
',
"
server shutdown (restart)
");
$ENV
{
RESTART_PVESTATD
}
=
1
;
sleep
(
$waittime
)
if
$waittime
;
# avoid high server load due to restarts
PVE::INotify::
inotify_close
();
exec
(
@$commandline
);
exit
(
-
1
);
# never reached?
}
my
$initial_memory_usage
;
for
(;;)
{
# forever
sub
run
{
my
(
$self
)
=
@_
;
eval
{
$next_update
=
time
()
+
$updatetime
;
for
(;;)
{
# forever
$next_update
=
time
()
+
$updatetime
;
if
(
$cycle
)
{
my
(
$ccsec
,
$cusec
)
=
gettimeofday
();
eval
{
$reload_config
=
0
;
# syslog('info', "start status update");
PVE::Cluster::
cfs_update
();
update_status
();
...
...
@@ -441,25 +353,35 @@ for (;;) { # forever
if
(
$diff
>
5
*
1024
*
1024
)
{
syslog
('
info
',
"
restarting server after
$cycle
cycles to
"
.
"
reduce memory usage (free
$mem
->{resident} (
$diff
) bytes)
");
restart_server
();
$self
->
restart_daemon
();
}
}
my
$wcount
=
0
;
while
((
time
()
<
$next_update
)
&&
(
$wcount
<
$updatetime
)
&&
# protect against time wrap
!
$reload_config
)
{
$wcount
++
;
sleep
(
1
);
};
};
!
$restart_request
)
{
$wcount
++
;
sleep
(
1
);
};
my
$err
=
$@
;
if
(
$err
)
{
syslog
('
err
',
"
ERROR:
$err
");
restart_server
(
5
);
exit
(
0
);
$self
->
restart_daemon
()
if
$restart_request
;
}
}
$daemon
->
register_start_command
(
__PACKAGE__
);
$daemon
->
register_restart_command
(
__PACKAGE__
);
$daemon
->
register_stop_command
(
__PACKAGE__
);
$daemon
->
register_status_command
(
__PACKAGE__
);
my
$cmddef
=
{
start
=>
[
__PACKAGE__
,
'
start
',
[]
],
restart
=>
[
__PACKAGE__
,
'
restart
',
[]
],
stop
=>
[
__PACKAGE__
,
'
stop
',
[]
],
status
=>
[
__PACKAGE__
,
'
status
',
[]
,
undef
,
sub
{
print
shift
.
"
\n
";}
],
};
my
$cmd
=
shift
;
PVE::CLIHandler::
handle_cmd
(
$cmddef
,
$0
,
$cmd
,
\
@ARGV
,
undef
,
$0
);
exit
(
0
);
__END__
...
...
@@ -470,11 +392,14 @@ pvestatd - PVE Status Daemon
=head1 SYNOPSIS
pvestatd
=include synopsis
=head1 DESCRIPTION
Documentation is available at www.proxmox.com
This daemom queries the status of VMs, storages and containers at
regular intervals. The result is sent to all nodes in the cluster.
=include pve_copyright
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment