Take the 2-minute tour ×
Database Administrators Stack Exchange is a question and answer site for database professionals who wish to improve their database skills and learn from others in the community. It's 100% free, no registration required.

If I run mysqld, ie invoke it directly on the command-line, it survives the shell being closed or hitting ctrl-c.

Is there any way to run it "interactively", ie so that it will shut down if either of those things happen?

(I'd find this useful during development as I have a tmux script to quickly bring up and down various servers.)

share|improve this question
    
If you have a tmux script i'm sure you have enough shell ability to record the PID in a shell variable or temporary file, also whack your shell PID in a temporary file, fork off another shell script that sits there and checks if everything you've written to your temporary files is still running, and if not. kill -9. Done. Why would mysqlDAEMON be interactive? –  Phil Nov 9 '13 at 2:22
    
Like I said, it's a convenience thing for development. Almost all other Unix servers work this way, so it helps if everything is consisten without having to stop and think how each particular server in my workflow is bounced. And yes, I (and anyone else facing this issue) could jump through hoops writing and debugging PID-munging bash scripts, but I asked the question in case there's already a tool out there or some option I missed. –  mahemoff Nov 9 '13 at 11:04
    
Also, if I close the tmux session, all servers should go away (convenient for freeing up resources on a machine that's used for different purposes). Right now, one of those services sticks around. –  mahemoff Nov 9 '13 at 11:30
add comment

2 Answers 2

up vote 1 down vote accepted

You could try --gdb. That will make it respond to SIGINT, though I'm not sure if that has potential to corrupt the database. --one-thread may also be of some help.

share|improve this answer
    
I've been trying --gdb for a while now and it's worked great, thanks. –  mahemoff Dec 3 '13 at 12:25
add comment

If installing the initscript and using the standard sudo service mysql start | stop aren't on the list of things you consider reasonable options, you could always compile your own version of mysqld with some custom hackery to the signal handling code in sql/mysqld.cc where it looks like some signals aren't defined yet, so presumably no-ops just waiting for some copy/paste, though there may be additional code that is masking them before this switch is hit.

switch (sig) {
case SIGTERM:
case SIGQUIT:
case SIGKILL:
#ifdef EXTRA_DEBUG
      sql_print_information("Got signal %d to shutdown mysqld",sig);
#endif
      /* switch to the old log message processing */
      logger.set_handlers(LOG_FILE, opt_slow_log ? LOG_FILE:LOG_NONE,
                          opt_log ? LOG_FILE:LOG_NONE);
      DBUG_PRINT("info",("Got signal: %d  abort_loop: %d",sig,abort_loop));
      if (!abort_loop)
      {
        abort_loop=1;       // mark abort for threads
#ifdef HAVE_PSI_THREAD_INTERFACE
        /* Delete the instrumentation for the signal thread */
        PSI_THREAD_CALL(delete_current_thread)();
#endif
#ifdef USE_ONE_SIGNAL_HAND
        pthread_t tmp;
        if (mysql_thread_create(0, /* Not instrumented */
                                &tmp, &connection_attrib, kill_server_thread,
                                (void*) &sig))
          sql_print_error("Can't create thread to kill server");
#else
        kill_server((void*) sig); // MIT THREAD has a alarm thread
#endif
      }
      break;
...

Otherwise, no.

share|improve this answer
1  
This makes sense... if you want to recompile the source you should add SIGINT (triggerd by ctrl-c) to that switch case and call the function kill_server that would do the trick.. –  Raymond Nijland Nov 9 '13 at 16:56
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.