/bin/cp: cannot create regular file `/usr/bin/mongod': Text file busy

3,823 views
Skip to first unread message

Michael Conigliaro

unread,
May 5, 2011, 11:51:20 AM5/5/11
to mongodb-user
Hey guys,

I noticed that Linux won't let me overwrite the MongoDB binaries while
they're in use. I get a message like this:

/bin/cp: cannot create regular file `/usr/bin/mongod': Text file busy

If I use lsof/fuser, it looks the executable is actually being held
open for some reason. I've never seen anything like this before, but
I've found that I can force overwriting the binary by using cp -f. Of
course, this closes the open file handle, but the service seems to
continue working anyway (as far as I can tell).

Is there any reason why I shouldn't do this? The reason I ask is
because it would be really easy to have my configuration management
system overwrite all the binaries for me in preparation for a minor
upgrade. Then I can just go around and manually restart the daemons
when I'm ready.

- Mike

Andreas Jung

unread,
May 5, 2011, 11:57:33 AM5/5/11
to mongod...@googlegroups.com
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Michael Conigliaro wrote:
> Hey guys,
>
> I noticed that Linux won't let me overwrite the MongoDB binaries while
> they're in use. I get a message like this:
>
> /bin/cp: cannot create regular file `/usr/bin/mongod': Text file busy
>
> If I use lsof/fuser, it looks the executable is actually being held
> open for some reason. I've never seen anything like this before, but
> I've found that I can force overwriting the binary by using cp -f. Of
> course, this closes the open file handle, but the service seems to
> continue working anyway (as far as I can tell).

lsof/fuser should tell you which process/pid is using the binary.

- -aj
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.11 (Darwin)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iQGUBAEBAgAGBQJNwsjtAAoJEADcfz7u4AZjbMQLv0bX8shvikmPjpxZ/a5dfnJC
NO7iBfrwAMvYXiQWTToOk8pPI6NMxnczzsw9By/mlMwqOudf3zp4dL65XybbhF+1
3QDe5UMcZd612BhOt7IrHWuo8c4iFMUqptN0MGE1ZQd9yrEulh5eQ0XHB5mc+gc1
LR+6mcbalvzaBp0CX0si3FE2VgMAs1ovxQrNZtSC+JVmvSNS/SHnfK90AxXCQevD
wGEMWErtFC0NcYgmdjX3p0BsDLAZmsJkv46d7Xwx6pUTH0OCnnnuQhaw+ulLPSvu
tZkdcX6tmIURf2vmZs8VBVV7126Qh2AS5l2x6PnN5wvRFGMxbxE5u0r4D0bnYFTA
Jh49YBKtBBHIyRA1teyEdaoU/QUbmwLt3KfwUMR3TC+3799kRll4wRgMVjdXw9V7
g7+M43Uy5IY+4ASxvTt+AYLuw53Ti+zI6fWeRNEtR3kjTW5d7k5yzZNzy7m37KM8
p0uZs0aMytnjNVLlM6POTGraBCafuiU=
=izui
-----END PGP SIGNATURE-----

lists.vcf

Scott Hernandez

unread,
May 5, 2011, 11:57:55 AM5/5/11
to mongod...@googlegroups.com
Yeah, I recently got this on gentoo as well. What os/distro are you using?

I rm'd the files first, or rsync'd, and that seemed to take care of it.

It was confusing to say the least :(


--
You received this message because you are subscribed to the Google Groups "mongodb-user" group.
To post to this group, send email to mongod...@googlegroups.com.
To unsubscribe from this group, send email to mongodb-user...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/mongodb-user?hl=en.


tmountain

unread,
May 5, 2011, 11:58:10 AM5/5/11
to mongodb-user
You can't do that. It will result in a corrupted binary, and mongod/
mongos/etc will crash. I tried to do this on some production servers
in the not so recent past, and it was a disaster. For more on why this
is, read this:

http://lists.freebsd.org/pipermail/freebsd-current/2003-September/009972.html

On May 5, 11:51 am, Michael Conigliaro

Richard Kreuter

unread,
May 5, 2011, 12:13:50 PM5/5/11
to mongod...@googlegroups.com
The behavior you're seeing is desirable behavior: if you overwrite a
binary (or a library it links to) while the corresponding process is
running, you'll corrupt the running process.

"cp -f" on the other hand, unlinks an existing file when open(2) fails,
and creates a new file with the same name. This is a reasonably safe
(albeit non-atomic) way to replace binaries and library files while a
process is running.

Regards,
Richard

> --
> You received this message because you are subscribed to the Google Groups "mo
> ngodb-user" group.
> To post to this group, send email to mongod...@googlegroups.com.

> To unsubscribe from this group, send email to mongodb-user+unsubscribe@google

tmountain

unread,
May 5, 2011, 12:22:27 PM5/5/11
to mongodb-user
Good tip on "cp -f", but I find it hard to imagine how corrupting a
running process would ever be "desirable behavior".

Richard Kreuter

unread,
May 5, 2011, 12:41:17 PM5/5/11
to mongod...@googlegroups.com
I meant that cp failing to overwrite the existing file with "Text file
busy" is desirable. Sorry about the ambiguity.

tmountain writes:
> Good tip on "cp -f", but I find it hard to imagine how corrupting a
> running process would ever be "desirable behavior".
>

> On May 5, 12:13=A0pm, Richard Kreuter <rich...@10gen.com> wrote:
> > The behavior you're seeing is desirable behavior: if you overwrite a
> > binary (or a library it links to) while the corresponding process is

> > running, you'll corrupt the running process. =A0


> >
> > "cp -f" on the other hand, unlinks an existing file when open(2) fails,

> > and creates a new file with the same name. =A0This is a reasonably safe


> > (albeit non-atomic) way to replace binaries and library files while a
> > process is running.
> >
> > Regards,
> > Richard
> >
> >
> >
> >
> >
> >
> >
> > Michael Conigliaro writes:
> > > Hey guys,
> >
> > > I noticed that Linux won't let me overwrite the MongoDB binaries while
> > > they're in use. I get a message like this:
> >
> > > /bin/cp: cannot create regular file `/usr/bin/mongod': Text file busy
> >
> > > If I use lsof/fuser, it looks the executable is actually being held
> > > open for some reason. I've never seen anything like this before, but
> > > I've found that I can force overwriting the binary by using cp -f. Of
> > > course, this closes the open file handle, but the service seems to
> > > continue working anyway (as far as I can tell).
> >
> > > Is there any reason why I shouldn't do this? The reason I ask is
> > > because it would be really easy to have my configuration management
> > > system overwrite all the binaries for me in preparation for a minor
> > > upgrade. Then I can just go around and manually restart the daemons
> > > when I'm ready.
> >
> > > - Mike
> >
> > > --

