Wednesday, October 15, 2014

Linux server thrashing using vmstat

You can use the vmstat command to detect thrashing of memory and hard disk as follows:

vmstat 2
where 2 represents the number of seconds to repeat.

You may see output similar to this

procs -----------memory---------- ---swap-- -----io---- --system-- -----cpu-----
 r  b   swpd   free          buff      cache      si   so    bi    bo   in   cs us sy id wa st
 1  0   1600 2244636 193816 1154164    0    0     1     9    0    0  1  0 98  0  0
 1  0   1600 2244496 193816 1154184    0    0     0    46 1768 1432 26  1 73  0  0
 1  0   1600 2244496 193816 1154184    0    0     0     0 1756 1383 25  1 74  0  0
 1  0   1600 2244496 193816 1154184    0    0     0     0 1732 1318 26  0 74  0  0



The parameters of interest are si and so (swap in, swap out).
In this case a value of 0, means there is no thrashing

References:

http://www.linuxjournal.com/article/8178

Monday, May 19, 2014

Automated database backups

Automated Database Backups

Postgres

Assuming we are using Linux, create a file called .pgpass in the user’s home directory with the following details:
hostname:port:database:username:password

Then from the command-line run the following command:
pg_dump –U user dbname | gzip > ~/backup/db/$(date +%Y-%m-%d).psql.gz

Mysql

Assuming we are using Linux, create a file called ~/.my.cnf in the user’s home directory with the following details:
[mysqldump]
user=mysqluser
password=secret

Then from the command-line
mysqldump –u user dbname | gzip > ~/backup/db/$(date +%Y-%m-%d).psql.gz

Crontab

If the command is successful, then create and add this command to a script, for example runBackup.sh
Then schedule the job to run by editing your crontab:
crontab -e
For example, to run once a week on Saturday at 2AM:
0 2 * * 6 ~/runBackup.sh

 

References




Wednesday, May 7, 2014

Automated tomcat start up on server reboot



Automated start up on server reboot


Create a new tomcat user using the following command:
adduser tomcat

Create the following file /etc/init.d/tomcat:
#!/bin/bash
#
# tomcat       
#
# chkconfig:
# description: Start up the Tomcat servlet engine.

# Source function library.
. /etc/init.d/functions


RETVAL=$?
CATALINA_HOME="/usr/local/apache-tomcat-7.0.52"

case "$1" in
 start)
        if [ -f $CATALINA_HOME/bin/startup.sh ];
          then
            echo $"Starting Tomcat"
            /bin/su tomcat $CATALINA_HOME/bin/startup.sh
        fi
        ;;
 stop)
        if [ -f $CATALINA_HOME/bin/shutdown.sh ];
          then
            echo $"Stopping Tomcat"
            /bin/su tomcat $CATALINA_HOME/bin/shutdown.sh
        fi
        ;;
 *)
        echo $"Usage: $0 {start|stop}"
        exit 1
        ;;
esac

exit $RETVAL

Edit the file and change CATALINE_HOME to the location of where tomcat is found.

Grant execution write of the new file using the following command:
chmod 755 /etc/init.d/tomcat

Reassign the owner of the tomcat folder and all subfolders to the tomcat user:
chown tomcat:tomcat –R /usr/local/apache-tomcat-7.0.52


To start up on server reboot:
ln –s ../init.d/tomcat S71tomcat
 

Sunday, January 5, 2014

Spring STS doesn't start up after many months of use

The problem:


After many months of using Spring STS IDE, I tried to reload the program but it always fails without any notifications or error messages. Even the "-clean" option failed to work.

