Author Archives: Manila Chaturvedi

How to persist ulimit settings in OSX

Shell Session Limit

The limits set via ulimit only affects processes created by the current shell session.

  • The “soft limit” is the actual limit that is used. It could be set, as far as it’s not greater than the “hard limit”.
  • The “hard limit” could also be set, but only to a value less than the current one, and only to a value not less than the “soft limit”.
  • The “hard limit”, as well as system-wide limits, could be raised by root (the administrator) by executing system configuration commands or modifying system configuration files.

After you terminate the shell session (by Ctrl+D, exit, or closing the window, etc.), the settings are gone. If you want the same setting in the next shell session, add the setting to the shell startup script.

NOTE: If you are using bash, then it should be ~/.bash_proile or ~/.bash_login. If you are using other shells, it should probably be ~/.profile.

System Limit (Requires Reboot to Take Effect)

For older Mac OS X (I guess it works on 10.7 (Lion) or before):You may add the following line to /etc/launchd.conf (owner: root:wheel, mode: 0644):

limit maxfiles 262144 524288

You should change the numbers according to your needs. They are the “soft limit” (262144) and the is “hard limit” (524288) respectively.

For 10.8 (Mountain Lion):You may add the following lines to /etc/sysctl.conf (owner: root:wheel, mode: 0644):


You should change the numbers according to your needs. They are the “system-wide limit” (kern.maxfiles) and “per-process limit” (kern.maxfilesperproc) respectively. For more settings, consult the manual page by running man sysctl, or read the source code at /usr/include/sys/sysctl.h.

For 10.9 (Mavericks), 10.10 (Yosemite),  10.11 (El Capitan), and 10.12 (Sierra):You have to create a file at /Library/LaunchDaemons/limit.maxfiles.plist (owner: root:wheel, mode: 0644):

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN"
<plist version="1.0">

You should change the numbers according to your needs. They are the “soft limit” (262144) and the is “hard limit” (524288) respectively. For more information, consult the manual page by running man launchd.plist.

If the system doesn’t let you set the limits above a certain value…The system doesn’t let you set a value higher than a “hard maximum” (proposed by Apple). To increase this “hard maximum”, you have to purchase “OS X Server” from “App Store”, then you have to execute the following command once:

sudo serverinfo --setperfmode true

This activates “server performance mode” on your machine. You can then set the maximum according to the configuration of your machine (see this).


PrestaShop – Setup TEST site in sub-domain

Clone production DB to a new database and run following query in new DB

UPDATE `ps_shop` SET `name`=concat('TEST ',`name`);
UPDATE `ps_shop_url` SET `domain`=concat('test.',`domain`),`domain_ssl`=concat('test.',`domain_ssl`);
UPDATE `ps_configuration` SET `value` = concat('test.',`value`) WHERE `name` like 'PS_SHOP_DOMAIN%';
UPDATE `ps_configuration` SET `value` = '0' WHERE `name` = 'PS_SHOP_ENABLE';
UPDATE `ps_configuration` SET  `value`=concat('TEST ',`value`) WHERE `name` = 'PS_SHOP_NAME';
UPDATE `ps_configuration` SET value = '2' where `name` = 'PS_SMARTY_FORCE_COMPILE';
UPDATE `ps_configuration` SET value = '0' where `name` = 'PS_SMARTY_CACHE';

You can run following query to avoid sending mails to customer for any test:

UPDATE `ps_customer` SET `email` = CONCAT(REPLACE(REPLACE(`email` ,'@','-'),'.','_'),'');


MySQL on Mac OSX change sql_mode in LaunchDaemons

