Delete content from a file in Linux without opening it

7/16/13
I had a problem once, with a huge log file in a Linux development environment. My Tomcat catalina.out was 9GB big. Yep, that's a lot.
Well, gedit and sublime crashed everytime I tried to open it, and I didn't want to delete the file, causing some strange permission no-write case.
So, nothing more simple:
just open the terminal, and to clean the file's content just write:
> /path/to/file

Done.
Great stuff!
Read more ...

Replace a String With Another String In All Files Using sed in Linux

7/4/13
Here is a quick and easy tweak to replace a string with another string.

Linux allows us to perform basic transformation on input stream (here is a great explanation).

To replace a string inside simple text files you should use the following syntax:

sed -i 's/old_string/new_string/g' */.*xml
where -i is the backup option if you provide the file extension.
The last part of the code line is the absolute path to your text files (in this case a dir containing xml files).
Read more ...

OTRS JavaScript Error: Cannot call method 'Init' of undefined

4/11/13
This error has bugged me for an entire day. The case scenario is:

  • CentOS 6.0 x64
  • OTRS 3.2
  • MySQL
After following the procedure for a correct installation in this link, I've tried the OTRS through localhost/otrs/installer.pl.
Everything went just fine, and I've managed some SysConfig for testing purposes.
After a reboot, this JavaScript error popped up on my OTRS Login page.

So, here are the steps that I managed to resolve this issue:

First of all, if the message in the error log of your Apache server has this  value: Can't remove shm for log, then you should disable SELinux:
  • Open your terminal
  • type: echo 0 >/selinux/enforce (you should be root to execute this comand)
  • to test if the SELinux is in permissive mode (0), jsut type cat /selinux/enforce in the terminal
