anacron dead but subsys locked

Eric

Verified User
Joined
Mar 25, 2004
Messages
116
Although the server is always on, I'd still like to get anacron to work.
Code:
bash-2.05# service anacron status
anacron dead but subsys locked

bash-2.05# service anacron stop
bash-2.05# service anacron start
Starting anacron:     [ OK ]
bash-2.05# service anacron status
anacron dead but subsys locked

bash-2.05# rm -f /var/lock/subsys/anacron
bash-2.05# service anacron start
Starting anacron:     [ OK ]
bash-2.05# service anacron status
anacron dead but subsys locked
What else should I do?


Thanks
Eric
 
Looks like it's not loading up correctly. It starts then dies and doesn't stop correctly. Check the logs /var/log/messages or wherever the logs for anacron are stored.

John
 
I can't find any error messages in the log files :(

Code:
bash-2.05#  service anacron start
Starting anacron:     [  OK  ]
bash-2.05#  service anacron status
anacron dead but subsys locked
bash-2.05#  grep 'anacron' /var/log/cron
Apr 13 21:38:14 220946 anacron[3923]: Anacron 2.3 started on 2004-04-13
Apr 13 21:38:14 220946 anacron[3923]: Normal exit (0 jobs run)
bash-2.05#  grep 'anacron' /var/log/messages
Apr 13 21:38:14 220946 anacron: anacron startup succeeded
 
Hello,

Not too sure, but "man anacron" mentioned this:
Unless the -d option is given (see below), Anacron forks to the background when it starts, and the
parent process exits immediately.
Not sure if that applies, but you can give it a shot (add/remove -d .. have a look in /etc/init.d/anacron to see whats currently there)

Or just run:
anacron

and/or

anacron -d

and see what happens

John
 
anacron -d runs fine, it returns
...... is running when I service anacron status

if the parent process exits immediately, the child becomes a zombie, no? so it is supposed to say "anacron dead but subsys locked" when people do service anacron status?

I'm gonna need some help here... people who read this post, can you tell me what returns to the console when you do service anacron status (assuming it's installed & running)


Thanks
Eric
 
Hello,

if the parent process exits immediately, the child becomes a zombie, no?
It would if they did it wrong. Normally they'd run setsid() which tells the child process to become the session leader, menaning it's now all grown up and no longer has a parent, so it's not a zombie :)

The "anacron dead but subsys locked" happens when the boot script creates the lock file in /var/lock/subsys/programname (or something similar) but the program never actually makes it to being run. So the anacron program is quitting right after it starts, but the boot script doesn't know that so it leaves lock file there. When you run status, the boot script is all confused because the lock file is there (to make sure it doesn't start another copy of the program) BUT the program isn't running.

So what needs to be done is to find out why the anacron program is exiting right after it starts.

My anacron boot script uses:
Code:
start() {
    echo -n $"Starting $prog: "
    daemon anacron
    RETVAL=$?
    [ $RETVAL -eq 0 ] && touch /var/lock/subsys/anacron
    echo
    return $RETVAL
}
to start it up (part of the /etc/init.d/anacron file)... so make sure yours contains that bit and check the last few lines of the /var/log/messages file right after you try to restart it.

John
 
Still the same...
Code:
#!/bin/sh
# Startup script for anacron
#
# chkconfig: 2345 95 05
# description: Run cron jobs that were left out due to downtime

# Source function library.
. /etc/rc.d/init.d/functions

[ -f /usr/sbin/anacron ] || exit 0

prog="anacron"

start() {
    echo -n $"Starting $prog: "
    daemon anacron
    RETVAL=$?
    [ $RETVAL -eq 0 ] && touch /var/lock/subsys/anacron
    echo
    return $RETVAL
}