> > > You received this message because you are subscribed to the Google Grou=


> ps "mo
> > > ngodb-user" group.
> > > To post to this group, send email to mongod...@googlegroups.com.

> > > To unsubscribe from this group, send email to mongodb-user+unsubscribe@=
> google
> > > groups.com.
> > > For more options, visit this group athttp://groups.google.com/group/mon=
> godb-
> > > user?hl=3Den.
>
> --=20
> You received this message because you are subscribed to the Google Groups "=
> mongodb-user" group.


> To post to this group, send email to mongod...@googlegroups.com.

> To unsubscribe from this group, send email to mongodb-user+unsubscribe@goog=
> legroups.com.
> For more options, visit this group at http://groups.google.com/group/mongod=
> b-user?hl=3Den.
>

Michael Conigliaro

unread,
May 5, 2011, 1:01:15 PM5/5/11
to mongodb-user
Andreas, I know how to check which process is using the binary. The
bottom line is that I don't care what's using it. I just want to know
if it's safe to overwrite it using cp -f to make upgrades a bit
simpler.

Scott, this is on Ubuntu 10.04.2 LTS. So you had no problems if you
deleted the binary first? I guess what concerned me was that after
replacing the binary (with cp -f), I could no longer find an open
filehandle with lsof. I didn't know if that meant anything. But like I
said, the daemon appeared to continue running fine (as far as I could
tell anyway).

tmountain, the link you posted is for FreeBSD. Do you know if the same
is true on Linux?

Richard, are you saying cp -f is safe then? Basically what I want to
do is overwrite all the binaries through an automated process, then
restart the daemons a few minutes later via a manual process (so I can
watch logs, etc.).

- Mike

Richard Kreuter

unread,
May 5, 2011, 1:15:12 PM5/5/11
to mongod...@googlegroups.com
Michael,

"cp -f" will produce a new file with an existing file's name, which is a
distinct thing from overwriting an existing file; and something like
that is probably what you want to do.

Reply all
Reply to author
Forward
0 new messages