I have this script: #!/bin/bash
if [ -e /var/run/pgsql.pipe ]; then while [ -e /var/run/pgsql.pipe ] do psql -q -h padsysdb -U sysloguser syslog </var/run/pgsql.pipe done fi
...running on a Ubuntu Linux server. It's clearly very simple; it just keeps checking the named pipe /var/run/pgsql.pipe and sending the contents to the psql command, which interprets the input as a SQL command and executes it accordingly.
My question is, given that I want this loop to execute (a) from server startup (b) indefinitely and without interruption, how do I reasonably ensure (a) and (b)?
More specifically, where do I stick this (or an equivalent) in the startup scripts on Ubuntu, and is there a good automated way to make sure it keeps going? I really don't want to lose any of my database input. It's a fairly critical system, and I'd like to make this pretty robust.
Kevin
Call the script from /etc/inittab, use the respawn keyword. Your X display manager is probably set up that way
Sean
On 1/30/07, Kevin McGregor kmcgregor@shaw.ca wrote:
I have this script: #!/bin/bash
if [ -e /var/run/pgsql.pipe ]; then while [ -e /var/run/pgsql.pipe ] do psql -q -h padsysdb -U sysloguser syslog </var/run/pgsql.pipe done fi
...running on a Ubuntu Linux server. It's clearly very simple; it just keeps checking the named pipe /var/run/pgsql.pipe and sending the contents to the psql command, which interprets the input as a SQL command and executes it accordingly.
My question is, given that I want this loop to execute (a) from server startup (b) indefinitely and without interruption, how do I reasonably ensure (a) and (b)?
More specifically, where do I stick this (or an equivalent) in the startup scripts on Ubuntu, and is there a good automated way to make sure it keeps going? I really don't want to lose any of my database input. It's a fairly critical system, and I'd like to make this pretty robust.
Kevin _______________________________________________ Roundtable mailing list Roundtable@muug.mb.ca http://www.muug.mb.ca/mailman/listinfo/roundtable
On 30 Jan, Kevin McGregor wrote:
I have this script: #!/bin/bash
if [ -e /var/run/pgsql.pipe ]; then while [ -e /var/run/pgsql.pipe ] do psql -q -h padsysdb -U sysloguser syslog </var/run/pgsql.pipe done fi
The if and while are redundant, no? Just use the while.
And does anything ever delete the pgsql.pipe file? If not, why the while? If you do Sean's inittab respawn you don't need the while.
If you're not expecting it to die, then you could try rc.local (run with &), with or without the while.
Oh ya, one other glitch: if the pipe doesn't exist at boot, your script will just end... or respawn too rapidly! Don't you want something more like:
while [ true ] do if [ -e /var/run/pgsql.pipe ]; then psql -q -h padsysdb -U sysloguser syslog </var/run/pgsql.pipe fi sleep 30 done
Oh ya, there's also potential race conditions there, but if you add
/dev/null 2>&1 to the psql line it probably won't matter.
Kevin McGregor wrote:
I have this script: #!/bin/bash
if [ -e /var/run/pgsql.pipe ]; then while [ -e /var/run/pgsql.pipe ] do psql -q -h padsysdb -U sysloguser syslog </var/run/pgsql.pipe done fi
...running on a Ubuntu Linux server. It's clearly very simple; it just keeps checking the named pipe /var/run/pgsql.pipe and sending the contents to the psql command, which interprets the input as a SQL command and executes it accordingly.
My question is, given that I want this loop to execute (a) from server startup (b) indefinitely and without interruption, how do I reasonably ensure (a) and (b)?
More specifically, where do I stick this (or an equivalent) in the startup scripts on Ubuntu, and is there a good automated way to make sure it keeps going? I really don't want to lose any of my database input. It's a fairly critical system, and I'd like to make this pretty robust.
Regardless of distribution, you can always just call a command from /etc/rc.local (or something very close to that)...
However, to ensure it stays running you can take advantage of init(8)'s functionality and put a line in /etc/inittab(5):
* km:2345:respawn:/usr/local/bin/mypgsqlscript.sh arg1 arg2 argN * ...and of course, mypgsqlscript.sh can do anything a shell script can. Keep in mind that init exec(2)'s everything as root, so if you need to run as a different user you'll need two scripts, where the first script is a two-liner that looks like:
* #!/bin/bash exec /bin/su --login --command="/usr/local/bin/my_unprivliged_script.sh $@" some_unprivilged_username * (Psql doesn't usually care who it gets run as, the username is provided on the command-line... see the one-liner, following:)
This technique is (almost) distro-independent; the exception being anything that uses a BSD-style startup sequence where init(8) doesn't exist... all the major (and all the minor (and almost all of the niche)) Linux distributions use SysV-style init so this will be available to you.
The other option I would recommend is to look at the "daemontools" or "mon" packages. They should be available for Ubuntu...
The last resort would be to have a script that actually does all the housekeeping necessary to monitor a daemon-like process and ensure that it restarts if it dies... but why go to that effort when init(8) does it for you?
Bottom line: you can do this all in one line with inittab(5):
* km:2345:respawn:/usr/bin/psql --dbname syslog --file /var/run/pgsql.pipe --hostname padsysdb --output /var/log/pgsql_pipe.out --quiet --username sysloguser * since according to fifo(4) the reading process will block until a writer connects to the FIFO (aka Named Pipe). Testing reveals that when the writer close(2)s the FIFO, the reader gets an EOF. The psql utility's --file option implies that the program will terminate upon reaching EOF in that file. Then init(8) will restart psql (because of "respawn") whereupon it will sit and wait for the next (set of) command(s) to arrive.
The big thing to watch out for here is timing. Regardless of which way it's done, psql probably isn't written to process asynchronous input and so will probably sit and do nothing until EOF occurs. So if you have a process writing commands once in a while to the FIFO, you need to ensure the file descriptor gets closed periodically so that psql can actually parse the SQL and run it.
Also, why would the FIFO vanish? If there's a real danger of that happening, wrap the psql command in a shell script and put a mkfifo or mknod call first
* #!/bin/bash [[ -p /var/run/pgsql.pipe ]] || /bin/mknod /var/run/pgsql.pipe p exec **/usr/bin/psql --dbname syslog --file /var/run/pgsql.pipe --hostname padsysdb --output /var/log/pgsql_pipe.out --quiet --username sysloguser * and call that script from inittab instead of psql directly. You probably only need/want to account for the possibility of the pipe vanishing on on end or the other - but you could always create a cron job that runs that one-liner (/bin/bash -c "exec </dev/null 2>&1
/dev/null; [[ -p /var/run/pgsql.pipe]] || mkfifo /var/run/pgsql.pipe")
every 5 minutes. Or put that into inittab, too, if you only care about it at system startup:
* pp:2345:sysinit:/bin/mknod /var/run/pgsql.pipe p * N.B. "/bin/mknod X p" is exactly equivalent to "/bin/mkfifo X". Not sure why the coreutils team decided to duplicate that functionality... probably because HP/UX or something had a mkfifo command once upon a time. The joy of backward compatability...
-Adam Thompson athompso-muug@athompso.net
I need to take a list of medications, display it on a screen which will allow a user to edit the list, and print it in a number of different forms (list for the patient, a hospital progress note, prescription pads). The printed forms have lines, etc, and could have geometric figures such as a logo. The input will likely be in XML.
The display could be done with XHTML. The printed forms could be done using LaTeX commands, but I imagine it would be painful to program. I could learn postscript. I assume Acrobat's pdf is proprietary and cannot be used. I have heard of an XML based page layout language, and such a solution would lend itself to an XSLT transformation.
Does anyone have suggestions?
Dan Martin wrote:
I need to take a list of medications, display it on a screen which will allow a user to edit the list, and print it in a number of different forms (list for the patient, a hospital progress note, prescription pads). The printed forms have lines, etc, and could have geometric figures such as a logo. The input will likely be in XML.
The display could be done with XHTML. The printed forms could be done using LaTeX commands, but I imagine it would be painful to program. I could learn postscript. I assume Acrobat's pdf is proprietary and cannot be used. I have heard of an XML based page layout language, and such a solution would lend itself to an XSLT transformation.
Does anyone have suggestions?
Sort of a sideways step here... Assume a proportional font (fixed width for all characters). Would it be easier to create a graphic image?
Alternatively, under M$ I was doing something for Treasury Board using Crystal Reports (wouldn't touch it again given a choice). There should be something similar for *NIX. You can set page size, place logos, set up a query to print out results for an individual record or many records. Input could be done interactively or through a database. Output can be done to a GUI or hardcopy. It's a quick and simple solution.
Later Mike
On 1/30/07, Dan Martin ummar143@cc.umanitoba.ca wrote:
The display could be done with XHTML. The printed forms could be done using LaTeX commands, but I imagine it would be painful to program. I could learn postscript. I assume Acrobat's pdf is proprietary and cannot be used. I have heard of an XML based page layout language, and such a solution would lend itself to an XSLT transformation.
PDF is a published specification, there are several good perl and php libraries for working with it (I recall reading that Adobe is seeking standards approval for it, too). I'd recommend against PostScript, while it is fun (especially if you had an HP-48 calculator at some point) it's a pain if you want to get away from text and line art, not to mention worrying about what each individual printer (or driver) is going to do to your output.
Two other ideas would be GD and ImageMagick. Both generate an image and offer libraries for php and perl.
Sean
Thanks Sean!
Since pdf has an open specification, I will likely use it. I normally use C++, but I did recently use perl to parse printed patient info, because of its pattern capabilities. I used a perl library to create XML patient files, the idea being that I could access these from Java or C++, but if there is a handy perl library for pdf, I might just stick with perl.
-Dan
Sean Walberg wrote:
On 1/30/07, *Dan Martin* <ummar143@cc.umanitoba.ca mailto:ummar143@cc.umanitoba.ca> wrote:
The display could be done with XHTML. The printed forms could be done using LaTeX commands, but I imagine it would be painful to program. I could learn postscript. I assume Acrobat's pdf is proprietary and cannot be used. I have heard of an XML based page layout language, and such a solution would lend itself to an XSLT transformation.
PDF is a published specification, there are several good perl and php libraries for working with it (I recall reading that Adobe is seeking standards approval for it, too). I'd recommend against PostScript, while it is fun (especially if you had an HP-48 calculator at some point) it's a pain if you want to get away from text and line art, not to mention worrying about what each individual printer (or driver) is going to do to your output.
Two other ideas would be GD and ImageMagick. Both generate an image and offer libraries for php and perl.
Sean
-- Sean Walberg < sean@ertw.com mailto:sean@ertw.com> http://ertw.com/
Dan Martin ummar143@cc.umanitoba.ca writes:
I need to take a list of medications, display it on a screen which will allow a user to edit the list, and print it in a number of different forms (list for the patient, a hospital progress note, prescription pads). The printed forms have lines, etc, and could have geometric figures such as a logo. The input will likely be in XML.
The display could be done with XHTML. The printed forms could be done using LaTeX commands, but I imagine it would be painful to program. I could learn postscript. I assume Acrobat's pdf is proprietary and cannot be used. I have heard of an XML based page layout language, and such a solution would lend itself to an XSLT transformation.
Does anyone have suggestions?
Hi Dan,
It might be good to ask if this has to integrate with existing software at all, as there might be constraints there.
There are probably quite a few choices, but a couple of Common Lisp libraries would fit very nicely. The first is cl-typesetting, which as the name indicates, is for program-based typesetting of documents and reports. Its companion, cl-pdf, generates PDF output directly.
Links:
http://www.fractalconcept.com/asp/cl-typesetting http://www.fractalconcept.com/asp/cl-pdf http://www.fractalconcept.com/ex.pdf (Example PDF)
The same author has also created a very nice mod-lisp package to interface with Apache, should a web interface be desired.
Lisp might be odd to some, but if you're already thinking of XML, you're really most of the way there.
Cheers, Tim
Tim:
Thanks for the suggestion. I am now thinking of using pdf, since I am not breaking any laws by using it, so it sure would be nice to have a library of pdf functions.
It has been a while since I have used Lisp. I must admit, it would not have been the first thing I would have thought of.
-Dan
Tim Lavoie wrote:
Dan Martin ummar143@cc.umanitoba.ca writes:
I need to take a list of medications, display it on a screen which will allow a user to edit the list, and print it in a number of different forms (list for the patient, a hospital progress note, prescription pads). The printed forms have lines, etc, and could have geometric figures such as a logo. The input will likely be in XML.
The display could be done with XHTML. The printed forms could be done using LaTeX commands, but I imagine it would be painful to program. I could learn postscript. I assume Acrobat's pdf is proprietary and cannot be used. I have heard of an XML based page layout language, and such a solution would lend itself to an XSLT transformation.
Does anyone have suggestions?
Hi Dan,
It might be good to ask if this has to integrate with existing software at all, as there might be constraints there.
There are probably quite a few choices, but a couple of Common Lisp libraries would fit very nicely. The first is cl-typesetting, which as the name indicates, is for program-based typesetting of documents and reports. Its companion, cl-pdf, generates PDF output directly.
Links:
http://www.fractalconcept.com/asp/cl-typesetting http://www.fractalconcept.com/asp/cl-pdf http://www.fractalconcept.com/ex.pdf (Example PDF)
The same author has also created a very nice mod-lisp package to interface with Apache, should a web interface be desired.
Lisp might be odd to some, but if you're already thinking of XML, you're really most of the way there.
Cheers, Tim
Dan Martin ummar143@cc.umanitoba.ca writes:
Tim:
Thanks for the suggestion. I am now thinking of using pdf, since I am not breaking any laws by using it, so it sure would be nice to have a library of pdf functions.
I like PDF myself. Not too bad to generate with appropriate tools, and people are used to being able to view it on-line or print nicely.
It has been a while since I have used Lisp. I must admit, it would not have been the first thing I would have thought of.
True, it's not the most common choice, but it is powerful. With the appropriate dev environment, it is a joy to use. Emacs + SLIME and SBCL is my favorite setup.
Cheers, Tim