Hiya Alvis
I do quite a bit of daemon/service kina work in Linux/Lazarus so I'll
try to help.
In this week I did a small prototype of an application that I'm doing
for linux with Lazarus.
It open socket for remote visual control, mysql connections, and other
nice things.


This is a cool idea, but please keep the following in mind:
When you create your project. You MUST choose "commandline
application" - NOT graphical application, else your daemon will refuse
to start (since gtk linked apps need to be stared INSIDE an active
X-server, which is not existing in the init-phases of a Linux system).


So my questions are...:
1) Does the kill on a linux service launch some "onkill" functions, or
that's a kill-without-doing-anithing-else ?
I'm thinking about using a soft close through the tcp connection with a
command in the init.d/my_service stop like that:
telnect localhost myport /my_service_suicide

Are'nt there any ways to put some code into a "onkill" event of a linux
process?
This is not actually true :)
The init scripts generally only make stop, start and restart available
- but there are far
more options in the Linux world. The kill command technically doesn't
"end" a process, it sends it a signal which the process should respond
to. Signal 15 is the one sent if none is specified and it means
"soft-kill" - the application is TOLD to die, and left to do so by
itself. Signal 9 is hard kill - which yanks the proggie right out of
the system and kills it dead right away. This is typically used when a
process crashed and it cannot do a proper soft-kill anymore.
Other signals that a daemon should handle include signals for "reload
all configs" etc.  as well (many init scripts have a 'reload' option
which triggers this, it is NOT meant to restart the daemon, but to
force it to reread it's config files - for daemons supporting this,
you can use it to load in updated config files without taking the
service down first).
The linux daemon demo shows how to handle all the important services.

2) How do I configure threads in linux? I mean... I'd like to change
their name and aspect like other services do, and keep under control
their behaviour (state, resume call times, speed, cpu usage, ecc).
Threads and daemons aren't directly related. You create a daemon by
FORK'ing the application. See yet again the daemon example which shows
how this works very well.
I personally suggest ANY modern daemon should AFTER the fork have code
to get it's NEW pid and save this to /var/run/daemonname.pid so that
init scripts can CLEANLY stop or restart it - this is the only thing
NOT in the demo though (catch it sorta requires that your daemon have
root privs but they usually do anyway).
Threads CAN be used with daemons, usually AFTER the fork to allow the
daemon to handle multiple tasks at once (e.g. multiple simultaneous
clients will usually require threading the app).
The best advice I can give HERE is to have a look at the TThread
tutorial in the wiki - I learned threading from there -this is
entirely platform neutral.


3) Does killing the main_unit (father) kills the processes? I tryed an
example in wich I launch 2 thread before the main closes with the .end
and they seem to "survive", but having the father alive can be useful to
control purposes...
Like I said above - use a fork to create the daemon, not a thread, you
can thread INSIDE but do it carefully.

4) What does the fpfork command used in the "doing a service under
linux" example on your wiki?
I'm a bit confused about it's behaviour, cause doing an if block with
(pid=0) on it makes the program do both the if and the else in the same
time...
Nope it does not. :)
A fork means the program creates a copy of itself into ram with all
the same variable data etc. - but as a sepperate process. In the
master, fpFork returns the pid of the fork, in the newly forked slave,
it returns 0 - this means lets you know which process to end and which
to keep running.
Now you see why I say you thread AFTER forking ?

5) How can I access classes istances (or threads) created by their
father from the different childs? I got a lot of recursive declaration
errors trying to do that but I failed to access them with
"self.father.class" like calls.
This one I don't know, sorry.


Ciao
A.J.
--
A.J. Venter
CEO - OutKast Solutions C.C.
http://www.outkastsolutions.co.za
Cell: +27 83 455 9978
Fax: +27 21 413 2800
Office: +27 21 591 6766

_________________________________________________________________
    To unsubscribe: mail [EMAIL PROTECTED] with
               "unsubscribe" as the Subject
  archives at http://www.lazarus.freepascal.org/mailarchives

Reply via email to