failure to start mysqld should not remove the /tmp/mysql.sock

failure to start mysqld should not remove the /tmp/mysql.sock

am 10.02.2003 00:01:38 von Nathan Neulinger

> I accidentically got my system to the state where there were two rc
> startup scripts starting mysql with safe_mysqld. Obviously, the second
> one failed cause the port was already in use.
>
> Problem is that the second startup removed the /tmp/mysql.sock file.
>
> This isn't desirable behavior. As it results in a second startup making
> the existing server innaccessible by the local unix socket.
>
> This is with 4.0.7-gamma, but probably affects others as well.
>

How-To-Repeat: Run safe_mysqld when mysqld is already running.

-- Nathan

------------------------------------------------------------
Nathan Neulinger EMail: nneul@umr.edu
University of Missouri - Rolla Phone: (573) 341-4841
Computing Services Fax: (573) 341-4216


------------------------------------------------------------ ---------
Before posting, please check:
http://www.mysql.com/manual.php (the manual)
http://lists.mysql.com/ (the list archive)

To request this thread, e-mail bugs-thread13727@lists.mysql.com
To unsubscribe, e-mail

Re: failure to start mysqld should not remove the /tmp/mysql.sock

am 11.02.2003 13:34:16 von Sinisa Milivojevic

Nathan Neulinger writes:
>
> > I accidentically got my system to the state where there were two rc
> > startup scripts starting mysql with safe_mysqld. Obviously, the second
> > one failed cause the port was already in use.
> >
> > Problem is that the second startup removed the /tmp/mysql.sock file.
> >
> > This isn't desirable behavior. As it results in a second startup making
> > the existing server innaccessible by the local unix socket.
> >
> > This is with 4.0.7-gamma, but probably affects others as well.
> >
>
> How-To-Repeat: Run safe_mysqld when mysqld is already running.
>
> -- Nathan
>
> ------------------------------------------------------------
> Nathan Neulinger EMail: nneul@umr.edu
> University of Missouri - Rolla Phone: (573) 341-4841
> Computing Services Fax: (573) 341-4216
>

Hi!

The above described behaviour is quite true.

But there are situations when mysql server dies without removing
socket and pid files.

So, what would one do in that case ??

--
__ ___ ___ ____ __
/ |/ /_ __/ __/ __ \/ / Mr. Sinisa Milivojevic
/ /|_/ / // /\ \/ /_/ / /__ MySQL AB, Fulltime Developer
/_/ /_/\_, /___/\___\_\___/ Larnaca, Cyprus
<___/ www.mysql.com

Join MySQL Users Conference and Expo:
http://www.mysql.com/events/uc2003/


------------------------------------------------------------ ---------
Before posting, please check:
http://www.mysql.com/manual.php (the manual)
http://lists.mysql.com/ (the list archive)

To request this thread, e-mail bugs-thread13740@lists.mysql.com
To unsubscribe, e-mail

Re: failure to start mysqld should not remove the /tmp/mysql.sock

am 11.02.2003 13:38:34 von Fred van Engen

On Tue, Feb 11, 2003 at 02:34:16PM +0200, Sinisa Milivojevic wrote:
> Nathan Neulinger writes:
> > > This is with 4.0.7-gamma, but probably affects others as well.
> > >
> >
> > How-To-Repeat: Run safe_mysqld when mysqld is already running.
> >
>
> The above described behaviour is quite true.
>
> But there are situations when mysql server dies without removing
> socket and pid files.
>
> So, what would one do in that case ??
>

Open the socket and die if a server responds on the socket. Print some
error message to indicate that something is misconfigured or someone
tried to start a second instance of the server.

Only if no server responds, do what you do now.


Regards,

Fred.

--
Fred van Engen XB Networks B.V.
email: fred.van.engen@xbn.nl Televisieweg 2
tel: +31 36 5462400 1322 AC Almere
fax: +31 36 5462424 The Netherlands