After installing MySQL for Mac OSX a launch daemon file (/Library/LaunchDaemons/ is created. Adding lines mentioned in Orange will force mysql daemon to use custom option.

<?xml version=”1.0″ encoding=”UTF-8″?>
<!DOCTYPE plist PUBLIC “-//Apple Computer//DTD PLIST 1.0//EN” “”>
<plist version=”1.0″>
<key>Label</key>             <string></string>
<key>ProcessType</key>       <string>Interactive</string>
<key>Disabled</key>          <false/>
<key>RunAtLoad</key>         <true/>
<key>KeepAlive</key>         <true/>
<key>SessionCreate</key>     <true/>
<key>LaunchOnlyOnce</key>    <false/>
<key>UserName</key>          <string>_mysql</string>
<key>GroupName</key>         <string>_mysql</string>
<key>ExitTimeOut</key>       <integer>600</integer>
<key>Program</key>           <string>/usr/local/mysql/bin/mysqld</string>
<key>WorkingDirectory</key>  <string>/usr/local/mysql</string>

MySQL start manually with diff user and data

If you have recently update mysql database and forgot to make a backup of old database then use following technique.

  1. Download TAR version my MySQL matching the old version
  2. untar the MySQL program
  3. stop new version of mysql server
  4. start old version of mysql using “mysqld –user=mysql –console –datadir=/usr/local/mysql-5.6.25-osx10.8-x86_64/data
  5. Now old version server is up so you can continue export databases
  6. stop mysqld
  7. start new MySQl server
  8. Restore database using newly backed up files.

Start Tomcat automatically on OS X using launchd

Using launchd with Tomcat

The Tomcat standalone distribution ships with Tomcat. There is a mismatch between how launchd expects a daemon to behave, and how the default startup scripts for Tomcat operate:

  • OS X’s launchd expects the process it starts to run forever, but ‘ start‘ starts the JVM to run Tomcat and then exits.
  • Tomcat provides ‘ stop‘ to shut down Tomcat cleanly by connecting to a socket which Tomcat listens on, but launchd stops daemons by sending them a signal that kills the process immediately if no specific handling is included.

You will need a wrapper shell script and properties list to make launchd work with Tomcat.

Step 1. Add a Wrapper Shell Script

Add the following wrapper shell script to $CATALINA_HOME/bin:
function shutdown()
        echo "Shutting down Tomcat"
        $CATALINA_HOME/bin/ stop
echo "Starting Tomcat"
export CATALINA_PID=/tmp/$$
# Uncomment to increase Tomcat's maximum heap allocation
# export JAVA_OPTS=-Xmx512M $JAVA_OPTS
. $CATALINA_HOME/bin/ start
# Allow any signal which would kill a process to stop Tomcat
echo "Waiting for `cat $CATALINA_PID`"
wait `cat $CATALINA_PID`


The above shell script starts Tomcat and then waits for the process to complete, so launchd is happy that Tomcat is still running. The script also installs a signal handler, which calls the shutdown() function to cleanly shut down Tomcat when launchd signals the script.

You can try this script manually: Start the script, watch Tomcat start, and then type ctrl-C and see Tomcat shut down cleanly. (Note that it will not shut down cleanly if Tomcat has not started yet. It takes a few seconds for Tomcat to start listening on the shutdown socket.)

Step 2. Add a launchd Property List

The launchd property list (.plist) tells launchd how to start Tomcat.

Add the following plist file to /Library/LaunchDaemons, which is the location for system-wide services which are not part of base OS X:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "">
<plist version="1.0">


  1. Replace ‘/Users/myname/conf/tomcat-6.0‘ with the path to your Tomcat installation. The string occurs four times in the above script.
  2. JAVA_HOME is set to use the default JDK. On OS X version 10.4.4, the default JDK is 1.4.2. You will need to change this value if you want to use a different version of Java. For example, if you want to use JDK 1.5, you will need to change JAVA_HOME to /System/Library/Frameworks/JavaVM.framework/Versions/1.5.
  3. In the above script, we have specified ‘root‘ as the UserName. If necessary, change the UserName to the user you want Tomcat to run as.

Starting and Stopping Tomcat Manually

To start and stop Tomcat manually, use the following commands:

  • Start:
    cd /Library/LaunchDaemons
    sudo launchctl load -w tomcat.plist
  • Stop:
    cd /Library/LaunchDaemons
    sudo launchctl unload -w tomcat.plist


  • Make sure both files and tomcat.plist have the necessary file privileges.
  • Check the console logging and log file for any abnormalities.