sixtydoses. where od is harmless.

January 22, 2010

Autostart tomcat upon reboot.

Filed under: Tech — Tags: , , , , — od @ 1:04 pm

So this morning they shutdown the server and called me up complaining that the website is down.

No, I didn’t ask how many times have they rebooted. Lol.

Anyway the website is down because I didn’t configure both apache and tomcat to run automatically upon reboot. Am so lazy today because it’s Friday, basically it’s a yippee day,  a day that is legal for you to come to work late, and go back early.

Googled for the auto script, but none satisfied my needs, so, here’s mine (adapted from a couple of scripts), because sharing is caring.

This script will always run tomcat as user ‘admin’ (EUID 500). If you run the script as a different user, it’ll prompt for admin’s password. Dump the script in /etc/init.d/ and run chkconfig to configure runlevel startup.

# tomcat     This is the init.d script used to start tomcat.
#                It calls $CATALINA_HOME/bin/ or
# chkconfig: – 91 15
# description: Apache Tomcat is an open source software implementation of the Java Servlet and JavaServer Pages technologies.
# processname: tomcat

export JAVA_HOME=/usr/java/jdk1.6.0_16
export CATALINA_HOME=/usr/local/apache-tomcat-5.5.28

tomcat_stop() {
if [[ $EUID -ne 500 ]]; then
su -c ‘$CATALINA_HOME/bin/’ admin
exit 1

tomcat_start() {
if [[ $EUID -ne 500 ]]; then
su -c ‘$CATALINA_HOME/bin/’ admin
exit 1

case $1 in
echo -n “Starting Tomcat server:”
echo “.”
echo -n “Stopping Tomcat server:”
echo “.”
echo “Usage: /etc/init.d/tomcat start|stop”

November 17, 2008

Back them up.

Filed under: Tech — Tags: , , , — od @ 9:07 pm

I learned my lesson the hard way. Last 2 years I bought a 120gb WD hard drive and used it for about 6 months before it suddenly died on me. 6 months, it was still covered by the warranty, but I chose not to return it for an exchange of a new one. I have tons of data inside but out of all data, I just need prolly around 30% of it. The rest, I can say goodbye with tears in my eyes. I still have the hard disk, kept nicely inside my wardrobe. When I have the chance, I’ll bring it back to live!

I love Maxtor hard drive. I still have one old Maxtor hdd that I’ve been using for almost 8 years running. In fact I used to have 2 of them. One has failed, but it is completely acceptable since it has served me for over 6 years.

Currently at work am preparing backup scripts for some servers. I find that backing up the entire directory of windows virtual machine is kinda annoying. Am thinking of what would be the best way to shutdown windows without using the force flag? Urgh. I wish I can just init 0.

At home I use a simple script that I wrote to backup directories. Basically what it does is it checks the content of both source and target directories, and any files/directories that are not available at the target location will be copied, creating a duplicate copy of the original directory. It’ll also generate a log (diff.log) to record what files that have been copied over. I use it to backup log files, nothing in giga size.


sSOURCE=`echo $SOURCE | awk -F/ ‘{print $NF}’`
sDEST=`echo $DEST | awk -F/ ‘{print $NF}’`
DATE=`date +”%v”`

echo “Directories comparison on $DATE” >> diff.log

diff -rq $SOURCE $DEST >> diff.log

s1=”Directories comparison on $DATE”
s2=`sed ‘$!d’ diff.log`

if [ “$s1” != “$s2” ]; then
sed -n ‘/'”$date”‘/,$p’ diff.log > copy.out

echo “Directory(s)/file(s) copied from $sSOURCE to $sDEST:” >> diff.log
f1=`sed -n ‘/^[Only in ]* /s///;s/:.///p’ copy.out`
f2=`sed -n ‘/Files/s/^.*Files.(.*) and.*$/1/p’ copy.out`


cp -vR $f1 $f2 $DEST >> diff.log

echo “Directory $sSOURCE is unchanged since yesterday.” >> diff.log

echo >> diff.log
echo “—————————————————————” >> diff.log
echo >> diff.log


The output of diff.log will be something like this:

Directories comparison on 15-Nov-2008
Only in /home/od/personal/script/cmp2dirs/diffmv/cmp2: white space 2
Directory(s)/file(s) copied from cmp2 to temp:
/home/od/personal/script/cmp2dirs/diffmv/cmp2/white space 2 -> ./temp/white space 2
/home/od/personal/script/cmp2dirs/diffmv/cmp2/white space 2/wsp -> ./temp/white space 2/wsp


Directories comparison on 16-Nov-2008
Directory cmp2 is unchanged since yesterday.


Directories comparison on 17-Nov-2008
Only in /home/od/personal/script/cmp2dirs/diffmv/cmp2: ghi
Directory(s)/file(s) copied from cmp2 to temp:
/home/od/personal/script/cmp2dirs/diffmv/cmp2/ghi -> ./temp/ghi


Create a free website or blog at