------------------------------------------------------------ ---------
Before posting, please check:
http://www.mysql.com/manual.php (the manual)
http://lists.mysql.com/ (the list archive)

To request this thread, e-mail bugs-thread13741@lists.mysql.com
To unsubscribe, e-mail

Re: failure to start mysqld should not remove the /tmp/mysql.sock

am 11.02.2003 15:44:30 von Nathan Neulinger

Here's a simpler approach.

You only want the local sockets removed if you're starting a new server
and an old one isn't running.

Change mysqld behavior to:
Bind to ip, exit if failed
Remove unix socket
Bind to unix socket, exit if failed

With that process, if it fails to bind to ip socket, it won't ever
remove the pre-existing unix socket.

I haven't looked at source, but it looks to me like it is doing it in a
different order now - to where it isn't failsafe.

Or, at the VERY least, change safe_mysqld to rename the socket to
mysql.sock.$$ or something prior to starting a new mysqld if it exists.
At least then, an admin can _fix_ the running server without having to
shut it down. Right now, it hoses the server completely to where it
requires killing if you don't accept connections for admin users from
the network.

-- Nathan

On Tue, 2003-02-11 at 08:44, Sinisa Milivojevic wrote:
> Fred van Engen writes:
> > On Tue, Feb 11, 2003 at 02:34:16PM +0200, Sinisa Milivojevic wrote:
> >
> > Open the socket and die if a server responds on the socket. Print some
> > error message to indicate that something is misconfigured or someone
> > tried to start a second instance of the server.
> >
> > Only if no server responds, do what you do now.
> >
> >
> > Regards,
> >
> > Fred.
> >
> > --
> > Fred van Engen XB Networks B.V.
> > email: fred.van.engen@xbn.nl Televisieweg 2
> > tel: +31 36 5462400 1322 AC Almere
> > fax: +31 36 5462424 The Netherlands
>
> We have on our TODO to add such diagnostic software, but it can not
> be a part of server.
--

------------------------------------------------------------
Nathan Neulinger EMail: nneul@umr.edu
University of Missouri - Rolla Phone: (573) 341-4841
Computing Services Fax: (573) 341-4216


------------------------------------------------------------ ---------
Before posting, please check:
http://www.mysql.com/manual.php (the manual)
http://lists.mysql.com/ (the list archive)

To request this thread, e-mail bugs-thread13746@lists.mysql.com
To unsubscribe, e-mail

Re: failure to start mysqld should not remove the /tmp/mysql.sock

am 11.02.2003 15:44:34 von Sinisa Milivojevic

Fred van Engen writes:
> On Tue, Feb 11, 2003 at 02:34:16PM +0200, Sinisa Milivojevic wrote:
>
> Open the socket and die if a server responds on the socket. Print some
> error message to indicate that something is misconfigured or someone
> tried to start a second instance of the server.
>
> Only if no server responds, do what you do now.
>
>
> Regards,
>
> Fred.
>
> --
> Fred van Engen XB Networks B.V.
> email: fred.van.engen@xbn.nl Televisieweg 2
> tel: +31 36 5462400 1322 AC Almere
> fax: +31 36 5462424 The Netherlands

We have on our TODO to add such diagnostic software, but it can not
be a part of server.

--
__ ___ ___ ____ __
/ |/ /_ __/ __/ __ \/ / Mr. Sinisa Milivojevic
/ /|_/ / // /\ \/ /_/ / /__ MySQL AB, Fulltime Developer
/_/ /_/\_, /___/\___\_\___/ Larnaca, Cyprus
<___/ www.mysql.com

Join MySQL Users Conference and Expo:
http://www.mysql.com/events/uc2003/


------------------------------------------------------------ ---------
Before posting, please check:
http://www.mysql.com/manual.php (the manual)
http://lists.mysql.com/ (the list archive)

To request this thread, e-mail bugs-thread13745@lists.mysql.com
To unsubscribe, e-mail

