Announcement

Collapse
No announcement yet.

Will this shutdown script work in Kubuntu?

Collapse
This topic is closed.
X
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Will this shutdown script work in Kubuntu?

    Hi All,

    I wrote a script to run first thing at shutdown over on CentOS 5.3. I use it to shutdown headless virtual machines. Will this modified version work in Kubuntu?

    The big thing I have to double check is in Red Hat, you must:
    Code:
      lockfile=/var/lock/subsys/a-local-shutdown
      touch $lockfile
    Or it won't shutdown. Is this the same in Kubuntu?

    And, is "/bin/logger" used the same way?

    -T

    My Modified script:

    Code:
    #!/bin/sh
    # /etc/init.d/a-local-shutdown
    #
    # Similar to rc.local only run at shutdown (rc0/1/6.d)
    #
    # lockfile: /var/lock/subsys/a-local-shutdown
    #
    # Note: Red Hat checks for a lock file for your script in
    #    /var/lock/subsys/<scriptname> or it won't run your
    #    K* scripts. You will find a "touch" command below under "start
    #    to take care of this
    #
    #
    #    list with rdX.d's with
    #      find /etc -iname \*a-local-shutdown\* -print  or
    #      find /etc -iname \*a-local-shutdown\* -exec ls -al {} \;
    #
    #
    #########################################################################
    # >> Do not place any custom code until the comment bar says you can << #
    #########################################################################
    
    echo -n $"Starting local-shutdown: "; echo
    
    # Make sure rc.local.shutdown link exists:
    if [ ! -h /etc/rc.shutdown ]; then
      ln -s /etc/init.d/a-local-shutdown /etc/rc.shutdown
    fi
    
    
    # Take care of start house keeping
    if [ "$1" = "start" ]; then
      lockfile=/var/lock/subsys/a-local-shutdown
      touch $lockfile
      /bin/logger -p user.notice -t a-local-shutdown " rc.shutdown touched $lockfile"
      exit 0
    fi
    
    
    # Show links rcX.d/KXXa-local-shutdown etc.
    if [ "$1" = "showlinks" ]; then
      find /etc -iname \*a-local-shutdown\* -exec ls -al {} \; 
      ls -al /etc/rc.shutdown
      exit 0
    fi
    
    
    # Make sure this script was called correctly
    if [ "$1" != "stop" ]; then
      echo $"Usage: $0 {start|stop|showlinks}"
      exit 2
    fi
    
    # Make a note in /var/log/messages that this script has been called:
    /bin/logger -p user.notice -t local-shutdown " rc.local.shutdown has been invoked"
    
    
    ###################################################
    # >>>> Place your custom code below this line <<<<#
    ###################################################
    
    
    
    
    
    exit 0

    #2
    [Solved] Re: Will this shutdown script work in Kubuntu?

    Figured it out. Ubuntu does not use the lock file and "/bin/logger" has been moved to "/usr/bin/logger". To use my script your can either reboot or run as root "/etc/init.d/a-local-shutdown". Set up the run levels with "sysvconfig" (the run levels are show in the scripts comments).

    -T

    Code:
    #!/bin/sh
    # /etc/init.d/a-local-shutdown
    #
    # Similar to rc.local only run at shutdown (rc0/1/6.d)
    # rc0/1/6.d:  K00
    # rc2/3/4/5.d: S99
    #
    # File permissions:
    # #ls -al a-local-shutdown
    #  -rwxr-xr-x 1 root root 1877 2009-09-27 17:23 a-local-shutdown
    #
    # lockfile: <there is none under Ubuntu, only under Red Hat>
    #
    #    list with rdX.d's with
    #      find /etc -iname \*a-local-shutdown\* -print  or
    #      find /etc -iname \*a-local-shutdown\* -exec ls -al {} \;
    #
    #
    #########################################################################
    # >> Do not place any custom code until the comment bar says you can << #
    #########################################################################
    
    echo -n $"Starting local-shutdown: "; echo
    
    # Make sure rc.local.shutdown link exists:
    if [ ! -h /etc/rc.shutdown ]; then
      ln -s /etc/init.d/a-local-shutdown /etc/rc.shutdown
    fi
    
    
    # Take care of start house keeping
    if [ "$1" = "start" ]; then
      exit 0
    fi
    
    
    # Show links rcX.d/KXXa-local-shutdown etc.
    if [ "$1" = "showlinks" ]; then
      find /etc -iname \*a-local-shutdown\* -exec ls -al {} \; 
      ls -al /etc/rc.shutdown
      exit 0
    fi
    
    
    # Make sure this script was called correctly
    if [ "$1" != "stop" ]; then
      echo $"Usage: $0 {start|stop|showlinks}"
      exit 2
    fi
    
    # Make a note in /var/log/messages that this script has been called:
    /usr/bin/logger -p user.notice -t local-shutdown " rc.local.shutdown has been invoked"
    
    
    ###################################################
    # >>>> Place your custom code below this line <<<<#
    ###################################################
    
    
    echo "Sleeping for 5 seconds"
    sleep 5
    
    
    
    exit 0

    Comment

    Working...
    X