Welcome to the Linux Foundation Forum!

Schedule process while shutdown & Restart

Dear All,

Greetings to All,

I have a doubt in scheduling job while restarting and shutdowning in RHEL 5. Can any help me to do this?

Regards,

Karthikeyan.N

Comments

  • atreyu
    atreyu Posts: 216
    gnkarthikeyann wrote:
    Dear All,

    Greetings to All,

    I have a doubt in scheduling job while restarting and shutdowning in RHEL 5. Can any help me to do this?

    Regards,

    Karthikeyan.N

    I'm sure someone here can help - can you go into more detail about what your prob is? Are you trying to schedule shutdowns/restarts, or are you scheduling some other job that is conflicting with shutdowns/restarts, or something else?
  • hi,

    I am trying to schedule a job while shutdown/restart in RHEL 5.
  • atreyu
    atreyu Posts: 216
    gnkarthikeyann wrote:
    hi,

    I am trying to schedule a job while shutdown/restart in RHEL 5.

    Okay, try this for starters. Create a test script, i'll call it "job", that takes "stop" as an argument, and put it in /etc/rc.d/init.d/ (or /etc/init.d/). Have it do something simple, like write something to a log: e.g.
    #!/bin/sh
    stop(){
      echo $0 > /tmp/job.log
    }
    case $1 in
      stop)
        stop
        ;;
        *)
    esac
    exit 0
    

    Make it executable:
    chmod 0755 /etc/rc.d/init.d/job
    

    Make a "kill" symlink for it in /etc/rc.d/rc6.d:
    ln -s /etc/rc.d/init.d/job /etc/rc.d/rc6.d/K99job
    

    the "K" in the beginning of the link name indicates that the script will be called with the "stop" arg when the system reboots/halts. The number after the K is the order in which it will get executed (1 = first, 99 = last).

    IMPORTANT: there must be a file (can be empty) in /var/lock/subsys with the same name as your init script (job). so before testing, do this:
    touch /var/lock/subsys/job
    
    Ideally, this file should get created when your job first gets started. Or if there is no such job already running, you can put this in /etc/rc.d/rc.local, and will get created every time the system comes up.
  • bataspur
    bataspur Posts: 2
    Awesome, this is solid help.

    Thanks!

Categories

Upcoming Training