Table of Contents
tvpowerd — Companion power management daemon for tvpvrd
tvpowerd(1) is a companion daemon that is meant to be used in conjunction with the tvpvrd(1) TV-recording daemon, However, it is vital and absolutely necessary that this daemon is run on a completely different physical server. The reason is that this daemon monitors the server doing the TV-recording and turns the power to the recording server on and off according to the recording schedule. This will allow the tv-recording server to act as a faithful imitation of a real VCR (or Digital PVR). This is good solution if you normally have one server that is constantly running (such as you mail- or file server) where this daemon can run (it takes virtually no extra CPU and a very small memory footprint). The media server doing the recording is often located somewhere else , perhaps in the TV-room, and it is desirable to both have it quiet when it is not recording as well as saving on the planets energy.
In order for this to work there are a few, but vital, pre-conditions that must be fulfilled.
Both server must have network connections and have ssh(1) installed (this is true for basically all Linux distributions)
The server running the recording daemon must allow the server running the power daemon to login via SSH certificate without password. This is easy done by copying the power servers public SSH key into the file "authorized_keys" on the TV-recording server. This is described in details further down.
The server running the TV recording must support Wake-On-Lan, i.e. it must be possible to turn the power on by sending a special data package to the network card. Virtually all network cards support Wake-On-Lan as well as most motherboards and BIOS. However, it is usually necessary to enable this feature in BIOS (it is often called something similar to "Wake-Up-On-PCI event".
The rest of the man page will go through the detailed step in setting this up.
The following arguments are supported
-d
, --daemon
[y|n]Determine whether the server should be disconnected from the controlling terminal (a.k.a. running as a daemon). If the server is run as a daemon the logfile cannot be 'stdout'. This command line option will override the 'daemon' setting in the ini-file. The default setting is to run as a daemon.
-h
, --help
Print a short help and exit.
-i
, --inifile
filename
Use the specified file as configuration file. This will override the
location specified at compile time. The default location is
'/etc/tvpvrd/tvpvrd.conf
'
-l
, --logfile
filename
Define what logfile to use. Two special names can be used
stdout
which will cause the log to be written
to the stdout and syslog
which
will cause the logs to be written using the default system log. This
command line option will override the 'logfile'
setting in the ini-file. The default location is
'/tmp/tvpvrd.log
'
-V
, --verbose
[0|1|2|3]Log verbosity level. 0 will only log error messages, 1 will log error and info messages, 2 will log errors, info and additional notices finally 3 will also log high volume debug messages.
-v
, --version
Print program version information and exit.
The default arguments corresponds to starting the server with
tvpvrd -d y -i /etc/tvpowerd/tvpowerd.conf -V 1 -l /tmp/tvpowerd.log
While strictly speaking not necessary the server should normally be started by the root user. As soon as the server doesn't need root privileges it will switch to run as the user specified in the ini-file, by default this is the user tvpowerd. This user should for security reasons not be the 'root' user. This user should be a system user without login shell. Such a user can normally be created by running the command 'useradd'. (If the server is installed via the RPM package this user will be automatically created)
$> useradd -r tvpowerd
To start the server as root the simplest way is to just call
$root> tvpowerd
In order to stop the server and allow it to do a clean shutdown the
SIGHUP
(or SIGSTOP
) signal should be sent to the
process running the server (assuming tvpvrd has been started as a daemon). The
distribution includes two support scripts to help with this.
The first script will be automatically installed in
"/etc/init.d/tvpvrd
" and follows the normal guidelines for
a "init.d
" service start/stopping script according to LSB
(Linux Standard Base). Using this script to start the server the command
/etc/init.d/tvpowerd start
is given and to stop the server the command
/etc/init.d/tvpowerd stop
should be given. The startup script also supports the "restart" and "status" options.
Finally if for some reason you don't want to use any of these scripts it is possible to manually kill the daemon process by sending the SIGHUP signal via the 'kill'command as
$> kill -SIGHUP <pid>
where <pid> is the process id of the tvpowerd daemon. Use
'ps xa' to find the pid or if the server was started as root look in the file
'/var/run/tvpowerd.pid
'
If the server gives the error message : "Server can not be started. See
system log" then more information about the details of the problem
can be found in the system log, normally /var/log/messages
. One
common issue might be a stale lock file (in
/var/run/tvpowerd.pid
) in case the server is not started
from the root user. The reason is that in order to write these lock files the server
must run as a root. Since normally the server only runs as a root at the startup
phase (and then switches over to the selected user) the lock/pid file cannot be
removed. This is not a problem if the server is again started as root but if the
server is started from the command line as a non-root user it will complain that the
lock file already exists. The solution in this case is to manually remove the
lockfile (as root).
The specific way to shutdown the remote recording server can be specified in the configuration file. By default the server will be shutdown via a standard call to shutdonw -h <time> command.
A variant of this is to put the recording server in suspend or hibernation mode. Most reasonable modern computers will support this way of energy saving. Unfortunately the ivtv driver (that controls the TV-card) is not aware of power management which means that it will not survive a suspend-wakeup cycle. In order for the driver to work it must firs be unloaded before the server is shut down and then reloaded when the server is started up. The driver load/unload will be handled automatically if the unload_driver variable is set as
unload_driver=yes
in the configuration file.
Note 1: If you decide to use suspend/resume it is probably best to try the commands manually first to make sure it works as expected.
Note 2: The suspend/hibernate shutdown method should still be regarded as experimental since experience shows that depending on hardware and system configuration this is not always 100% reliable. On some hardware/system configurations it has been reported that after a suspend a driver unload/load cycle is still no sufficient to make the driver work again. On yet other HW it has been reported that the daemon does no longer respond after a suspend/wakeup cycle. If yoiu experince these problems please use the default shutdown method.
The daemon follows a number of strict rules when it will and when it wont shutdown the remote server. The daemon will only shutdown the recording server it the following conditions are satisfied:
There are no users logged into the recording server.
The 5 min avg load on the server is less than
max_shutdown_5load
as specified in the configuration
file (default is 0.5). This helps prevent shutdown if the user has
manually started some jobs on the server.
There are no ongoing transcodings or recordings.
It is at least min_poweroff_time
minutes until the next
recording as specified in the configuration file (default is
45min).
Tip: In order to manually force a wakeup the daemon will look for a an (empty)
file named /tmp/start_tvp
so giving the command
$>touch /tmp/start_tvp
will force a restart of the recording server. The daemon will remove the file after it has been seen to avoid endless wake-up events.
In order for the daemon to be able to turn the power off on the remote machine it must be given root permission. Since we want to avoid to store plain passwords (especially the root password) in configuration file the best way to solve this is to allow the managing server (the one running the daemon) to log into the recording server via ssh certificates.
This is done by adding the public ssh certificate from the user running the tvpowerd to the list of authorized users that can log into the root account on the recording daemon.
Assuming the power daemon is running as user 'tvpower
' (we assume
that the user exists and has been created). The following steps will create and
install the public key on the recording server.
On the managing server. Switch to the 'tvpower' user and give the following command
$tvpower>ssh-keygen
When asked for a password just type return (twice) to create a
certificate without password. The public certificate will be stored in
the file '~tvpower/.ssh/id_rsa.pub
'
The next step is to add the content of the
'~tvpower/.ssh/id_rsa.pub
' file to the end of
the root users '.ssh/authorized_keys
' file on the
recording server.
After this is done it should be possible for the tvpower
user to login to the recording server as root without giving a password
using ssh. Make sure that it is possible to execute
a remote command on the recording server as root user without giving a
password. For example the following command (replace the "fake" IP 192.168.0.100 with the IP address of your
recording server).
$tvpower>ssh root@192.168.0.100 uptime
14:22pm up 1:13, 2 users, load average: 0.00, 0.00, 0.00
$tvpower> _
If this does not work go back and check that no extra blanks or line
breaks where inserted by mistake when the public key was copied. Also
check that it was really the public key from the tvpower
user on the managing server that was added to the root
user
on the recording server.
It is absolutely critical that the ssh login works before moving on. Without this functionality the daemon will no be able to function as intended.
Note: The system configuration directory to be used is a compile time settings and specified with the 'configuration' argument '--sysconfdir'.
The logfile. The log-directory is specified in the ini-file. It can
also be specified as a command line argument (-l,
--logfile
) which will then override the ini-file setting.
By default the log file will be stored under
/tmp/tvpvrd.log
.(The reason not to use
/var/log/tvpowerd.log
is the fact that the
server will not normally run as root and hence will not have write
access to this directory.)
The pid of the started 'tvpvrd' server. This is used to easily find the pid in order to shutdown the server. This is used by the stop-tvpvrd script. Note that in order to use this directory the daemon has to be started by the root user.
Default configuration file
The /var/run/tvpowerd.pid
file is not removed
after the program has shut down if the effective user is any other than
'root', (by default the server will switch to the 'tvpvrd' user) since
only root has access to /var/run
All information and error messages are hard coded in English and cannot be easily localized.
Any errors that are discovered in the startup phase before a logfile has been
established will be written to the default system log (normally
/var/log/messages
)