Slashdot Mirror


Preventing Shutdown on Active NFS Servers?

Ed Almos asks: "Like many Slashdot Readers, I run a small network at home with a server and a number of desktops. The server holds all our files as NFS shares and doubles as a desktop machine should the need arise. Problems however occur if the server is shut down whilst there are NFS shares in use, the minimum disruption is a crashed desktop and a couple of times I have had to deal with corrupted files. Does anyone know of a way to prevent shutdown of a machine if someone else has drives mounted to its NFS shares ? I have already explored use of the /etc/shutdown.allow file but all this does is determine who can kill the machine. The minimal solution would be something similar to a Microsoft Windows system, where a request to shutdown brings up a warning window that there are users connected to the system, but I am not sure how to achieve this on a Linux system. Ideally I would like to prevent shutdown of a system with active NFS shares altogether, or at least until the user has unmounted and logged off the network."

66 comments

  1. Can't do it by djmitche · · Score: 4, Insightful

    NFS is stateless from the server's perspective. This is done so that the server doesn't have to track the state of a whole fleet of clients (and so that the server can pick up where it left off when it crashes and restarts).

    So the server, by design, has no notion of the number / names of users connected to it.

    The best you could do would probably be to monitor NFS traffic, and present a dialog on shutdown if there has been any traffic in the last 5 minutes or so.

    1. Re:Can't do it by Anonymous Coward · · Score: 1, Informative

      NFS is not stateless. There are files in

      /var/lib/nfs

      /var/state/nfs
      which specificly tell IP addresses and mountpoints of clients. If those files are deleted/modified while nfs is off, when nfs returns it won't know anything about the clients already connected, and their accesses will fail.

    2. Re:Can't do it by loony · · Score: 1

      >NFS is stateless from the server's perspective. This is done so that the server doesn't have to track the state of a whole fleet of clients (and so that the server can pick up where it left off when it crashes and restarts).

      Wrong - the nfsd is statless.. mounts, locks and stuff like that persists...

    3. Re:Can't do it by Paul+Jakma · · Score: 1

      NFS is stateless from the server's perspective. .... So the server, by design, has no notion of the number / names of users connected to it.

      NFS is indeed stateless, however the server does know of users "connected" to it via the mount RPC protocol which is stateful. Try 'showmount'.

      --
      I use Friend/Foe + mod-point modifiers as a karma/reputation system.
  2. But... by Trbmxfz · · Score: 3, Informative

    Not quite an answer to the article's question, but...

    Theoretically, once the NFS server has crashed, shouldn't all clients simply freeze until the server is back? On all systems I used, this was the observed behavior, and it is quite useful actually: it seems to avoid all data loss problems (under conditions). When the NFS gets reachable, all running program go on executing as if nothing had happened.

    A solution to the original problem, though, would be: tell all user that the NFS machine is to be powered on constantly.

    1. Re:But... by danbeck · · Score: 2, Informative

      This is only useful if the clients are never doing anything important. Try this on a huge cluster of webserver nodes with nfs mounts and you have one hell of a dead website. Remember kids, if you are going to go to bed with your nfs, bring along a few intrs for a safe, enjoyable time.

  3. low tech solution by ArmorFiend · · Score: 2, Interesting

    1) Put a big piece of tape/wood/whatever protecting the power switch on the NFS server, and disable software shutdown by non-root.
    2) Put your NFS server on the *best* machine, not the worst one, so that users want to use it first. If worst comes to worst, put signs on the other machines advertising the other's superiority. (and without the NFS overhead, it will really outperform its clients!)
    3) Put your NFS server on a g3 laptop or other ultra low power system, and hide the system in your closet so others can't find it to turn it off. (hardware suggestions, anyone?)
    4) switch to samba (heh heh heh)

    1. Re:low tech solution by Anonymous Coward · · Score: 0
      "Oh Bwunhiwda, you'we so wuvwy.."
      "Yes I know it, I can't help it..."
  4. You've got something wrong... by Whip · · Score: 4, Informative

    If your NFS server rebooting, shutting down, or crashing causes any problem but temporarilly 'hung' clients, you have something wrong.

    NFS is explicitly designed to be stateless, precisely to allow it to function across server reboots, crashes, and other fun. If your clients are crashing, or getting back corrupted data, something is screwed up somewhere.

    And, by the way, if you're getting corrupted data on a server crash, and the server is linux, you just had an object lesson on why it's bad that linux NFS defaults to async writes. :)

    1. Re:You've got something wrong... by prefect42 · · Score: 1

      That would be a good point, if it wasn't horribly out of date:

      "In releases of nfs-utils upto and including 1.0.0, this option was the default. In this and future releases, sync is the default, and async must be explicit requested if needed."

      From the rpm changelog:

      "* Mon Jul 22 2002 Bob Matthews bmatthews@redhat.com>

      - Move to nfs-utils-1.0.1"

      'nuff said.

      --

      jh

  5. May be wrong... by bored_SuSE_user · · Score: 1

    I know when I am shutting down my computer from a command prompt, it pops up saying the computer is being shut down in KDE. Obviously I know this because it's my computer, but don't you get a similar message when you shutdown your server? I am sure you can delay the shutdown for 30 seconds or so to allow users to unmount. I remember at our university, the 'server' when down on our solaris machines, and everything froze, but then re-started again in a couple of minutes, without problems. People booted into Windows got blue screens....

    --
    Bored? http://www.dodgybloke.co.uk
    1. Re:May be wrong... by Alizarin+Erythrosin · · Score: 1

      Maybe there's a way to send one of those "net send" messages to the network saying the server is going down for a reboot? Doesn't it say something like that when you do it on the console to all those logged in?

      --
      There are only 10 kinds of people in this world... those who understand binary and those who don't
  6. Try rwall or similar by ctr2sprt · · Score: 3, Informative
    There's a network-able version of wall that uses RPC (I think). It's not a foolproof solution, since it won't work if your users are logged in without an open terminal window, but it's a help. I'm sure it's terrifically insecure, but since you're running NFS you're already insecure (and so hopefully have a firewall).

    If that isn't good enough for you, there are a couple other possibilities. You could probably cobble together an utterly trivial Python (or Perl or whatever) script on your client machines, then have the server invoke it via ssh when a shutdown starts. If you aren't a programmer at all, you could try firing off an email to the client machines. As long as you have a periodic mail-checker going, it would alert you to the arrival of a new message. (Since you'd be able to use the local spool, you could have it check every 15 seconds.)

  7. Replace /sbin/shutdown with a wrapper script... by knife_in_winter · · Score: 2, Interesting

    If I understand you correctly, it sounds like you just want to replace shutdown with a wrapper script.

    a) Move /sbin/shutdown to something like /sbin/shutdown.real.

    b) Write a shell script called /sbin/shutdown that checks for your NFS mounts before invoking shutdown.real.

    If you want to make it really fancy, you can do something like calling and parsing the output of 'df', comparing that to the contents of /etc/fstab...or just compare /etc/mtab to /etc/fstab. Whatever....just look to see that your have NFS mounts. If you do, don't shutdown; if you don't, go ahead and shutdown.

    Is that what you want? If that *is* what you want, make sure you backup your wrapper and be aware that the next time you upgrade your base system, the wrapper will get blown away. Also make sure your wrapper script is passing all command options to the real shutdown.

    --

    Tyler's words coming out of my mouth.
    1. Re:Replace /sbin/shutdown with a wrapper script... by knife_in_winter · · Score: 1

      Doh!

      I just read a post below mine and realized I *completely* misunderstood the question.

      Nevermind!

      --

      Tyler's words coming out of my mouth.
  8. use correct mount options by stevef · · Score: 5, Interesting

    If you use the correct mount options you should not have to worry about corruption when the nfs server goes away.

    The options you want (for filesystems mounted rw) are:

    rw,hard,nointr...

    A lot of people don't like these options because it means that the clients will hang until the server returns, but it is THE RIGHT THING TO DO if you are mounting important data rw. If you can't stand for your clients to hang, maybe replace 'nointr' with 'intr', but you've been warned.

    Steve

    1. Re:use correct mount options by mcSey921 · · Score: 1, Redundant

      The parent has the correct answer.

      rw,hard,nointr

      Those are the correct options for a read-write NFS drive that will freeze the clients until the server has been restarted. After restart the clients continue as if nothing has happened.

    2. Re:use correct mount options by richie2000 · · Score: 1
      That's what I have, however sometimes when the server's been down and back up again, the clients get a "Stale NFS handle" error trying to access the mounted volumes. umount/mount fixes it, but what causes it in the first place? Kernel 2.4.22, Gentoo.

      Hey, this IS an Ask Slashdot, right? :-)

      --
      Money for nothing, pix for free
    3. Re:use correct mount options by jmauro · · Score: 1

      NFS doesn't use full path names but compressed unique ID called cookies for each file. And it usually generates these cookies as the files are being accessed You'll get a "stale nfs handle" when the machine reboots, the old cookie (kept by the client) is now no longer known to the server. Remounting fixes it because the client will ask for new cookies starting at the file system root and forget all the old cookies.

    4. Re:use correct mount options by richie2000 · · Score: 1
      Ah. And as the file system (Reiser3, in this case) assigns an inode to directories (ie making it a file in some technical meaning), that's why I get the Stale NFS Handle message even when I just try to ls /nfs-mounted-dir/ on the client? Makes some kind of sense...

      But doesn't this cookie system sorta break the statelessness of the NFS server, at least in spirit? What's the reason for doing it this way instead of having the client ask for full path names? Can this behaviour be turned off somehow? Having the client automatically ask for a new cookie when it receives this error message would seem like a good idea...?

      --
      Money for nothing, pix for free
    5. Re:use correct mount options by buysse · · Score: 1
      No, what's breaking statelessness is that Reiser doesn't really use inodes and is not a very good choice for a NFS server. Sadly, as it's a beautiful file system. IIRC, ReiserFS generates inode numbers on the fly -- directories in a traditional Un*x filesystem have inode numbers, because they are just files. Ext3, XFS, JFS - all better choices for a NFS server.

      Sorry, dude.

      --
      -30-
  9. maybe... by Froze · · Score: 3, Interesting

    use lsof to monitor tcp/udp/rcp sockets that are open on the host and pointing at the file space that nfs is serving.

    Then write a wrapper around each of halt, shutdown, and reboot to check the open ports and fail if they are active.

    Seems fairly hackish, but... whaddya expect from /.?

    --
    -- The morphemes of your disquisition are ascertainable, but they have eschewed an ambit of transpicuous exposition.
  10. NFS Locking Service might work? by stefanlasiewski · · Score: 4, Interesting

    I can't remember the details on this, but would the NCF Locking Services work for you?

    NFS input/output is stateless, but I believe the locking mechanism is stateful.

    When clients are accessing a file, a lock is established. When the client is done with the file, the lock is removed. You can see who has what resource locked with a utility (I forget which, but fcntl() and lockf() come to mind).

    In a shutdown script, look for locks, and refuse to procede until the locks are cleared.

    --
    "Can of worms? The can is open... the worms are everywhere."
    1. Re:NFS Locking Service might work? by stefanlasiewski · · Score: 1

      I can't remember the details on this, but would the NCF Locking Services work for you?

      Sorry, that's "NFS Locking Services"

      --
      "Can of worms? The can is open... the worms are everywhere."
  11. maybe i'm just stupid.. by gl4ss · · Score: 3, Insightful

    but wouldn't one key things to consider when building such a system be that a) it's down as little as possible and b) when it goes down it's well known beforehand(and the users can be told in advance that it will go down at time x and they're fsced if they don't get out before it).

    look, what point would there be in initiating the shutdown if you didn't know when the users will get out anyways? it could take hours/days before it would actually boot, and if that doesn't matter(waiting _hours_) then why would you be booting it in the first place? just out of habit?

    anyways.. it sounds a lot like you should be fixing on why you have to be booting it instead of how the booting occurs.. so that you wouldn't need to be booting it.

    --
    world was created 5 seconds before this post as it is.
  12. WARNING: FIRE HAZARD!!!!! by Anonymous Coward · · Score: 0

    hide the system in your closet so others can't find it to turn it off

    NEVER, EVER PUT A COMPUTER IN A CLOSET.

    As a pretty general rule of thumb, closets are made of wood, which is a polite way of saying kindling.

    NEVER, EVER RUN ELECTRONIC GEAR IN A WOOD CLOSET. EVER.

    1. Re:WARNING: FIRE HAZARD!!!!! by pediddle · · Score: 1

      As opposed to a wood desk or the rest of your house?

    2. Re:WARNING: FIRE HAZARD!!!!! by yuri+benjamin · · Score: 2, Funny

      So build a closet out of fire-retardant building materials. Try your local building supplies shop. Make sure there is adequate cooling/ventilation for the sake of your server.

      Heck, you could even build some kind of coolstore. A bit OTT but doable if you have the money.

      --
      You make the mistake of thinking you can educate the fundamental stupidity out of people. You can't.
    3. Re:WARNING: FIRE HAZARD!!!!! by Anonymous Coward · · Score: 0

      Closets are made of drywall, also known as sheetrock. Code requires walling material to be fire-resistant. (Of course it will burn. But it's not wood, and it's not kindling.)

      Besides, if you put your electronics in a poorly ventilated space and a small fire starts, it'll smolder and then die instead of flaring up.

    4. Re:WARNING: FIRE HAZARD!!!!! by unitron · · Score: 1
      "Closets are made of drywall, also known as sheetrock. Code requires walling material to be fire-resistant. (Of course it will burn. But it's not wood, and it's not kindling.)

      Besides, if you put your electronics in a poorly ventilated space and a small fire starts, it'll smolder and then die instead of flaring up."

      One of the reasons that drywall (gypsum board) is so heavy is that there's about a gallon of water in every 4 square feet so by the time you can get any more of it than the paper backing to burn the 2 x 4s it's nailed to will have been reduced to charcoal and ash. I wouldn't count on poor ventilation being able to snuff out a fire. Especially since that ventilation will probably still allow enough smoke to escape to attract someone's attention, at which point they'll probably go open said closet and get their eyebrows pretty well singed off when the inrushing air supply reaches the flame.

      --

      I see even classic Slashdot is now pretty much unusable on dial up anymore.

  13. Mod parent up by Emnar · · Score: 2, Informative

    I work for a major NAS storage company. Using the mount option "hard" is the right advice. It sounds like the submission author is using soft NFS mounts, which is a big no-no with rw mounts where you want any kind of data integrity.

    1. Re:Mod parent up by HalfFlat · · Score: 3, Interesting

      Back when I was administering a mixed Unix network, we used to say the two NFS mount options were 'hard' and 'corrupt'.

      I believe that it is theoretically possible to write software that can survive a soft mounted filesystem disappearing from under it, but no one ever does. How often do people check the return value from write()? And in memory mapped io land, it would be nasty.

  14. Implementation by Short+Circuit · · Score: 2, Interesting

    As a hack, you could replace /sbin/shutdown with a shell script that pops up a dialog (If $DISPLAY is set) or asks on the console.

    1. Re:Implementation by Glonoinha · · Score: 4, Insightful

      Even better thought, he could decide that there actually is a distinction between server duty and workstation duty and decide which this particular machine is going to pull. If he needs the machine to run as a workstation, quit trying to use an unstable environment as a server. If the files and stability of the system are of any importance whatsoever then it is a server, treat it as such and buy another computer to use as a workstation (they are dirt cheap now.) Pretty simple.

      Want to see your uptime and stability rise incredibly on the server? Put it in the closet on a UPS and once it is running turn off the monitor, unplug the keyboard, and tape a piece of cardboard over the power switch so it doesn't get turned off by accident. Where the machine used to sit put a cheap replacement computer to use as a workstation - even new entry level boxes are starting at under $500 fully loaded (a little wimpy, but including all the necessary parts including a monitor) and used hardware has gotten insanely cheap (ie $200 for a full machine that is a generation or two old, PIII .5 to 1GHz range with a CRT.)

      That said, I am going to read every post in this thread to get a better understanding of how to do this - now you have my interest up.

      --
      Glonoinha the MebiByte Slayer
  15. Yeah, but the client thinks it's stateful by bill_mcgonigle · · Score: 4, Informative

    put a program on each client machine, call it nfsmounts and it would go a little something like this:

    mount | grep $1 | wc -l

    then write a wrapper on the server that does

    foreach client (client list)
    mounted = ssh client nfsounts `hostname`
    ok = false if (mounted)
    end

    you can hook that into your shutdown script, and abort if there are any clients who think they have a mounted drive.

    of course, read the other suggestions about mount options. Noone's mentioned sync yet, but don't mount your shares async even though the performance is so much better or you'll loose data.

    --
    My God, it's Full of Source!
    OUTSIDE_IP=$(dig +short my.ip @outsideip.net)
    1. Re:Yeah, but the client thinks it's stateful by Anonymous Coward · · Score: 0

      Wouldn't it be simpler to have a file on the nfs mounted partition machines that keeps a count of machines connected to it?

      Put a simple script in your startup that reads the value in the file, increments it, then writes it back.

      Update your shutdown scripts to read the value in that file, decrement it, then write it back. On the nfs server, update the shutdown script to check that the value is 0.

      Ok, maybe not easier, but the shutdown process doesn't have to ssh to a number of machines before it completes.

    2. Re:Yeah, but the client thinks it's stateful by boneshintai · · Score: 1

      And if a machine dies (think "power failure" or "kernel panic") before decrementing the mounted count file? The grandparent's solution doesn't have that limitation, in exchange for a little processor time and a little bandwidth.

  16. Alternate solution by 0x0d0a · · Score: 2, Interesting

    I know that it's not quite what you wanted, but using Coda, which is designed to support disconnected operation (i.e. servers goes away for a while and then comes back) may be an appealing option for you.

  17. Couple suggestions.... by !3ren · · Score: 2, Informative

    First off, I would recommend that you never run applications on your file server. That just seems like tempting fate to me. Get a cheap old system from reseller/friend/garbage and use that.

    Second, use FTP instead of NFS. Allow it to support resume, only let it talk locally. I believe there are utils which will allow you to mount an FTP as a drive in windows as well...

    couple of ideas anyways.

    1. Re:Couple suggestions.... by Anonymous Coward · · Score: 0

      NFS and FTP are two completely different animals. Unless I missed the memo pointing out how you can mount a remote FTP server as a local share and then proceed to use it in a completely transparent fashion. I suppose one could do this via a loopback mechanism... except that performance would suck and you would lose out on the benefits of things like file locking. Not to mention the issues around permissions (both the chmod/chown settings, but the actual access controls as well).

  18. Re:WARNING tsarkon reports SLASHDOT TRACKS AC-IP-U by Anonymous Coward · · Score: 0

    > 4. Log back in and try to moderate your AC comment...
    > you can't!!!

    I just did.

    > Big brother is watching. So while I might be a "troll" a lot
    > of the AC things I said were to protect myself from Slash-
    > bot groupthink. They punished me for voicing my opinion
    > freestyle.

    It's an online forum. Go get some sun.

  19. NFS Automounter by Mike+Dahlgren · · Score: 2, Interesting

    Where I work they had this problem and someone implemented a automounter program that mounts the shares when they are needed and releases them as soon as they are not needed. Not a perfect solution but it works really well.

    1. Re:NFS Automounter by Anonymous Coward · · Score: 2, Insightful
      This comment is definitely on the right track. I've managed a number of sites which use NFS heavily on hundreds of systems, and it all comes down to effective use of the automounter.
      At larger sites, you also get some other great benefits, like being able to move filesystems transparently from one server to another without touching the clients, all by managing the automounter map.

      Most Unix and Linux variants have a standard automounter. Use it! This will lead to two possible scenarios when the fileserver goes down:

      Idle filesystems which have been unmounted.

      Active filesystems which remain mounted.

      You have to be clear about why filesystems are active in the second case. For example, clients which are running daemons or other always-on software should not be using NFS files, otherwise you've engineered yourself a brittle metasystem. Daemons should run out of the local filesystems only.

      User applications which write frequently to the home directory are another common source of filesystem dependency. The idea of a central home directory is architecturally excellent. Just don't abuse it. If an application really needs the NFS home directory, then it can wait until the server is back up. Otherwise, fix the application.

      Of course you already bring the server down gracefully, using

      shutdown
      rather than
      halt
      . You may want to add behavior to the shutdown script which sends an announcement to the clients using
      rwall
      , sends a remote command to the clients to shut down any specialized applications which are known to depend on shared files, puts up a confirmation prompt on the server, or the like.
  20. Message From Original Poster by Ed+Almos · · Score: 1

    No, you haven't got it wrong, this is EXACTLY what I am looking for. Some sort of wrapper around the shutdown command which looks for active NFS shares before shutting down the system.

    Ed

    --
    The more corrupt the state, the more numerous the laws. - Tacitus, 56-120 A.D.
    1. Re:Message From Original Poster by knife_in_winter · · Score: 1

      Oh, well, I am glad the wrapper idea helps you...but there is still the issue of actually recognizing the shares as being active, which is different from them just existing, which is all my idea helps with.

      --

      Tyler's words coming out of my mouth.
  21. rmtab by Bazman · · Score: 2, Interesting

    The file /var/lib/nfs/rmtab on the server keeps a list of what systems have mounted NFS drives. What you then do is this:

    1. When shutting down, first go through rmtab and send an rwall message to those machines, saying 'get the heck off because the server is going down shortly'

    2. Two minutes later try again and send a more forceful message.

    3. Two minutes later tell them they are about to get it in the neck. And shutdown.

    If you really dont want to shut the machine down with NFS mounted stuff still there, then modify to taste - dont shutdown unless rmtab doesn't have any shares from machines you dont want to annoy.

    This is untested of course.... Until you try it! Read the warnings about rmtab in man mountd. It may not be trustworthy.

    Baz

  22. Simple ... by forsetti · · Score: 0

    rm -f /usr/sbin/shutdown

    --
    10b||~10b -- aah, what a question!
    1. Re:Simple ... by Anonymous Coward · · Score: 0

      Silly person, that file doesn't exist.

      truffula:~# ls /usr/sbin/shutdown
      ls: /usr/sbin/shutdown: No such file or directory
      truffula:~# which shutdown
      /sbin/shutdown

  23. Solved a similar problem ... by Tux2000 · · Score: 2, Informative

    ... a long time ago. Basically, every user gets a simple switch, all switches are connected in parallel, so you get a "wired-or". All users are told: If you need the server, turn on that switch. If you don't need the server any more, switch it off again. A little piece of electronic connected to a RS232 port and a tiny C programm control the power supply for the server. Details (german only, sorry) are here.

    The trick is: The server now knows best when to start and to shutdown, there is no more need for manual boot or shutdown. If you replace the switches with a relay per workstation that closes the contact whenever the workstation is powered on, you don't even have to tell the users about the switch. You don't even need extra cables if you use 10/100 MBit/s ethernet, there are two unused wire pairs in every ethernet connection.

    OK, this is a hardware solution, not a nice popup window. But don't we all hate those nasty popups? ;-)

    Tux2000

    --
    Denken hilft.
  24. lsof ? by Cpt+Kirk · · Score: 1

    Couldnt you use lsof to get a list of open files and check if they are in mounted nfs shares ? If there are any when shutdown is called use a bit of scripting to pop up a dialog ? Just my 0.02

    --
    --- Did I say that ?
  25. Home network server by 1eyedhive · · Score: 2, Informative

    I use samba to share my files so i can't comment on NFS too much.

    Similar setup:
    one Linux file server, 3 desktops (mixed nix and win2k), when the server shuts down, any cients active go nuts (winamp freezes, explorer complains about the sudden disconnect)
    best theing to do, since you're on a home network is to make sure no one's using the damn thing before you shut it down.

    This is easy, even with 6 systems, (assuming samba), just make sure no programs are activly using the shares and reboot the box, the workstations will yelp in agony, until the server returns, then all's well.

    In windows, when a mounted (read: drive mapped) smb share goes off line, windows complains, programs too, then windows marks the drive as disconnected, when the server's back up, reconnectying by just clicking the drive in My Computer restores everything to normal. I haven't messed with client side SMB under nix enough to know what happens when a samba server reboots (gracefully or otherwise) while files are in use client side.

    --

    --
    Logistical Chaos Officer http://www.slagg.org - LAN Gaming in Sarasota FL,USA
  26. showmount anyone? by loony · · Score: 2, Informative

    showmount -a is your friend ... that will show you all clients that currently have a filesystem mounted... just move your shutdown, reboot or whatever out of the way, replace them by a wrapper script that checks if showmount -a returns any clients, and only executes the real shutdown when noone has the filesystems mounted... if they do you can always print out a list of workstations that have mounted filesystems...

    1. Re:showmount anyone? by Anonymous Coward · · Score: 0

      Showmount provides an approximation only, and not a very good one in my experience.

      Implementations vary, but in general it tracks explicit mount and unmount events, but not client shutdowns, for example. Experiment thoroughly before use.

  27. Best Solution by cherad · · Score: 1

    Does anyone know of a way to prevent shutdown of a machine if someone else has drives mounted to its NFS shares ?

    Put a sign on the server that reads "Do not shutdown this server". If you want a technical solution - use a post-it.

  28. Mod parent up by calidoscope · · Score: 1

    The parent posting is well worth reading.

    --
    A Shadeless room is a brighter room.
  29. Tsk Tsk by Networkpro · · Score: 1

    Define all of your enviros at the start of your script and you won't have that problem. {BTW Not everyone uses csh... it just reeks of being a Sunny)

    1. Re:Tsk Tsk by Short+Circuit · · Score: 1

      What makes you think I use csh? I use bash on Linux, tcsh on OS X

      Besides, checking to see if $DISPLAY is set tells you if the command was run from within an X display.

  30. NFS Locking is the cat's meow. by Kludge · · Score: 1

    I use nfs locking for everything. It's just as good as regular file locking.

    Try this:
    Create /nfsmount/.lockfile on the nfsdrive readable by everyone.
    After the clients mount the nfs drive, have them perform a read (non-exclusive) lock on /nfsmount/.lockfile & Put it in the background.
    (clientnfslock /nfsmount/.lockfile & )
    In the server shutdown script put in a routine that fails if it can not perform a write (exclusive) lock on that same file.
    (... servernfslock /nfsmount/.lockfile || exit; ...)

    Note that flock will not work across NFS, so you have to use fcntl. Of course you can do this in perl:

    servernfslock:
    #!/usr/bin/perl
    use Fcntl;
    $cinfile=$ARGV[0];
    open(TEMP,"+ $cinfile") || die "Couldn't open the file $cinfile\n";
    &lockfile(TEMP) || die " Could not lock file $cinfile\n";

    sub lockfile {
    $bub=$_[0];
    $lockz = pack('s s l l s', &F_WRLCK, 0, 0, 0, 0);
    $gg=fcntl($bub, &F_SETLK,$lockz ) || -1; # do a write lock

    return $gg;
    }

    and clientnfslock is the same except you use a F_RDLCK instead of a F_WRLCK, and you put a
    sleep
    at the end of the script so the script never dies and the file never closes and never becomes unlocked.

    The beauty is that this utilizes the very service of interest (nfs) and none other.

    Of course, don't run clientnfslock on your server, or it won't shut down :). If you have problems contact me: slashdotNFSlockdec03.12.cudgle@spamgourmet.com

  31. You can easily see who has it mounted by Anonymous Coward · · Score: 0

    That is what "showmount" does.
    Simply write a wrapper shutdown that runs
    showmount and lets you know who has it
    mounted.

  32. Re:WARNING tsarkon reports SLASHDOT TRACKS AC-IP-U by Anonymous Coward · · Score: 0
    It's an online forum. Go get some sun.
    It's a free country. Don't try to project your fragile self-esteem issues onto me. I will make you cry like you haven't since infanthood and then you will thank me for setting you straight.
  33. Re:WARNING tsarkon reports SLASHDOT TRACKS AC-IP-U by Anonymous Coward · · Score: 0

    People like you are a great example of why there should not be truely anonymous posting.

  34. Re:WARNING tsarkon reports SLASHDOT TRACKS AC-IP-U by Anonymous Coward · · Score: 0

    Oh THE POWERS THAT BE! You fascist Waffen Shutzstauffel Waffen SS Hitler's secret police. You just thought yourself judge jury and executioner. You said, you don't like someone for revealing a truth in you fascist machinations and you would rid EVERYONE'S RIGHTS TO SUPRESS YOUR POLITICAL ENEMIES. This is a legitimate justification for you death. I hope freedom fighters around the world target you and mark you for death.