We were looking for a nice background image for our new blog. So we stumbled over several candidates until Fabian Trampusch came up with the idea of showing a live htop summary.
Everyone was happy with the idea, so we began to take screenshots and tried to automate the process. I mean “what could be so difficult at taking automated screenshots?”
…until we realized, we are in an ssh session on the remote server. A screenshot without the X window System is not as trivial as it sounds.
The Imagemagick attempt
After some bit of googling we found our first attempt:
Use ImageMagick to print the output of a process to an image.
ls -lah | convert -resize 500 label:@- image.jpg
The output was not very appealing so we went on to a more sophisticated solution with postscript:
- Using a2ps to convert… anything (?!) to postscript,
- … gs to convert it into a png-file
- … and trim it with ImageMagick.
ls -la | a2ps -=book -B -q --medium=A4dj --borders=no -o out1.ps gs -sDEVICE=png256 -dTextAlphaBits=4 -q -r300x300 -sOutputFile=out2.png < out1.ps convert -trim out2.png result.png
The result is better than the first solution, but also unsatisfying. Also a problem is that a2ps needs piped data from your process. Htop is a process which doesn’t terminate by itself and produces no direct pipable output.
The Snapscreenshot attempt
After some more research we found out about the tool snapscreenshot, which is able to capture the output of a TTY.
After download, compilation and installation, we were able to use it to capture the output of /dev/tty1… which is somehow unspectacular.
The next step is to start htop on another TTY:
read _ _ sid < &1 strace -esetsid setsid sh -c "exec $PROGRAM /dev/tty2 >&0 2>&1 ")
Linux… are you drunk?
Due to the fact that we need the process id of the new htop instance, this command is somehow a bit complex. For writing a proper daemon, you have to store the PID to terminate the process later. So This commad starts htop on tty2, and stores the pid into $sid.
The difficult part of the project is done. We’ve got a solution to start htop on tty2, can capture it and it is also daemonizable (what a word).
The next steps are trivial. Write an init script, modify the webpage to load a certain Image as background and go for it.
Again thanks to Fabi for building a quick javasript function to periodically reload the beackground.
Now to the initial question…
Is it intelligent to show everybody what your server does?
… But we thought everyone with a bit of knowledge about webservers and WordPress knows the disclosed information anyways. So the only new parts are that we have one gig ram and two cores.
Original URL: http://feedproxy.google.com/~r/feedsapi/BwPx/~3/BAznDnW8eaY/41