When I insepected the log file found in the workspace/.metadata/log I noticed the following error:



 !ENTRY org.eclipse.core.jobs 2 2 2014-01-06 07:44:26.601  
 !MESSAGE Job found still running after platform shutdown. Jobs should be canceled by the plugin that scheduled them during shutdown: org.eclipse.core.internal.refresh.RefreshJob  
 !ENTRY org.eclipse.core.jobs 2 2 2014-01-06 07:44:26.601  
 !MESSAGE Job found still running after platform shutdown. Jobs should be canceled by the plugin that scheduled them during shutdown: org.eclipse.core.internal.refresh.RefreshJob  
 !ENTRY org.eclipse.ui 4 0 2014-01-06 07:44:26.602  
 !MESSAGE Error occurred during status handling  
 !STACK 0  
 java.lang.NullPointerException  
      at org.eclipse.ui.internal.statushandlers.StatusHandlerRegistry.<init>(StatusHandlerRegistry.java:61)  
      at org.eclipse.ui.internal.statushandlers.StatusHandlerRegistry.getDefault(StatusHandlerRegistry.java:91)  
      at org.eclipse.ui.statushandlers.StatusManager.getStatusHandler(StatusManager.java:135)  
      at org.eclipse.ui.statushandlers.StatusManager.handle(StatusManager.java:189)  
      at org.eclipse.ui.statushandlers.StatusManager.handle(StatusManager.java:231)  
      at org.eclipse.ui.statushandlers.StatusManager$StatusManagerLogListener.logging(StatusManager.java:305)  
      at org.eclipse.core.internal.runtime.RuntimeLog.logToListeners(RuntimeLog.java:160)  
      at org.eclipse.core.internal.runtime.PlatformLogWriter.logged(PlatformLogWriter.java:100)  
      at org.eclipse.equinox.log.internal.ExtendedLogReaderServiceFactory.safeLogged(ExtendedLogReaderServiceFactory.java:86)  
      at org.eclipse.equinox.log.internal.ExtendedLogReaderServiceFactory.logPrivileged(ExtendedLogReaderServiceFactory.java:205)  
      at org.eclipse.equinox.log.internal.ExtendedLogReaderServiceFactory.log(ExtendedLogReaderServiceFactory.java:178)  
      at org.eclipse.equinox.log.internal.ExtendedLogServiceFactory.log(ExtendedLogServiceFactory.java:65)  
      at org.eclipse.equinox.log.internal.ExtendedLogServiceImpl.log(ExtendedLogServiceImpl.java:87)  
      at org.eclipse.equinox.log.internal.LoggerImpl.log(LoggerImpl.java:54)  
      at org.eclipse.core.internal.runtime.PlatformLogWriter.logging(PlatformLogWriter.java:43)  
      at org.eclipse.core.internal.runtime.RuntimeLog.log(RuntimeLog.java:96)  
      at org.eclipse.core.internal.jobs.JobManager.doShutdown(JobManager.java:606)  
      at org.eclipse.core.internal.jobs.JobManager.shutdown(JobManager.java:252)  
      at org.eclipse.core.internal.jobs.JobActivator.stop(JobActivator.java:55)  
      at org.eclipse.osgi.framework.internal.core.BundleContextImpl$2.run(BundleContextImpl.java:771)  
      at java.security.AccessController.doPrivileged(Native Method)  
      at org.eclipse.osgi.framework.internal.core.BundleContextImpl.stop(BundleContextImpl.java:764)  
      at org.eclipse.osgi.framework.internal.core.BundleHost.stopWorker(BundleHost.java:510)  
      at org.eclipse.osgi.framework.internal.core.AbstractBundle.suspend(AbstractBundle.java:566)  
      at org.eclipse.osgi.framework.internal.core.Framework.suspendBundle(Framework.java:1206)  
      at org.eclipse.osgi.framework.internal.core.StartLevelManager.decFWSL(StartLevelManager.java:592)  
      at org.eclipse.osgi.framework.internal.core.StartLevelManager.doSetStartLevel(StartLevelManager.java:257)  
      at org.eclipse.osgi.framework.internal.core.StartLevelManager.shutdown(StartLevelManager.java:215)  
      at org.eclipse.osgi.framework.internal.core.InternalSystemBundle.suspend(InternalSystemBundle.java:284)  
      at org.eclipse.osgi.framework.internal.core.Framework.shutdown(Framework.java:692)  
      at org.eclipse.osgi.framework.internal.core.Framework.close(Framework.java:600)  
      at org.eclipse.core.runtime.adaptor.EclipseStarter.shutdown(EclipseStarter.java:400)  
      at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:200)  
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)  
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)  
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)  
      at java.lang.reflect.Method.invoke(Method.java:601)  
      at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:636)  
      at org.eclipse.equinox.launcher.Main.basicRun(Main.java:591)  
      at org.eclipse.equinox.launcher.Main.run(Main.java:1450)  
      at org.eclipse.equinox.launcher.Main.main(Main.java:1426)  

Solution

It appears that it may have gotten itself into a bad state. To reset this persisted state we can use the "-cleanPersistedState" option, when launching the application.


Reference: http://stackoverflow.com/questions/15372023/eclipse-will-not-start-and-i-havent-changed-anything