stop() {
    if test "x`pidof anacron`" != x; then
        echo -n $"Stopping $prog: "
        killproc anacron
        echo
    fi
    RETVAL=$?
    [ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/anacron
    return $RETVAL
}

case "$1" in
        start)
            start
            ;;

        stop)
            stop
            ;;

        status)
            status anacron
            ;;
        restart)
            stop
            start
            ;;
        condrestart)
            if test "x`pidof anacron`" != x; then
                stop
                start
            fi
            ;;

        *)
            echo $"Usage: $0 {start|stop|restart|condrestart|status}"
            exit 1

esac

exit 0

Code:
bash-2.05#  service anacron start
Starting anacron:     [ OK ]
bash-2.05#  service anacron status
anacron dead but subsys locked
bash-2.05#  grep 'anacron' /var/log/messages
Apr 15 15:35:52 220946 anacron: anacron startup succeeded
bash-2.05#  grep 'anacron' /var/log/cron
Apr 15 15:35:52 220946 anacron[27685]: Anacron 2.3 started on 2004-04-15
Apr 15 15:35:52 220946 anacron[27685]: Normal exit (0 jobs run)
Normal exit = dead but subsys locked?
 
Oh :) I get that too .. I should have checked my own copy.

I think the anacron program run via cron (I might be wrong on that), but I'm getting the same results as you. So it's not actually a daemon, but gets run by the cron daemon instead.


John
 
In /etc/rc.d/init.d/functions

It returns "dead but subsys locked" instead of "is running" because anacron exits immediately (without removing the lock file) after it's started if there are no jobs to run... Is it supposed to do this? anacron is a standard program in Linux; does that mean this happens to all of us who use Linux?
Code:
status() {
     local base=${1##*/}
     local pid

     # Test syntax.
     if [ "$#" = 0 ] ; then
          echo $"Usage: status {program}"
          return 1
     fi

     # First try "pidof"
     pid=`pidof -o $$ -o $PPID -o %PPID -x $1 || \
          pidof -o $$ -o $PPID -o %PPID -x ${base}`
     if [ -n "$pid" ]; then
             echo $"${base} (pid $pid) is running..."
             return 0
     fi

     # Next try "/var/run/*.pid" files
     if [ -f /var/run/${base}.pid ] ; then
             read pid < /var/run/${base}.pid
             if [ -n "$pid" ]; then
                     echo $"${base} dead but pid file exists"
                     return 1
             fi
     fi
     # See if /var/lock/subsys/${base} exists
     if [ -f /var/lock/subsys/${base} ]; then
          echo $"${base} dead but subsys locked"
          return 2
     fi
     echo $"${base} is stopped"
     return 3
}
 
So it's a bug, or it's just supposed to do that?

DirectAdmin Support said:
Oh :) I get that too .. I should have checked my own copy.

I think the anacron program run via cron (I might be wrong on that), but I'm getting the same results as you. So it's not actually a daemon, but gets run by the cron daemon instead.


John
 
Same conclusion as I came up with :cool:
So I guess there's no fix for this...

Eric said:
In /etc/rc.d/init.d/functions

It returns "dead but subsys locked" instead of "is running" because anacron exits immediately (without removing the lock file) after it's started if there are no jobs to run.
Code:
status() {
     local base=${1##*/}
     local pid

     # Test syntax.
     if [ "$#" = 0 ] ; then
          echo $"Usage: status {program}"
          return 1
     fi

     # First try "pidof"
     pid=`pidof -o $$ -o $PPID -o %PPID -x $1 || \
          pidof -o $$ -o $PPID -o %PPID -x ${base}`
     if [ -n "$pid" ]; then
             echo $"${base} (pid $pid) is running..."
             return 0
     fi

     # Next try "/var/run/*.pid" files
     if [ -f /var/run/${base}.pid ] ; then
             read pid < /var/run/${base}.pid
             if [ -n "$pid" ]; then
                     echo $"${base} dead but pid file exists"
                     return 1
             fi
     fi
     # See if /var/lock/subsys/${base} exists
     if [ -f /var/lock/subsys/${base} ]; then
          echo $"${base} dead but subsys locked"
          return 2
     fi
     echo $"${base} is stopped"
     return 3
}
 
Back
Top