Re: failure to start mysqld should not remove the /tmp/mysql.sock

am 11.02.2003 16:06:43 von Sinisa Milivojevic

Nathan Neulinger writes:
> Here's a simpler approach.
>
> You only want the local sockets removed if you're starting a new server
> and an old one isn't running.
>
> Change mysqld behavior to:
> Bind to ip, exit if failed
> Remove unix socket
> Bind to unix socket, exit if failed
>

The above will not work if first server was started with --skip-networking.

--
__ ___ ___ ____ __
/ |/ /_ __/ __/ __ \/ / Mr. Sinisa Milivojevic
/ /|_/ / // /\ \/ /_/ / /__ MySQL AB, Fulltime Developer
/_/ /_/\_, /___/\___\_\___/ Larnaca, Cyprus
<___/ www.mysql.com

Join MySQL Users Conference and Expo:
http://www.mysql.com/events/uc2003/


------------------------------------------------------------ ---------
Before posting, please check:
http://www.mysql.com/manual.php (the manual)
http://lists.mysql.com/ (the list archive)

To request this thread, e-mail bugs-thread13747@lists.mysql.com
To unsubscribe, e-mail

Re: failure to start mysqld should not remove the /tmp/mysql.sock

am 11.02.2003 16:15:54 von Nathan Neulinger

On Tue, 2003-02-11 at 09:06, Sinisa Milivojevic wrote:
> Nathan Neulinger writes:
> > Here's a simpler approach.
> >
> > You only want the local sockets removed if you're starting a new server
> > and an old one isn't running.
> >
> > Change mysqld behavior to:
> > Bind to ip, exit if failed
> > Remove unix socket
> > Bind to unix socket, exit if failed
> >
>
> The above will not work if first server was started with --skip-networking.

In which case, it's going to hose the state regardless - cause unless
you do something special with locking, the second mysql _IS_ going to
start, and you're going to have multiple writers to the same db files.

This will at least fix the most common case, with no impact on the other
case.

I suppose you could always have mysqld to try and connect to the local
unix socket during it's startup (as an extra check), and refuse to start
up if something answered.

-- Nathan

------------------------------------------------------------
Nathan Neulinger EMail: nneul@umr.edu
University of Missouri - Rolla Phone: (573) 341-4841
Computing Services Fax: (573) 341-4216


------------------------------------------------------------ ---------
Before posting, please check:
http://www.mysql.com/manual.php (the manual)
http://lists.mysql.com/ (the list archive)

To request this thread, e-mail bugs-thread13748@lists.mysql.com
To unsubscribe, e-mail

Re: failure to start mysqld should not remove the /tmp/mysql.sock

am 11.02.2003 16:31:34 von Sinisa Milivojevic

Nathan Neulinger writes:
> On Tue, 2003-02-11 at 09:06, Sinisa Milivojevic wrote:
>
> In which case, it's going to hose the state regardless - cause unless
> you do something special with locking, the second mysql _IS_ going to
> start, and you're going to have multiple writers to the same db files.
>

Not necesarily.

Second server can be started with different --datadir, so it does not
hold.

> This will at least fix the most common case, with no impact on the other
> case.
>

Again, not entirely. You can have truly many different variants of
start-ups, for example with --bind-address.

> I suppose you could always have mysqld to try and connect to the local
> unix socket during it's startup (as an extra check), and refuse to start
> up if something answered.
>
> -- Nathan

I do not think that we should clibber server with such diagnostics.

But an optional client program that checks on socket / ip is doable.

--
__ ___ ___ ____ __
/ |/ /_ __/ __/ __ \/ / Mr. Sinisa Milivojevic
/ /|_/ / // /\ \/ /_/ / /__ MySQL AB, Fulltime Developer
/_/ /_/\_, /___/\___\_\___/ Larnaca, Cyprus
<___/ www.mysql.com

Join MySQL Users Conference and Expo:
http://www.mysql.com/events/uc2003/


