Bogus I-Cap System V-like init script

Bug #886695 reported by Philippe Vialle
8
This bug affects 1 person
Affects Status Importance Assigned to Milestone
c-icap (Ubuntu)
Fix Released
Undecided
Unassigned

Bug Description

Hi all,

I've noticed several problems after having installed c-icap on a fully-patched Ubuntu 11.04 (Proxy squid3, c-icap service, ClamAV-Daemon, and SquidClamav as a redirector). I've tried the c-icap package provided by Ubuntu, and the c-icap that I compiled from source: both seem to show the same behavior.

First: the command service c-icap start was not sometimes terminated properly since the "dot" at the end wasn't being displayed in the terminal. One could tell something was going wrong for there was unexpected icap errors while using the HTTP proxy).
Furthermore, the "service start" command, most of the time, returns an error:
root@proxy-ubuntu:/# service c-icap start
Starting c-icap: ERROR.

Whereas the c-icap's processes do run in memory:

root@proxy-ubuntu:/# ps aux |grep icap |grep -v grep
root 16772 0.0 0.1 2516 676 pts/1 S 23:14 0:00 /usr/local/bin/c-icap -d 2
root 16773 0.0 0.0 92684 416 pts/1 Sl 23:14 0:00 /usr/local/bin/c-icap -d 2
root 16774 0.0 0.0 92684 416 pts/1 Sl 23:14 0:00 /usr/local/bin/c-icap -d 2
root 16775 0.0 0.0 92684 416 pts/1 Sl 23:14 0:00 /usr/local/bin/c-icap -d 2

And the ICAP service is indeed working at this time.

The thing is, looking closer at the System V-like script execution, it seems that the error comes from the line:
[ ! -f "$PIDFILE" ] && return 1
since the function apparently finishes its execution at this point.
Nonetheless, the PID file is present in /var/run/c-icap at the end.

BTW, if you start the service, whatever the output is, and then start it a second time, there is no "already running" message, but nothing...
root@proxy-ubuntu:/# service c-icap start
Starting c-icap: ERROR.
root@proxy-ubuntu:/# service c-icap start
Starting c-icap: root@proxy-ubuntu:/#

Note the truncated end of the script output.

AFAIU this is quite abnormal.
Many thanks.
Cheers,

PS:
/usr/local/bin/c-icap -f /etc/c-icap/c-icap.conf &
then
killall c-icap
work like a charm :(

description: updated
summary: - Bogus I-Cap service System V-like script
+ Bogus I-Cap System V-like init script
description: updated
description: updated
Revision history for this message
Philippe Vialle (philippe-vialle-l) wrote :

Guys,
Getting closer to the issue.
If I add prompts to see what's going on, let's say:

case "$1" in
  start)
        check_ctl_dir
        echo -n "Starting $DESC: "
        echo -n "DAEMON : $DAEMON\n"
        echo -n "DAEMON_OPTS : $DAEMON_OPTS\n"

        start-stop-daemon --start --quiet --pidfile $PIDFILE \
                --exec $DAEMON -- $DAEMON_OPTS
        if running ; then
            echo "$NAME."
        else
            echo " ERROR."
        fi
        ;;

And:

running()
{
# Check if the process is running looking at /proc
# (works for all users)

    # No pidfile, probably no daemon present
        echo -n "PIDFILE, $PIDFILE"
        ls /var/run/c-icap
    [ ! -f "$PIDFILE" ] && return 1
[...]

Here is the output (after having stopped the service):

root@proxy-ubuntu:/# service c-icap start
Starting c-icap: DAEMON : /usr/local/bin/c-icap
DAEMON_OPTS : -f /etc/c-icap/c-icap.conf -d 2
PIDFILE, /var/run/c-icap/c-icap.pid
c-icap.ctl
 ERROR.

As you can see, there is no ".pid" file in /var/run/c-icap!
I guess this is why the script terminates itself when checking the pid file.

Revision history for this message
Philippe Vialle (philippe-vialle-l) wrote :

Last!

I think I found it. Did not expect to find it like that.

The solution is as simple as adding a "sleep" before starting the "running" subfunction.
Here is the code:

 start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON -- $DAEMON_OPTS
        sleep 0.1
        if running ; then
            echo "$NAME."
        else
            echo " ERROR."
        fi
        ;;

This way, the start&stop do perfectly work. I guess the c-icap daemon needs a lil bit of time before it creates the pid file.

May I suggest you guys add this little fix into the next patch?

Cheers,

Revision history for this message
Mathieu Parent (math-parent) wrote :

I have completly rewritten the init script. I'mclosing this, feel free to reopen if this is still present in version >= 1:0.3.3-3.

Changed in c-icap (Ubuntu):
status: New → Fix Released
Revision history for this message
Philippe Vialle (philippe-vialle-l) wrote : Re: [Bug 886695] Re: Bogus I-Cap System V-like init script

Hi,
thanks a lot for the follow-up!
After a so long time, I was not sure to get a fix some day... but thanks
again!
I will try to test it in production ASAP, and will get back to you guys if
issue still happens.
Cheers,

2014-06-20 15:05 GMT+02:00 Mathieu Parent <email address hidden>:

> I have completly rewritten the init script. I'mclosing this, feel free
> to reopen if this is still present in version >= 1:0.3.3-3.
>
> ** Changed in: c-icap (Ubuntu)
> Status: New => Fix Released
>
> --
> You received this bug notification because you are subscribed to the bug
> report.
> https://bugs.launchpad.net/bugs/886695
>
> Title:
> Bogus I-Cap System V-like init script
>
> Status in “c-icap” package in Ubuntu:
> Fix Released
>
> Bug description:
> Hi all,
>
> I've noticed several problems after having installed c-icap on a
> fully-patched Ubuntu 11.04 (Proxy squid3, c-icap service, ClamAV-
> Daemon, and SquidClamav as a redirector). I've tried the c-icap
> package provided by Ubuntu, and the c-icap that I compiled from
> source: both seem to show the same behavior.
>
> First: the command service c-icap start was not sometimes terminated
> properly since the "dot" at the end wasn't being displayed in the terminal.
> One could tell something was going wrong for there was unexpected icap
> errors while using the HTTP proxy).
> Furthermore, the "service start" command, most of the time, returns an
> error:
> root@proxy-ubuntu:/# service c-icap start
> Starting c-icap: ERROR.
>
> Whereas the c-icap's processes do run in memory:
>
> root@proxy-ubuntu:/# ps aux |grep icap |grep -v grep
> root 16772 0.0 0.1 2516 676 pts/1 S 23:14 0:00
> /usr/local/bin/c-icap -d 2
> root 16773 0.0 0.0 92684 416 pts/1 Sl 23:14 0:00
> /usr/local/bin/c-icap -d 2
> root 16774 0.0 0.0 92684 416 pts/1 Sl 23:14 0:00
> /usr/local/bin/c-icap -d 2
> root 16775 0.0 0.0 92684 416 pts/1 Sl 23:14 0:00
> /usr/local/bin/c-icap -d 2
>
> And the ICAP service is indeed working at this time.
>
> The thing is, looking closer at the System V-like script execution, it
> seems that the error comes from the line:
> [ ! -f "$PIDFILE" ] && return 1
> since the function apparently finishes its execution at this point.
> Nonetheless, the PID file is present in /var/run/c-icap at the end.
>
> BTW, if you start the service, whatever the output is, and then start it
> a second time, there is no "already running" message, but nothing...
> root@proxy-ubuntu:/# service c-icap start
> Starting c-icap: ERROR.
> root@proxy-ubuntu:/# service c-icap start
> Starting c-icap: root@proxy-ubuntu:/#
>
> Note the truncated end of the script output.
>
> AFAIU this is quite abnormal.
> Many thanks.
> Cheers,
>
> PS:
> /usr/local/bin/c-icap -f /etc/c-icap/c-icap.conf &
> then
> killall c-icap
> work like a charm :(
>
> To manage notifications about this bug go to:
> https://bugs.launchpad.net/ubuntu/+source/c-icap/+bug/886695/+subscriptions
>

--
Philippe Vialle

Revision history for this message
Mathieu Parent (math-parent) wrote :

Note that I'm the Debian maintainer, and I'm not using Ubuntu. I came here by chance ;-).

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.