-
Notifications
You must be signed in to change notification settings - Fork 1
Home
Welcome to the napd wiki!
napd will put your computer to sleep according to a set of easily defined rules (e.g. "vlc is not running" or "there are no active connections on mysql").
4 kind of things can be tracked :
- PIDs (which must be specified at runtime).
- running systemd units.
- processes (by full path, basename, or cmdline).
- custom scripts whose return value are checked.
Something providing the logind D-Bus API, QtDBus, QMake. Also, if units file are to be checked, the systemd1 D-Bus API is required.
cd your_build_folder
qmake path/to/src/Base.pro
make
make install
The configuration format is similar to systemd unit files and is, for now, very likely to change.
There are exemples files in the source tree (lib/napd/). napd checks for its configuration in /etc/napd... For now there is no install script (I guess it is more a "distro" work).
After creating the configuration files, they should be enabled with napctl (see below).
/etc/napd/processes.d
[Process]
# Any combination of MatchingPath, MatchingBasename, MatchingCmdline.
MatchingPath=/opt/google/chrome-unstable/chrome
MatchingBasename=chrome
MatchingCmdline=/opt/google/chrome-unstable/chrome --type=gpu-broker
Timeout=42 # The number of second the timer waits if this process is found running.
/etc/napd/units.d
[Unit]
UnitName=apache2.service # Mandatory
Timeout=42 # Facultative, the number of second the timer waits if this unit is found running.
/etc/napd/checks.d
[Check]
Exec=/some/script.sh # Mandatory
MustEqual=46 # Expected return value of the program. Default is 0.
AsUser=napd # Default is the user napd is ran as.
Timeout=42 # The number of second the timer waits if this check is true.
napd comes with an utility named napctl.
-
Syntax :
napctl command arguments
-
Available commands
- add-pid PID [timeout] : adds a PID to track, with an optional timeout
- remove-pid PID : removes a tracked PID
- enable : enables a file in
/etc/napd/{checks,processes,units}.dby making a symlink towards it in theactivesubfolder of the relevant folder - disable : disables a file in
/etc/napd/{checks,processes,units}.dby removing it.
-
SSH: Returns 0 if there are no active SSH clients connected to this computer.
[[ -z "$(netstat -t -n -A inet|awk -F ' ' '{print $4}'|grep ':22')" ]] -
NFS: Returns 0 if no computers are mounting any NFS shares from this computer.
[[ -z $(showmount|tail -n +2) ]] -
SMB : Returns 0 if there are no Samba clients connected.
[[ -z $(smbstatus -bp|grep -P '\b(?:\d{1,3}\.){3}\d{1,3}\b') ]] -
MySQL : Returns 0 if there is nobody accessing the DB right now.
[[ $(sudo mysqladmin -uYOURUSER -pYOURPASSWORD extended-status | grep -wi 'threads_connected' | awk '{ print $4}') -gt "1" ]] -
Deluge : Returns 0 if there are no active torrents.
[[ -z $(deluge-console info|egrep 'Downloading|Seeding') ]]