Category Archives: Linux

OpenOffice service init.d script for CentOS

This script will start soffice headless listening on port 8100. You can use it eg. with JODConverter.

#!/bin/bash
# openoffice.org headless server script
#
# chkconfig: 2345 80 30
# description: headless openoffice server script
# processname: openoffice
#
OOo_HOME=/usr/bin
SOFFICE_PATH=$OOo_HOME/soffice
PIDFILE=/var/run/openoffice-server.pid

set -e

case "$1" in
start)
if [ -f $PIDFILE ]; then
echo "OpenOffice headless server has already started."
sleep 5
exit
fi
echo "Starting OpenOffice headless server"
$SOFFICE_PATH -nologo -nodefault -norestore -nocrashreport -nolockcheck -headless -nofirststartwizard -accept="socket,host=localhost,port=8100;urp" & > /dev/null 2>&1
touch $PIDFILE
;;
stop)
if [ -f $PIDFILE ]; then
echo "Stopping OpenOffice headless server."
killall -9 soffice && killall -9 soffice.bin
rm -f $PIDFILE
exit
fi
echo "Openoffice headless server is not running."
exit
;;
*)
echo "Usage: $0 {start|stop}"
exit 1
esac
exit 0

How to rescue damaged harddisk

For the past three days I was trying to rescue a damaged disk of my colleague. I already knew about a great disk cloning tool called ddrescue in Linux. So this was the first step I did. After 20 hours of work the clone has been created, but with some errors during read. I was hoping that I will be able to boot from it after I put it back to the PC, but in this case there was some problem with the partition table, so Windows has not been even be able to recognize it as NTFS, even though Linux did!
I didn’t want to reinstall the system after so much hours spend on this, so I was looking for some other tools which could help me save the disk. There was a lot of suggestions on using some paid software, but I don’t have good experience with them.
Finally I found another great open source software called TestDisk. It is a command line tool, but I don’t care much if it helps 🙂 Using this software I was able to recreate the partition table, after it found the lost NTFS partition and as soon as I restarted PC, Windows finally fixed the NTFS using chkdsk.

Running wuala in background with no gui

I have finally found a solution for my problem described in older post. Today I have found out that you can run Wuala without GUI. To do this you have to call wuala with the following parameter.

wuala -nogui

But only this is not enough. You have to also login to your account, because Wuala won’t auto login in this case. I have created a bash script which runs Wuala and as soon as it is initialized it logs you in.

#!/bin/sh

# Run Wuala with no GUI
wuala -nogui &

# Give Wuala some time to initialize
sleep 30

# Login
wuala login USERNAME PASSWORD

Change USERNAME and PASSWORD with your credentials and save this piece of code to /usr/bin/start-wuala.sh. Make it executable by calling sudo a+x /usr/bin/start-wuala.sh. After that you can put it to Startup Applications. But before you do that, you should setup your synchronization, because when Wuala starts in background you are not able to start another instance. To shutdown existing instance go to terminal and execute wuala shutdown.
You can also check status of the background process on the following address: http://127.0.0.1:33333/.

Running UltraVNC repeater under Linux server

I am playing with remote support tools. There are a lot of good payed tools like TeamViewer, GoToMeeting and others but they are expensive. I found that UltraVNC has some tools like Single Click which can make it easy to provide remote support to your customers. Finally I ended by ChunkVNC which is basically UltraVNC but looking much more better.
There is a lot of tutorials on the Internet but they describe direct connection support. Which means at least one of the PC’s has to be accessible from the outside world. But I wanted to setup some server which I would connect to instead of connecting directly to customer’s PC. This server is called Repeater. UltraVNC has a repeater targeting Windows platform. But I have a Linux server and I wanted it to be running there. Fortunately a Linux port of the UltraVNC Repeater is also available. I have created a mirror of the latest version in case the original page won’t work.
The installation itself is not a big problem even though you have to compile the sources.

  1. Connect to the server using SSH
  2. Go to temp: cd /tmp/
  3. Download the sources: wget http://downloads.stefko.cz/uvncrepeater.tar.gz
  4. Extract them: tar zxvf  uvncrepeater.tar.gz
  5. Go to the sources directory: cd uvncrepeater/
  6. Compile the sources: make
  7. Copy repeater to sbin: cp repeater /usr/sbin/repeater
  8. Run it: /usr/sbin/repeater

