Previously I have discussed how fixing the Debian init script integration issues using only shell script, proved relatively successful but complex and unsatisfying. The duende approach seems more elegant and is of course the approach recommneded by upstream. However it has hitherto hit the fundamental issue that we need a pid file for the duende process. Apparently other people had had the same issue and provided a patch that provides an optional pid file argument. However this was not enough to complete the integration. Furthermore it occurred to me that duende could be of wider interest.

You must be wondering what a duende actually is and where the word comes from. According to wikipedia a duende is a "fairy- or goblin-like mythological creature from Iberian, Latin American and Filipino folklore". The word is a shortening of "duen de casa", meaning the "the owner of the house". I find these definitions hard to relate to the carnival pictures on the left. However Sam Trenholme says that the word simply means "daemon" in Spanish, which makes a lot more sense of those pictures and does also fit with what the executable does.
In local traditions the word often takes on extra colour. In the Phillipines:
They are known to be either good or mischievous, depending on how homeowners treat them. They usually come out at 12 noon for an hour and during the night. Filipinos always mutter words ("tabi-tabi po" or "bari-bari apo ma ka ilabas kami apo") asking them to excuse themselves for bothering the Duwendes. Filipinos would leave food on the floor, so that the duwende residing (or guarding) the house would not be angry with them. They also take your things, and laugh at you when you try to find it. They give it back when they feel like it, or when you tell them to please give it back.
In the Hispanic folklore of Central America and the American Southwest:
Duendes are known as gnome like creatures who live inside the walls of homes, especially in the bedroom walls of young children. They attempt to clip the toenails of unkempt children, often leading to the mistaken removal of entire toes.[2] They are also known for taking items from young children. They have also been able to barter with the mother of young children so that they can take the child and have them to eat. They appear at night when children are at play with a ball, and watch the children and later make their appearance and confront the children.
The concept of duende has also become a term in Spanish, meaning something like the spirit that transforms art from being merely skillful to being sublime. In 1933, the Spanish poet and playwright, Federico García Lorca, delivered a lecture in which he described the role of duende in art:
La Niña de Los Peines had to tear apart her voice, because she knew experts were listening, who demanded not form but the marrow of form, pure music with a body lean enough to float on air. She had to rob herself of skill and safety: that is to say, banish her Muse, and be helpless, so her duende might come, and deign to struggle with her at close quarters. And how she sang! Her voice no longer at play, her voice a jet of blood, worthy of her pain and her sincerity, opened like a ten-fingered hand as in the feet, nailed there but storm-filled, of a Christ by Juan de Juni.
The duende process starts a child process and a log helper process that captures the output from the child process and passes it onto syslog:
In order to better integrate duende into Debian and to baptise it as a useful program in its own right, I have added the following arguments to the duende code base:
| short form | long form | description |
|---|---|---|
| -c | --chroot=DIR | Directory log helper should change and chroot to |
| -g | --gid=GID | Groupid log helper should change down to |
| -i | --ident=STR | How log helper should be identified in syslog |
| -p | --pid=FILE | File used to store pid of duende process |
| -r | --restart_on=INT | Exit status on which to restart child process |
| -u | --uid=UID | Userid log helper should change down to |
These arguments are parsed with the argp
library and so the --usage, --help and -? arguments are supported.
There are a couple of other issues. It seemed that the log helper did not actually call chroot.
Also when collecting the exited children there seemed to be a race condition. As the duende code stands when the main child process exits, the log helper process will be killed and vice versa. The current code always tries to reap the main child process first and the log helper process second. I found that in some cases the log helper process gets missed and so a zombie process gets created. This Debian version reaps all exited child processes and takes the appropriate action according to whether this was a main child, the log helper or something that got missed from a previous cycle.
In this release I have provided an example Perl daemon script that can be used with this version of Duende. The script responds to various stimuli as follows:
| Stimulus | Response to stdout | Other repsonse |
| Every 61 seconds | Anyone there? | n/a |
| USR1 signal | Ouch! | n/a |
| USR2 signal | Stop that or I will blow your computer up! | n/a |
| HUP signal | n/a | exit 42 |
| HTTP access on port 8888 | Message from [host]:[port] | One line web page |
The example init script uses this version of duende to drop the user and group of the script
to daemon, change the working directory and chroot and prepares to restart the main child
when it exits with code 42. All of the steps required to daemonize a process are handled betweem the
start-stop-daemon pocess, the init script or the Duende process apart from:
setpgrpThe example script cheats slightly because it does these things after all the Perl modules have been loaded. In some real world examples it might be necessary to have a chroot environment with something actually in it.