Now, verify where are your otrs js-cache files stored in (usually in otrs/var/httpd/htdocs/js), then, before starting the otrs istance, delete all the js cached file (probably you'll need to be root to execute rm * command).

Then restart your Apache Server, MySQL (optional), and OTRS services.

The problem should be gone.

Read more ...

Lucene search query boolean values in Alfresco

3/29/13
This is quite a simple trick, that allows to search against boolean values of node properties in Alfresco.
Suppose you have a "custom:myProperty" deployed as a boolean value in the customModel.xml
You want to extract through your custom webscript documents that have myProperty true or false.
That's easy, the query should look similar to this:
@custom\:myProperty:"true"
@custom\:myProperty:"false"
But, if you want to extract all documents with myProperty (true, false, or empty/null).
Thats' why you should use this query:
@custom\:myProperty:*
It's important to notice that you shouldn't use quotation marks with the wildcard. With this query, you can easily extract every node in Alfresco with the custom:myProperty assigned, even if it's value isn't true or false.

 
 

Read more ...

Razer Blackwidow Ultimate backlights problem

3/25/13
I had this sort of problem. Once restarted the computer after a Razer Synapse 2.0 Update, the backlights of my Blackwidow Ultimate wouldn't turn on.
In Synapse software, I could switch between different light settings but nothing would change. Everything was off. Except NUM, CAPS and SCR LK led lights.
So, thanks to this guy, I managed to resolve the problem. You should just create a new profile in the Synapse (pay attention, a new game profile for your keyboard, not a new user account).
After that, everything turned back just fine.
Hope it helps, folks.
Read more ...

How to extend partitions on Linux VMware virtual machines through shell

3/21/13
So, if you need to extend disk storage on your virtual machines running on Linux, here are the steps to do it properly (you must be root to achieve this):

  • First of all, you need to extend the space through VMware settings
  • Open terminal and digit: fdisk -l
  • Then you should prompt type fdisk /dev/sda (change /dev/sda according to what the previous command returned to you)
  • type p so you can see the partition table
  • type n to add a new partition
  • type p to select the primary partition
  • If you want to use all the new space that you assigned through VMware, just use the default values for the first and the last cylinders
  • type w to confirm and save the changes, then restart the machine
  • After logging back in (always as root), you should print in terminal fdisk -l again, so you can see the partition you just created (probably listed as /dev/sda2 or 3 or 4 etc, depend on how many partitions do you have on you machine)
  • Now you should initialize the partition. In order to achieve this goal, you should first type df -h to find the name of the volume group to extend. Then type vgextend [volume group name] /dev/sdaN (where 'N' stands for the number of the new partition). The volume group name should be something like vg_root or similar
  • Now just type vgdisplay to see the free space available. You need to know the exact amount in order to use it to initialize a partition
  • type lvextend -L+100G /dev/vmvolgroup/vg_root (where 100G are the amount of GB of free space to use, in your case it should be probably a different value.  the /dev/vmvolgroup/vg_root should be probably different too, you can see the name of the volume group to extend in the previous steps)
  • Now, the final step is to expand the filesystem: resize2fs /dev/vmvolgroup/vg_root (always the same name as above. This operation could take some time to complete, it depends on the space and your harwdare, just wait 'til the terminal doesn't finish)
  • Now, if you want to check your extended partition, just use df -h command again, and you'll see the new allocated space

Read more ...

Connect to a Linux machine through another Linux Machine

3/19/13
Here is a simple and quick guide to connect to a Linux machine and start services like VNC server or FTP, through shell, without having physical access to the machine.

For ease of use I will call use these names:

  • serverA = this is your machine, where you have access through VNC or remote desktop
  • serverB = this is the machine you need to reach through terminal
  • userB = this is the user you use to connect to serverB

Open the terminal in your local machine e digit:
ssh userB@serverB
where serverB is the reachable IP of the machine (it depends on your network).

You will be prompted with a confirm dialog to connect, and after that, you will be connected in the terminal to the other machine.
Frome there you can start VNC serer through the command 
vncserver
or services like FTP and so on.
It's simple like that.
Hope it helps.
Read more ...

Lucene performance during index recovery in Alfresco

2/18/13
PROBLEM:

Lucene full index recovery takes N days to finish, with many GC and overheap memory problems.

SOLUTION:

After googling and posting questions on forums/stackoverflow and so on, I figured out how to boost Lucene performance in Alfresco when it comes to full index recovery.
Browsing the internet, and the Alfresco Documentation an enlightened link appears:
It states:
It is usualy a good practice that the highest-numbered INDEX entries (which contains the least documents, number 4 in the examples above) do not contain more than a few hundred documents. It it’s not the case, it could lead to massive amount of IO pressure on the index directories for merging operations.
So we started to mess around with some Lucene properties in alfresco.global.properties (copying from repository.properties), precisely with :
  • lucene.indexer.mergerTargetIndexCount
  • lucene.indexer.mergerMergeFactor
  • lucene.indexer.batchSize
  • index.tracking.disableInTransactionIndexing
  • lucene.maxAtomicTransformationTime
The last two actually fit in the "improve Lucene performance during bulk uploads in Alfresco" category, but it's useful not to forget that too.

lucene.indexer.mergerTargetIndexCount=10 - the default Alfresco value is 5, but you should change that value to 8-10. Higher values mean slower search (but if you need to improve reindex performance that is not a problem for now). After finishing you can always revert the change.
lucene.indexer.mergerMergeFactor=10 the default Alfresco value is 5, but you should set this value as high as possible. We tried to use Alfresco with values close to 1000, and everything worked fine. The higher the value of this property faster the response as in memory indexing increased, but the communication speed between disk and RAM is decreased.
lucene.indexer.batchSize = 1000 - This value prevents GC and memory leaks.
index.tracking.disableInTransactionIndexing= true - this value prevent Lucene from indexing content nodes during operations like modify/update/create/upload, but stores operations for later use, when the system is not under pressure.
PLEASE NOTE: USE THIS ONLY DURING MASS UPLOAD AND BEFORE FULL REBUILD, OTHERWISE YOU WILL NOT FIND ANY DOCUMENT ON THE REPOSITORY.
lucene.maxAtomicTransformationTime=0 - this value must be set to 0 to improve Lucene performance during bulk uploads.

The last change to do is properly configure is JAVA_OPTS in setenv.sh:
export JAVA_OPTS="-XX:MaxPermsize=512m -Xms512m -Xmx4G -Xss=128k"
Obviously these values change if you have less/more RAM to use for your JVM. The only value that you should not change is -Xss=128k, it could cause great performance and stability issues on your server.

In the end, there are some best practices to know (credits to Ivan Pleština):
  • Greatest impact on user-experience in Alfresco is achieved by optimizing search/indexing behavior
  • Searching lucene is FAST no matter how many document you search
  • Checking permissions on documents found using lucene is SLOW
  • Considering the above, make sure your database is working as fast as possible
  • Use RAID 10 for database files, and for lucene index
  • Use SSD if possible
  • Make sure your lucene index is configured optimally, specifically mergerMergeFactor and mergerTargetIndexCount parameters
  • Alfresco content store can be on slow disks and it generally won’t impact user-experience
  • CPU is rarely a real problem
  • JVM heap size is rarely a real problem (but helps tuning it up in the right way)
  • Content transformations (for instance document preview) can be a resource hog – offload if possible
  • HotThreads is your friend
  • org.alfresco.repo.search.impl.lucene.index.IndexInfo is your friend

Read more ...

Integrate Tomcat with Apache Server

1/3/13
To use web application with a frontend server, we need the mod_jk module, which implements the interface between Tomcat and Apache.
The first steps are:
  • Make sure you have JAVA installed and you've correctly set the environment variable path JAVA_HOME
  • Set the PATH variable to point the the bin directory of your JAVA installation
  • Download JK source code from mod_jk link the latest version of the module (at the time of writing this article, it's 1.2.37)
  • Extract the source code in a directory of your choice and go to /native directory
Now is all about building and compiling the source code so you can use the module itself.
./configure --with-apxs=/usr/local/apache/apxs
 make
where /usr/local/apache/apxs is the path to your apxs Apache Server installation path.
Now, go to the apache-2.0 directory, and simply copy the module file "mod_jk.so" into your /modules directory of your Apache Server installation.

Now you have to tell the Apache Server about the module you just copied there:
Open the httpd.conf file and write:
LoadModule jk_module modules/mod_jk.so
JkWorkersFile /usr/local/apps/tomcat/conf/workers.properties
JkLogFile /usr/local/apache/logs/mod_jk.log
JkLogLevel info
JkLogStampFormat "[%a %b %d %H:%M:%S %Y]"
where JkWorkersFile should point to the location of the file that specifies how mod_jk should connect to the Tomcat service and interact with the various worker processes created by Tomcat.
JkLogFile specifies the location of a log for mod_jk errors and information. JkLogLevel and JkLogStampFormat specify what the log contains and what it looks like.

Now you have to create a file named "workers.properties" in the path mentioned above, and fill it with:

workers.tomcat_home=/usr/local/apps/tomcat
workers.java_home=/usr/java
ps=/
worker.list=ajp13
worker.ajp13.port=8009
worker.ajp13.host=localhost
worker.ajp13.type=ajp13
where the port is obviously the Tomcat istance listening port.

The last step is:
add in the httpd.conf file 
JkMount /* ajp13
this will let Apache Server know that i has to forward all the requests to Tomcat.

Now start the Tomcat istance and the Apache server, and just try an example jsp from Tomcat example bundle.
You should reach the jsp page from http://localhost:8080 and from http://localhost

If you have some errors, just control the logs in Apache or Tomcat log directories.



Read more ...

XAMPP: Couldn't start MySQL, problem on Ubuntu

12/12/12

If you have a problem with the error:
XAMPP: Couldn't start MySQL
during your
lampp start
comand, just open the terminal and digit:
sudo chown nobody:root -R /opt/lampp/var/mysql/

That should do the trick. Otherwise, try to uninstall XAMPP and the reinstall it as 'root'.
Read more ...