1

I am trying to roll out pt-stalk with an init script, but I'm having a hard time getting the mysql credentials into the script without putting them in the MYSQL_OPTS section for the pt-stalk launch. [Documentation]

Normally on the servers we have /root/.my.cnf containing the admin credentials for that machine, but no matter if I set the HOME var in the script explicitly to /root within the init script pt-stalk fails to start because the mysql CLI utility cannot find the credentials.

I've looked through the man page, but I cannot find anything that allows me to specify a credentials file to use rather than putting everything as command line arguments.

The init script in question:

#!/usr/bin/env bash
# chkconfig: 2345 20 80
# description: pt-stalk
### BEGIN INIT INFO
# Provides: pt-stalk
# Required-Start: $network $named $remote_fs $syslog
# Required-Stop: $network $named $remote_fs $syslog
# Should-Start: pt-stalk
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
### END INIT INFO

export HOME=/root
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
DAEMON="/usr/bin/pt-stalk"
DAEMON_OPTS="--config /etc/pt-stalk.conf"
NAME="pt-stalk"
DESC="pt-stalk"
PIDFILE="/var/run/${NAME}.pid"
STALKHOME="/var/lib/pt-stalk"

test -x $DAEMON || exit 1

[ -r /etc/default/pt-stalk ] && . /etc/default/pt-stalk

#. /lib/lsb/init-functions

sig () {
    test -s "$PIDFILE" && kill -$1 `cat $PIDFILE`
}

start() {
  if [[ -z $MYSQL_OPTS ]]; then
HOME=$STALKHOME $DAEMON $DAEMON_OPTS
  else
HOME=$STALKHOME $DAEMON $DAEMON_OPTS -- $MYSQL_OPTS
  fi
return $?
}

stop() {
  if sig TERM; then
    while sig 0 ; do
      echo -n "."
      sleep 1
    done
    return 0
  else
    echo "$DESC is not running."
    return 1
  fi
}

status() {
  if sig 0 ; then
    echo "$DESC (`cat $PIDFILE`) is running."
    return 0
  else
    echo "$DESC is stopped."
    return 1
  fi
}

log_begin_msg() {
        echo $1
}

log_end_msg() {
        if [ $1 -eq 0 ]; then
           echo "Success"
        else
           echo "Failure"
        fi
}

case "$1" in
  start)
   log_begin_msg "Starting $DESC"
   start
   log_end_msg $?
   ;;

  stop)
   log_begin_msg "Stopping $DESC"
   stop
   log_end_msg $?
   ;;
  status)
    status ;;

  restart)
    log_begin_msg "Restarting $DESC"
    stop
    sleep 1
    start
    log_end_msg $?
    ;;

  *)
    echo "Usage: $0 {start|stop|status|}" >&2
    exit 1
    ;;
esac

Originally from GitHub with a couple minor changes.

1 Answer 1

2

The example on this page seems to suggest to pass the --defaults-file=./my.default.cnf as an option to pt-stalk.

So update your $MYSQL_OPTS variable to have that as a value, probably giving the absolute path to you a mysql configuration file (.my.cnf) stored somewhere that the pt-stalk command can read.

1
  • That's the ticket. Thank you, sir. It's super helpful that this option is not in the man page or any official MySQL documentation that I could turn up.
    – Sammitch
    Aug 20, 2013 at 20:46

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .