Thursday, June 16, 2016

SetUp a cron to restart node project if it's not running

Check if node project is running using swagger and start if not running.

#!/bin/bash

###edit the following
service=swagger
email=email@yourdomain.com.au
###stop editing

host=`hostname -f`
if (( $(ps -ef | grep -v grep | grep $service | wc -l) > 0 ))
then
 echo "$service is running"
else
 /root/.nvm/versions/node/v4.4.5/bin/swagger project start -m /root/snpts/my-mock-api &
 if (( $(ps -ef | grep -v grep | grep $service | wc -l) > 0 ))
 then
  subject="$service at $host has been started"
  echo "$service at $host wasn't running and has been started" | mail -s "$subject" $email
 else
  subject="$service at $host is not running"
  echo "$service at $host is stopped and cannot be started!!!" | mail -s "$subject" $email
 fi
fi

Ref: http://www.akamaras.com/linux/linux-script-to-check-if-a-service-is-running-and-start-it-if-its-stopped/

Tuesday, May 17, 2016

SCP copy files recursively and exclude file

To copy files recursively from remote using SCP, just use flag "-r" like this:

$ scp -r user@acidstaging.com:/home/dltr/public_html/current/trunk/* ./trunk/

If you would like to exclude some files then use either of these:

exclude dot files:

$ scp -r [!.]* user@acidstaging.com:/home/dltr/public_html/current/trunk/* ./trunk/

exclude .svn files:

$ scp -r [!.svn] user@acidstaging.com:/home/dltr/public_html/current/trunk/* ./trunk/

For Rsync check this post.

http://www.snpts.org/2016/04/rsync-multiple-examples-to-exclude.html

Friday, May 6, 2016

Use Meld.exe as git mergetool in cygwin windows

I am using cygwin git and I was struggling to use meld as my favorite mergetool.

I was unable to run meld which was installed in cygwin, so installed in windows instead at:

C:\Program Files (x86)\Meld\Meld.exe


My ~/.gitconfig had this setting, but says file not found when i run git mergetool.

[merge]
    tool = meld
[mergetool "meld"]
    path = "C:\Program Files (x86)\Meld\Meld.exe"


So ended up removing meld from cygwin and symlink windows meld like this:

$ cd /usr/bin/
$ ln -s "C:\Program Files (x86)\Meld\Meld.exe" meld

Changed .gitconfig to:

[merge]
    tool = meld
[mergetool "meld"]
    path = /usr/bin/meld

Then I was successfully able to use meld as a git merge tool. Only thing it still doesn't work is when i try to use it from windows cmd. So just for git merge tool, i have to open cygwin bash :(


Let me know if you know a good solution that will work on both bash (cygwin & windows)

Tuesday, April 5, 2016

Magento Warning: simplexml_load_string() Parser Error

Sometimes when you enable caching in magento, you will get this error:

Warning: simplexml_load_string(): Entity: line 83: parser error : StartTag: invalid element name  in /home/magento/enterprise/lib/Varien/Simplexml/Config.php on line 383

#0 [internal function]: mageCoreErrorHandler(2, 'simplexml_load_...', '/home/magento/enterprise/...', 383, Array)
#1 /home/magento/enterprise/lib/Varien/Simplexml/Config.php(383): simplexml_load_string('loadCache()
#3 /home/magento/enterprise/app/code/core/Mage/Core/Model/App.php(424): Mage_Core_Model_Config->loadModulesCache()
#4 /home/magento/enterprise/app/code/core/Mage/Core/Model/App.php(354): Mage_Core_Model_App->_initModules()
#5 /home/magento/enterprise/app/Mage.php(684): Mage_Core_Model_App->run(Array)
#6 /home/magento/enterprise/index.php(86): Mage::run('', 'store')
#7 {main}


I am sure you have custom theme (or extensions) installed, and you can't trust them 100%.

To quickly fix check if you can find any entries when you run:

SELECT * FROM `core_config_data` where path > 0;


If you can, then awesome, you can fix it by running:

DELETE FROM `core_config_data` where path > 0;


Flush your cache and you are good to enable cache again.

If those entries re-appear you need to investigate every single third party additions.

Rsync Multiple Examples to Exclude Files and Directories Using exclude-from

1. Exclude one directory

$ rsync -avz --exclude 'dir1' source/ destination/


2. Exclude multiple directories using pattern

$ rsync -avz --exclude 'dir*' source/ destination/


3. Exclude one file

$ rsync -avz --exclude 'dir1/dir2/file3.txt' source/ destination/


4. Exclude certain file types

$ rsync -avz --exclude '*.txt' source/ destination/


5. Exclude multiple files and folders at the same time

$ rsync -avz --exclude file1.txt --exclude dir3/file4.txt source/ destination/

or,

$ rsync -avz --exclude-from 'exclude-list.txt' source/ destination/

where: exclude-list.txt contains excluded files and folder names

e.g.
excluded-file.txt
excluded/directory/
var/log/
media/catalog/product/cache/

Tuesday, May 27, 2014