------------------------------------------------------------ ---------
Before posting, please check:
http://www.mysql.com/manual.php (the manual)
http://lists.mysql.com/ (the list archive)

To request this thread, e-mail bugs-thread13749@lists.mysql.com
To unsubscribe, e-mail

Re: failure to start mysqld should not remove the /tmp/mysql.sock

am 11.02.2003 22:25:31 von Jani Tolonen

Sinisa Milivojevic writes:
> Nathan Neulinger writes:
> > On Tue, 2003-02-11 at 09:06, Sinisa Milivojevic wrote:
> >
> > In which case, it's going to hose the state regardless - cause unless
> > you do something special with locking, the second mysql _IS_ going to
> > start, and you're going to have multiple writers to the same db files.
> >
>
> Not necesarily.
>
> Second server can be started with different --datadir, so it does not
> hold.
>
> > This will at least fix the most common case, with no impact on the other
> > case.
> >
>
> Again, not entirely. You can have truly many different variants of
> start-ups, for example with --bind-address.
>
> > I suppose you could always have mysqld to try and connect to the local
> > unix socket during it's startup (as an extra check), and refuse to start
> > up if something answered.
> >
> > -- Nathan
>
> I do not think that we should clibber server with such diagnostics.
>
> But an optional client program that checks on socket / ip is doable.

Hi!

I think there is quite easy solution to this...

This problem only occurs if the second safe_mysqld is started with
different --datadir option than the previous one OR if the pid_file is
not found. If pid_file of the previously started MySQL server is
found, safe_mysqld does NOT remove socket file and exists with error:

"A mysqld process already exists"

However, if pid_file is not found (different datadir, or previous
MySQL server did not create it for some reason, maybe a permission
problem, or whatever), then it currently removes the UNIX socket
file that it thinks belongs to the server it's trying to start.

The fix is simple:

This is latest mysqld_safe from mysql-4.1 distribution. The
same fix is easy to implement to any safe_mysqld version.

------------------------------------------------------------ ----------
*** /my/tmp/mysqld_safe.sh.org Tue Feb 11 23:23:06 2003
--- mysqld_safe.sh Tue Feb 11 23:23:19 2003
***************
*** 270,276 ****
echo "`date +'%y%m%d %H:%M:%S mysqld started'`" >> $err_log
while true
do
- rm -f $MYSQL_UNIX_PORT $pid_file # Some extra safety
if test -z "$args"
then
$NOHUP_NICENESS $ledir/$MYSQLD $defaults --basedir=$MY_BASEDIR_VERSION --datadir=$DATADIR $USER_OPTION --pid-file=$pid_file @MYSQLD_DEFAULT_SWITCHES@ >> $err_log 2>&1
--- 270,275 ----
***************
*** 309,315 ****
I=`expr $I + 1`
done
fi
!
echo "`date +'%y%m%d %H:%M:%S'` mysqld restarted" | tee -a $err_log
done

--- 308,314 ----
I=`expr $I + 1`
done
fi
! rm -f $MYSQL_UNIX_PORT $pid_file # Some extra safety
echo "`date +'%y%m%d %H:%M:%S'` mysqld restarted" | tee -a $err_log
done
------------------------------------------------------------ ----------

Regards,

- Jani

For technical support contracts, visit https://order.mysql.com/
__ ___ ___ ____ __
/ |/ /_ __/ __/ __ \/ / Mr. Jani Tolonen
/ /|_/ / // /\ \/ /_/ / /__ MySQL AB, Full-Time Developer
/_/ /_/\_, /___/\___\_\___/ Helsinki, Finland
<___/ www.mysql.com

------------------------------------------------------------ ---------
Before posting, please check:
http://www.mysql.com/manual.php (the manual)
http://lists.mysql.com/ (the list archive)

To request this thread, e-mail bugs-thread13753@lists.mysql.com
To unsubscribe, e-mail