Forum Stats

  • 3,838,084 Users
  • 2,262,326 Discussions
  • 7,900,498 Comments

Discussions

mysqld_safe how does the instance check work

daniel_hauke
daniel_hauke Member Posts: 211 Bronze Badge
edited Mar 7, 2018 9:40AM in MySQL Community Space

Hi everybody,

can anyone please explain me how the mysqld_safe process is doing the check of the mysqld process.

Does it use mysqladmin ping or something like that?

Greetings Daniel

daniel_hauke

Best Answer

  • Gaz in Oz
    Gaz in Oz Member Posts: 3,785 Bronze Crown
    edited Mar 6, 2018 9:33PM Answer ✓
    ...can anyone please explain me how the mysqld_safe process is doing the check of the mysqld process.

    Looking at the /usr/bin/mysqld_safe shell script, it checks to see if mysqld is running via:

    ## If there exists an old pid file, check if the daemon is already running# Note: The switches to 'ps' may depend on your operating systemif test -f "$pid_file"then  PID=`cat "$pid_file"`  if /usr/bin/kill -0 $PID > /dev/null 2> /dev/null  then    if /bin/ps wwwp $PID | grep -v " grep" | grep -v mysqld_safe | grep -- "$MYSQLD" > /dev/null    then    # The pid contains a mysqld process      log_error "A mysqld process already exists"      exit 1    fi  fi  rm -f "$pid_file"  if test -f "$pid_file"  then    log_error "Fatal error: Can't remove the pid file:$pid_filePlease remove it manually and start $0 again;mysqld daemon not started"    exit 1  fifi

    Lines 07. to 14.

    Does it use mysqladmin ping or something like that?

    No.

       https://dev.mysql.com/doc/refman/5.7/en/mysqld-safe.html

    daniel_hauke

Answers

  • Gaz in Oz
    Gaz in Oz Member Posts: 3,785 Bronze Crown
    edited Mar 6, 2018 9:33PM Answer ✓
    ...can anyone please explain me how the mysqld_safe process is doing the check of the mysqld process.

    Looking at the /usr/bin/mysqld_safe shell script, it checks to see if mysqld is running via:

    ## If there exists an old pid file, check if the daemon is already running# Note: The switches to 'ps' may depend on your operating systemif test -f "$pid_file"then  PID=`cat "$pid_file"`  if /usr/bin/kill -0 $PID > /dev/null 2> /dev/null  then    if /bin/ps wwwp $PID | grep -v " grep" | grep -v mysqld_safe | grep -- "$MYSQLD" > /dev/null    then    # The pid contains a mysqld process      log_error "A mysqld process already exists"      exit 1    fi  fi  rm -f "$pid_file"  if test -f "$pid_file"  then    log_error "Fatal error: Can't remove the pid file:$pid_filePlease remove it manually and start $0 again;mysqld daemon not started"    exit 1  fifi

    Lines 07. to 14.

    Does it use mysqladmin ping or something like that?

    No.

       https://dev.mysql.com/doc/refman/5.7/en/mysqld-safe.html

    daniel_hauke
  • daniel_hauke
    daniel_hauke Member Posts: 211 Bronze Badge
    edited Mar 7, 2018 9:40AM

    Hi,

    thanks fot the hint and your answer. That was very helpful.

    Greetings Daniel