2

I'm developing a small piece of software, that is able to control (start, stop, restart and so on - with gnu screen) every possible gameserver (which have a command line) and includes a tiny standalone webserver with a complete webinterface (you can access the gnu screen from there, like if you're attached to it) on linux.

Almost everything is working and needs some code cleanup now.

It's written in python, the standalone webserver uses cherrypy as a framework.

The problem is, that the gnu screen output on the webinterface is done via a logfile, which can cause high I/O when enabled (ok, it depends on what is running).

Is there a way to pipe the output directly to the standalone webserver (it has to be fast)? Maybe something with sockets, but i dont know how to handle them yet.

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
carrot
  • 51
  • 1
  • 6
  • 1
    When you say "gnu screen", do you mean http://www.gnu.org/software/screen/? – Aaron Digulla Mar 27 '13 at 08:47
  • yes, thats exactly right. – carrot Mar 27 '13 at 09:30
  • How do you create the "log files" when using `screen`? – Aaron Digulla Mar 27 '13 at 10:00
  • Are you saying you're just sending stdout to a log file and to the screen? In which case you could just pipe it to the stdin of the webserver instead of sending it to the logfile? (look up tee if you still want ordinary stdout) – james.haggerty Mar 27 '13 at 10:42
  • Currently its done via "screen -dmS name script -f -c 'command' /some_path/logs/screen.log" (-> script). It should be piped directly to the webserver, because the log-file _can_ cause a high hdd I/O in bad cases. Its not that urgent, but would be a nice i think. – carrot Mar 27 '13 at 11:43

3 Answers3

2

If you create a FIFO with mkfifo mypipe.log and write your log to it you should be able to open this from python and read in. Python and FIFOs might be helpful. If you want a hard-copy of the log as well you can pipe the output through tee.

Community
  • 1
  • 1
Samizdis
  • 1,591
  • 1
  • 17
  • 33
1

Writing to a pipe would work but it's dangerous since your command (the one writing the pipe) will block when you're not fast enough reading the data from the pipe.

A better solution would be create a local "log server" which publishes stdin on a socket. Now you can pipe the output of your command to the log server which reads from stdin and sends copy of the input to anyone connected to it's socket.

When no one is connected, then the output is just ignored.

Writing such a "log server" is trivial (about 1h in Python, I'd guess).

An additional advantage would be that you could keep part of the log file in memory (say the last 100 lines). When your command crashes, then you could still get the last output from your log server.

For this to work, you must not terminate the log server when stdin returns EOF. The drawback is that you need to clean up stale log servers yourself. When you use sockets, you can send it a "kill" command from your web app.

Aaron Digulla
  • 321,842
  • 108
  • 597
  • 820
0

You can use syslog or even better you can configure it to send all logs to a database!

h4unt3r
  • 846
  • 10
  • 14