If you want to make it running as a service you can use the following piece of code:

#! /bin/sh
# vnc: start/stop/restart the VNC repeater server
# chkconfig: 3 20 80
# description: VNC repeater server

vnc_start() {
if [ ! -f /etc/uvncrepeater.ini ]; then
echo "File /etc/uvncrepeater.ini does not exist. Aborting."
exit
fi
/usr/sbin/repeater 2>>/var/log/vnc.log &
pgrep repeater >/var/run/vnc.pid
}

vnc_stop() {
killall repeater
rm /var/run/vnc.pid
}

vnc_restart() {
if [ -r /var/run/vnc.pid ]; then
kill `cat /var/run/vnc.pid`
else
echo "Killing repeater in the absence of /var/run/vnc.pid"
killall repeater
fi
sleep 1
vnc_start
}

case "$1" in
'start')
vnc_start
;;
'stop')
vnc_stop
;;
'restart')
vnc_restart
;;
*)
echo "usage $0 start|stop|restart"
esac

Take the code and save it into /etc/init.d/vnc file on the server. Then run the following commands to install it as a service:

  1. chmod +x /etc/init.d/vnc
  2. chkconfig –add vnc
  3. chkconfig –level 3 vnc on

Connection problem when stunnel is run on boot time in Ubuntu

If you are using stunnel in client mode you may experience connection problems when connecting to your stunnel services.
To avoid these problems make the following changes in your stunnel.conf file:

  1. Comment out the following line: chroot = /var/lib/stunnel4/
  2. Update pid file location with this: pid = /var/lib/stunnel4/stunnel4.pid
  3. Add delay = yes into the service configuration

In this case DNS lookup will be done when the service is needed for the first time.

Enabling WMA support under Wine in Linux

I am using foobar2000 as my audio player in Linux, because I am very familiar with it and I was unable to find sufficient alternative. In my music library I also have albums with songs in WMA (Windows Media Audio) format. This format is not supported under Wine by default. But you can fix this very easily by installing Windows Media Player 10.
Windows Media Player itself does not start under Wine, but the codec is installed successfully.

Making FastMail default mail reader in GNOME

In Ubuntu, I am using mail-notification to get notified about new e-mail in my FastMail account. From time to time I also click on some mailto link. In both of these cases I would like a FastMail page to be opened in Opera. But to make it a lil bit smart, I would like to open inbox when double-clicking on new e-mail notification, but in case I click mailto link I would like to be redirected to compose new FastMail e-mail url.
I have created a bash script, which does this job quite well. All you need to do is to copy the following text into clipboard, past it into some text editor and save it into /usr/bin/fastmail-mailto.sh.

#!/bin/sh
BROWSER="opera"

# Mailto URI may look like this
#mailto:[email protected]?subject=hi&body=message

# Most of the parameters are called the same, we just need to parse e-mail
uri=`echo "$1" | sed -e 's/^mailto:/*([^&?]+)[?&]?(.*)$/1&2/'`

if [ "$uri" ];
then exec $BROWSER "http://www.fastmail.fm/action/compose/?to=$uri"
fi

exec $BROWSER "http://www.fastmail.fm/"

After you are finished, you need to make the file executable by calling the following command: sudo chmod a+x /usr/bin/fastmail-mailto.sh.
Finally just go to Preferences > Preferred Applications and change Mail Reader to Custom with the following text: /usr/bin/fastmail-mailto.sh.