Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2009-05

Daemon question

5 messages · 3 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Koenraad Lelong

Hi,
I wrote a daemon monitoring my solar powerstation. It works fine but I want to extend it.
At the moment I log everything to file, and I put some data into rrdtool. I would like to be able to ask the daemon some information, but I don't know how to do this.
I made some signals : sigterm to terminate gracefully, sighup to restart, sigusr0 to get the uptime and sigusr1 to get some device-info. Except, sigusr0 and sigusr1 use writeln's to output the data which I never see when I ask for them (kill -10 <processid>). Where do these writeln's write to ? Sigterm and sighup do work fine, so I think my handler is OK.
How can I get that info ? It should be software-independent, because I would like to use php to get that information.
I thought of writing the info to a file, but that info is updated every 15 seconds. I think it's not good to write a new file every time. Now I'm writing this, I could write to a file after receiving a signal, and then reading this with php.
Thinking about it, does php support sending signals ? Back to the books.

Before you ask, I'm running Linux.

Thanks for any pointers,
Koenraad Lelong.

Reply by email

Joost van der Sluis
to Koenraad Lelong

Op woensdag 13-05-2009 om 22:28 uur [tijdzone +0200], schreef Koenraad Lelong:

Show quoted text 11 lines
Hi, I wrote a daemon monitoring my solar powerstation. It works fine but I want to extend it. At the moment I log everything to file, and I put some data into rrdtool. I would like to be able to ask the daemon some information, but I don't know how to do this. I made some signals : sigterm to terminate gracefully, sighup to restart, sigusr0 to get the uptime and sigusr1 to get some device-info. Except, sigusr0 and sigusr1 use writeln's to output the data which I never see when I ask for them (kill -10 <processid>). Where do these writeln's write to ?

If you have 'daemonized' your program properly, these writelines disappear in an empty void... (As they should)

Or else (if it's not daemonized properly) they would go to the terminal which was used to start the daemon. And that's not what you want.

The 'daemonize-process' closes the stdout-handle, or re-assigns it to /dev/null. You could assign it to something else, like a file.

How can I get that info ? It should be software-independent, because I would like to use php to get that information. I thought of writing the info to a file, but that info is updated every 15 seconds. I think it's not good to write a new file every time.

There's no difference between writing to file and writing to console?

Now I'm writing this, I could write to a file after receiving a signal, and then reading this with php.

You could use IPC. (TSimpleIPCServer)

Thinking about it, does php support sending signals ? Back to the books.

And does it support IPC? No idea, but php can call external programs.

Joost.

Reply by email

Henry Vermaak
to Koenraad Lelong: I wrote a daemon monitoring my solar powerstation. It works fine but I want to extend it.…

2009/5/13 Koenraad Lelong :

Show quoted text 19 lines
Hi, I wrote a daemon monitoring my solar powerstation. It works fine but I want to extend it. At the moment I log everything to file, and I put some data into rrdtool. I would like to be able to ask the daemon some information, but I don't know how to do this. I made some signals : sigterm to terminate gracefully, sighup to restart, sigusr0 to get the uptime and sigusr1 to get some device-info. Except, sigusr0 and sigusr1 use writeln's to output the data which I never see when I ask for them (kill -10 <processid>). Where do these writeln's write to ? Sigterm and sighup do work fine, so I think my handler is OK. How can I get that info ? It should be software-independent, because I would like to use php to get that information. I thought of writing the info to a file, but that info is updated every 15 seconds. I think it's not good to write a new file every time. Now I'm writing this, I could write to a file after receiving a signal, and then reading this with php. Thinking about it, does php support sending signals ? Back to the books.

i think the most elegant and scalable solution is to write a client/controller program that communicates with the server. this client can control the server, set options, get information/status via sockets, or some form of ipc. php can then call this client with the required options and use the output. a lot of unix daemons use this approach, see udevadm (for udev) and smbcontrol (for samba), for example.

if this is too much trouble, your daemon can just append data to log files every x seconds and php can read these files. you will have to implement some log rotation scheme, though, or the log files will take over your system.

henry

Reply by email

Koenraad Lelong
to Henry Vermaak
Henry Vermaak wrote
2009/5/13 Koenraad Lelong : > Hi, > I wrote a daemon monitoring my solar powerstation. It works fine but I > want to extend it.

...

Show quoted text 19 lines
> Now I'm writing this, I could write to a file after receiving a signal, > and then reading this with php. > Thinking about it, does php support sending signals ? Back to the books. i think the most elegant and scalable solution is to write a client/controller program that communicates with the server. this client can control the server, set options, get information/status via sockets, or some form of ipc. php can then call this client with the required options and use the output. a lot of unix daemons use this approach, see udevadm (for udev) and smbcontrol (for samba), for example. if this is too much trouble, your daemon can just append data to log files every x seconds and php can read these files. you will have to implement some log rotation scheme, though, or the log files will take over your system. henry

My "big" logs are 1.6M per day, but they are about 5000 lines at the end of the day. Wouldn't it be a waste to read the last line of such a big file ?
My last remark was about sending a signal via php (it does support sending signals) and then writing the desired value to a file which would be a single line, and then php reads this file. There could be problems with concurrency, although the website will only be available at home, so the number of possible users will be limited. I will read about IPC and sockets. Do you have any good references at hand about these ? I think googling will be difficult, but I will.

Thanks guys,
Koenraad.

Reply by email

Henry Vermaak
to Koenraad Lelong

2009/5/14 Koenraad Lelong :

Show quoted text 11 lines
My "big" logs are 1.6M per day, but they are about 5000 lines at the end of the day. Wouldn't it be a waste to read the last line of such a big file ? My last remark was about sending a signal via php (it does support sending signals) and then writing the desired value to a file which would be a single line, and then php reads this file. There could be problems with concurrency, although the website will only be available at home, so the number of possible users will be limited. I will read about IPC and sockets. Do you have any good references at hand about these ? I think googling will be difficult, but I will.

as Joost mentioned, TSimpleIPCServer is available for fpc (i haven't used it, though). otherwise you can look at the bind(2) manpage for an example of sockets in linux.

henry

Reply by email