~ubuntu-branches/debian/wheezy/ledcontrol/wheezy

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
This file documents how to make a new script for ledcontrol. You are
encouraged also to read the existing scripts found in scripts/*.sh

NOTE: The script interface has changed since version 0.4.0!!!
Variables LEDDPIPE and USLEEP are not defined anymore!


### Basic I/O

The interface to ledd has changed since version 0.4.0. With newer
versions everything the script writes to STDOUT is read as a command
given to ledd and everything written to STDERR is logged via syslog,
level LOG_WARNING.


### Variables

There are a few environment variables available to the script:

LEDDSCRIPTS	Directory in which all the scripts have (hopefully)
		been installed to, including startup.sh.

SUCCESS		Commands to be given in case of success/failure. The
FAILURE		function is allowed to change these (they won't affect
		the permanent settings).

COMMAND		Whole command that was given to start the function.

COUNT		Number from COMMAND_xxx (the xxx part).

USE_BACKGROUNDING Whether backgrounding of time-consuming checks is allowed.

### Startup

When started, startup.sh sources every script ending in .sh found in
$LEDDSCRIPTS, so you just have to write it there (note that the
executable bit doesn't have to be set). Every script should only
include one function that does the task. The function name should
start with led_ and have a short, distinct name that still informs of
the function.

You can also write the function into ledcontrol.conf.


### Normal checks

The normal type of checkers should just return 0 to signal success or
anything else to signal failure (for example file.sh, size.sh).


### Outputting arbitrary numbers

If you want to make a script that outputs an arbitrary number, you
should append the number to the environment variable SUCCESS and
return 0 (examples in load.sh, netload.sh).


### Doing nothing

In the case that the script temporarily can't get the required
information and would like to return without modifying anything you
should set SUCCESS=nop and return 0.


### Time-consuming checks

If the check will/might take a long time (>5 seconds) then you should
check if $USE_BACKGROUNDING is set to "YES" (or "yes") and if so, then
make a background process which will test it and "echo $SUCCESS" or
"echo $FAILURE". The process itself should set SUCCESS=nop and
return 0. If $USE_BACKGROUNDING is not YES, it should just test it and
return the result. Note that when making the background process, use
should ALWAYS check if the old process is still running and in case it
is set SUCCESS=nop and return 0. You can do this by saving the PID of
the checker (given in $!) and checking if /proc/$PID exists. A good
example is given in ping.sh.


### Saving data

You may use nearly any environment variable internally (except
eg. COUNT), but you should not rely that it is the same on the next
round (remember - there may be several versions of the check
running). If you want to save information for the next time, save them
in LED_NAME_DESC_$COUNT where NAME is the name of the function, DESC
is a short name for the data and at the end the value of $COUNT. You
can write to it by

eval 'LED_NAME_DESC_'$COUNT'="DATA $VARIABLE etc"'

(write the strings and contents of $VARIABLE) and read it similarly
with

eval 'LOCAL=LED_NAME_DESC_'$COUNT

(read it to variable LOCAL). A good example of this can be found in
netload.sh.


### If all else fails

1. Read the existing scripts! 
2. Figure a neat way of doing it!
3. Mail me!


### After you have made the script

1. Mail me, Sampo Niskanen <sampo.niskanen@iki.fi>, with it.