Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
Init script doesn't capture pid
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Portage & Programming
View previous topic :: View next topic  
Author Message
audiodef
Watchman
Watchman


Joined: 06 Jul 2005
Posts: 6639
Location: The soundosphere

PostPosted: Fri Aug 16, 2013 3:17 pm    Post subject: Init script doesn't capture pid Reply with quote

I have the following init script. I need to modify it, and I'm not sure how. It is supposed to be used like net.lo - you make a symlink to it such as liquidsoap.main. The problem is, when I do that, it starts the first process and thereafter produces no error about new processes, but the new processes aren't actually started.

For example, /etc/init.d/liquidsoap.main start starts up and everything works as expected. If I then do /etc/init.d/liquidsoap.ambient start, I can see ambient.pid in /usr/local/var/run/liquidsoap, but there is no process other than liquidsoap.main found by ps aux | grep liquidsoap.

How should this script be changed to fix this?

/etc/init.d/liquidsoap:

Code:

#!/sbin/runscript

script=${RC_SVCNAME#*.}
scriptfile="/etc/liquidsoap/${script}.liq"
command=/usr/local/bin/liquidsoap
command_args="--daemon -t ${scriptfile}"
start_stop_daemon_args="--user liquidsoap:liquidsoap --nicelevel -15 "
pidfile="/usr/local/var/run/liquidsoap/${script}.pid"
name=${RC_SVCNAME}

description="Liquidsoap deamon that obeys ${scriptfile}"
extra_commands="check"
description_check="Check and evaluate stream scripts without interupting streaming."

depend() {
    need localmount
    use net
    after alsasound icecast
}

_script_exists() {
    if [ "${script}" = "${RC_SVCNAME}" ]; then
        eerror "You have to create an init script for each stream script:"
        eerror "ln -s liquidsoap /etc/init.d/liquidsoap.<script>"
        eerror "where script refers to /etc/liquidsoap/<script>.liq"
        return 1
    fi

    if [ ! -f "${scriptfile}" ]; then
        eerror "${scriptfile} not found"
        return 1
    fi
}

check() {
    _script_exists || return 1
    einfo "Checking ${scriptfile}"
    use net
    after alsasound icecast
}

_script_exists() {
    if [ "${script}" = "${RC_SVCNAME}" ]; then
        eerror "You have to create an init script for each stream script:"
        eerror "ln -s liquidsoap /etc/init.d/liquidsoap.<script>"
        eerror "where script refers to /etc/liquidsoap/<script>.liq"
        return 1
    fi

    if [ ! -f "${scriptfile}" ]; then
        eerror "${scriptfile} not found"
        return 1
    fi
}

check() {
    _script_exists || return 1
    einfo "Checking ${scriptfile}"
    check_result=`$command --check-lib ${scriptfile}`
    eend $? ${check_result}
    return $?
}

start_pre() {
    _script_exists || return 1
}

start() {
    start-stop-daemon --start  \
        ${start_stop_daemon_args} \
        --pidfile ${pidfile} \
        --exec ${command} \
        -- ${command_args}
}

_________________
decibel Linux: https://decibellinux.org
Github: https://github.com/Gentoo-Music-and-Audio-Technology
Facebook: https://www.facebook.com/decibellinux
Discord: https://discord.gg/73XV24dNPN
Back to top
View user's profile Send private message
Naib
Watchman
Watchman


Joined: 21 May 2004
Posts: 6051
Location: Removed by Neddy

PostPosted: Fri Aug 16, 2013 3:42 pm    Post subject: Reply with quote

sounds like it crashed.
_________________
Quote:
Removed by Chiitoo
Back to top
View user's profile Send private message
audiodef
Watchman
Watchman


Joined: 06 Jul 2005
Posts: 6639
Location: The soundosphere

PostPosted: Fri Aug 16, 2013 3:44 pm    Post subject: Reply with quote

All I can tell you is that it runs - reliably. But stop() and restart() claim there is no such process when in fact it is running (and working correctly), and the pidfile exists. That's why I'm thinking the script simply did not capture the pid. Is there something in this script that looks wrong?
_________________
decibel Linux: https://decibellinux.org
Github: https://github.com/Gentoo-Music-and-Audio-Technology
Facebook: https://www.facebook.com/decibellinux
Discord: https://discord.gg/73XV24dNPN
Back to top
View user's profile Send private message
Naib
Watchman
Watchman


Joined: 21 May 2004
Posts: 6051
Location: Removed by Neddy

PostPosted: Fri Aug 16, 2013 4:07 pm    Post subject: Reply with quote

Well that init script doesn't have a stop or check, so I guess it is inheriting.
The last time I ran into something like this it was downto a script launching the actual process so its PID isn't valid for the running process.

also this should be in programming
_________________
Quote:
Removed by Chiitoo
Back to top
View user's profile Send private message
audiodef
Watchman
Watchman


Joined: 06 Jul 2005
Posts: 6639
Location: The soundosphere

PostPosted: Fri Aug 16, 2013 4:20 pm    Post subject: Reply with quote

I'm afraid I'm not much of an expert with writing init scripts. Should I not inherit? If so, what would be the best way to write my own stop() and restart()? How does launching an actual process make the pid invalid for the running process? Isn't the actual process supposed to be launched?
_________________
decibel Linux: https://decibellinux.org
Github: https://github.com/Gentoo-Music-and-Audio-Technology
Facebook: https://www.facebook.com/decibellinux
Discord: https://discord.gg/73XV24dNPN
Back to top
View user's profile Send private message
Naib
Watchman
Watchman


Joined: 21 May 2004
Posts: 6051
Location: Removed by Neddy

PostPosted: Fri Aug 16, 2013 4:33 pm    Post subject: Reply with quote

looking in my init.d directory it looks like they all define their own stop method:

Quote:
stop() {
ebegin "Stopping Tor"
start-stop-daemon --stop --pidfile "${PIDFILE}" --exec /usr/bin/tor -- --PidFile "${PIDFILE}"
eend $?



I am only postulating whether the process you are launching is the actual process that does the work. Quite a few processes have a wrapper script/program that kind of prepares environments etc.
_________________
Quote:
Removed by Chiitoo
Back to top
View user's profile Send private message
audiodef
Watchman
Watchman


Joined: 06 Jul 2005
Posts: 6639
Location: The soundosphere

PostPosted: Fri Aug 16, 2013 4:49 pm    Post subject: Reply with quote

It is launching the actual process - no wrapper here.

Thank you! Adding a stop() to the script is exactly what I needed. Now the script simply works as expected. I appreciate this very much. This has been bugging me for a while now. :)

Just needed to add, at the end:

Code:

stop() {
ebegin "Stopping Liquidsoap..."
start-stop-daemon --stop --pidfile "${pidfile}" --exec ${command} -- --PidFile "${pidfile}"
eend $?
}

_________________
decibel Linux: https://decibellinux.org
Github: https://github.com/Gentoo-Music-and-Audio-Technology
Facebook: https://www.facebook.com/decibellinux
Discord: https://discord.gg/73XV24dNPN
Back to top
View user's profile Send private message
John R. Graham
Administrator
Administrator


Joined: 08 Mar 2005
Posts: 10587
Location: Somewhere over Atlanta, Georgia

PostPosted: Fri Aug 16, 2013 9:31 pm    Post subject: Reply with quote

Moved from Off the Wall to Portage & Programming. Seems to fit better here.

- John
_________________
I can confirm that I have received between 0 and 499 National Security Letters.
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Portage & Programming All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum