◎ Example mariadb_ctl.erb
export JOB_INDEX=<%= index %>
if [ ! -f /usr/local/bin/mysql ]; then
log "Adding mysql to path"
ln -s /var/vcap/packages/mariadb/bin/mysql /usr/local/bin
◎ add perl libraries to perl env
◎ The start script must always exit 0 if there's a chance Maria could start successfully,
◎ as if monit sees a pid for Maria but this script exited with error, it will assume
◎ someone else started the process in the background.
◎ This will latch the status to "Execution failed" until someone manually calls
monit unmonitor && monit monitor, at which point monit would find the pid and reset the status to 'running'
if [[ ! -d "$RUN_DIR" ]]; then
log "start script: directory $RUN_DIR does not exist, creating it now"
log "start script: checking for existing instance of $MY_NAME"
$(source /var/vcap/packages/common/utils.sh; pid_guard $PIDFILE $MY_NAME)
log "start script: pg_exit_code: $pg_exit_code"
if [ $pg_exit_code -eq 1 ]; then
log "start script: $MY_NAME already running. Exiting 0 so that monit doesn't think that execution failed"
log "start script: writing pid $ for $MY_NAME to $PIDFILE"
log "start script: checking if mysqld_safe is already running... "
pgrep -f /var/vcap/packages/mariadb/bin/mysqld_safe
// Exit code of 0 means we did find a process, so we should exit.
if [ $result_code -eq 0 ]; then
log "start script: mysqld_safe already running - exiting with 0 so that monit doesn't think that execution failed"
log "start script: mysqld_safe not already running - continue"
chown vcap:vcap $LOG_FILE
date >> $LOG_FILE 2>> $LOG_FILE
It is surprisingly hard to get the config file location passed in
on the command line to the mysql.server script. This is easier.
ln -sf $MARIADB_JOB_DIR/config/my.cnf $CONFIG_DIR/my.cnf