0

Something wrong with one service on FreeBSD 7.3:

1) it starts with command "service my_secret_service start" but later if I enter "service my_secret_service status" - it shows as not running. But in processes it exists (ps auwx | grep secret_service) with all threads (python threads) and I can see that it's working because of service logs, access to webui of service, etc.

2) If I type "service my_secret_service stop", it can't kill main process and all threads.

My secret rc script:

#!/bin/sh                                                                                                                                                                                                   

# PROVIDE: sbdns_daemon

. /etc/rc.subr

CONFROOT=/usr/local/secret_group/secret_service/etc
export CONFROOT

name=secret_service_daemon
rcvar=`set_rcvar`
pidfile="/var/run/secret_service/${name}.pid"
logfile="${CONFROOT}/log.conf"

command_interpreter=/usr/bin/python
command="full path to python service file"
command_args="--logconf ${logfile} -d "
stop_postcmd="${name}_post_stop"

secret_service_daemon_post_stop()
{
    n=0 
    until [ $n -ge 3 ] 
    do  
        child_processes=$(check_alive_processes)
        if [ -z "$child_processes" ]
        then
            echo "All child processes were shutdown gracefully!"
            exit 0
        else
            if [ $n = 0 ] 
            then
                echo "Processes are still alive. Waiting for them to shutdown gracefully..."
            fi  
            n=$(($n+1))
            echo "Attempt $n/3, alive processes: $child_processes"
            sleep 5
        fi  
    done
    echo "Not all processes were terminated! Forcibly terminating child processes: $child_processes!"
    pkill -if "${command}"
}
check_alive_processes()
{
    echo "$(pgrep -if -d " " "${command}")"
}

chmod +x $command
load_rc_config "$name"

secret_service_daemon_enable=${secret_service_enable-NO}

echo "Enabled: ${secret_service_daemon_enable}"

run_rc_command "$1"

What's wrong?

Update #1. Looks like problem was just in path to pidfile, very interesting. Thank you!

1 Answer 1

3

When you use the service command in will look for the process id (pid) as it was set when it was started. Your service has it defined as:

pidfile="/var/run/secret_service/${name}.pid"

When you ask for status the pid will be fetched from this file and it will check if the process is running.

If you examine the output of ps I am pretty sure that you will find that the process id of your running service does not match what is in the pidfile.

Your rc script does look a little suspect. Are you sure you want "secret_service" in the pidfile path? If so make sure it is there.

It would be more common with:

pidfile="/var/run/${name}.pid"

See Practical rc.d scripting in BSD

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .