1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Privoxy won´t start

Discussion in 'Tomato Firmware' started by Prophet, Aug 15, 2012.

  1. Prophet

    Prophet Networkin' Nut Member

    Hey,

    Installed privoxy and it works fine. However I cannot get it to auto-start. At first I went into the webinterface and put "/opt/sbin/privoxy /opt/etc/privoxy/config" in scripts. This works from the cmd-line. But it doesnt start.
    So I created a script in /opt/etc/init.d which also works if I run it from the cli.

    #!/bin/sh

    prefix="/opt"
    PATH=${prefix}/bin:${prefix}/sbin:/sbin:/bin:/usr/sbin:/usr/bin:/opt/sbin
    NAME=privoxy
    DAEMON=${prefix}/sbin/${NAME}
    DAEMON_OPTS="/opt/etc/privoxy/config"

    test -x $DAEMON || exit 0

    if [ -z "$1" ] ; then
    case `echo "$0" | sed 's:^.*/\(.*\):\1:g'` in
    S??*) rc="start" ;;
    K??*) rc="stop" ;;
    *) rc="usage" ;;
    esac
    else
    rc="$1"
    fi

    case "$rc" in
    start)
    echo "Starting privoxy: $NAME"
    $DAEMON $DAEMON_OPTS
    ;;
    stop)
    if [ -n "`pidof $NAME`" ]; then
    echo "Stopping privoxy: $NAME"
    killall $NAME 2> /dev/null
    fi
    ;;
    restart)
    "$0" stop
    sleep 1
    "$0" start
    ;;
    *)
    echo "Usage: $0 (start|stop|restart|usage)"
    ;;
    esac

    exit 0

    This doesnt work either. So I started messing around with screen. It seems it cant find the configfile. Youstart privoxy by
    "/sbin/opt/privoxy /opt/etc/privoxy/config" and when I do "screen /sbin/opt/privoxy /opt/etc/privoxy/config" it says it cant find the file. Both files are there, I can run the command manually and /sbin/opt is not in the path. Not sure why that would matter since I write it manually.. butt...
     
  2. Dark_Shadow

    Dark_Shadow Addicted to LI Member

  3. Prophet

    Prophet Networkin' Nut Member

    I put the file : cat /opt/etc/config/privoxy-check.sh
    /opt/sbin/privoxy /opt/etc/privoxy/config


    Its +x. Doesnt start on boot.
     
  4. Dark_Shadow

    Dark_Shadow Addicted to LI Member

    .sh will not run on bootup. read the link i posted a little more closely, towards the bottom.
     
  5. Prophet

    Prophet Networkin' Nut Member

    Ah sorry yes you are right I didnt get the part about extensions. Anyway:
    . root@Wonderland:/tmp/home/root# ls /opt/etc/config/
    01-privoxy.wanup
    and still no go.
     
  6. koitsu

    koitsu Network Guru Member

    Your problem is this:

    Code:
    prefix="/opt"
    ...
    NAME=privoxy
    DAEMON=${prefix}/sbin/${NAME}
    DAEMON_OPTS="/opt/etc/privoxy/config"
    ...
    start)
    echo "Starting privoxy: $NAME"
    $DAEMON $DAEMON_OPTS
    
    Look very, very carefully at what $DAEMON gets expanded to, then compare that to what you said in this post:

    So is it /sbin/opt/privoxy or is it /opt/sbin/privoxy? I think it's the latter (which would mean your sh script is probably fine), but the inconsistency could explain the problem if the binary is truly in /sbin/opt.

    Furthermore, are you sure /opt is truly and immediately available after you reboot the router + init script stsart? I've found that /opt mounts are usually not available immediately (even if put in WAN Up section), especially if CIFS/SMB is in use. It takes some time (maybe 10-15 seconds, but it varies -- keep reading) before the system gets around to mounting it.

    The problem may be that your /opt filesystem is not available by the time the script runs automatically (hence "file not found"), but is obviously available by the time you telnet/SSH in. There is no way to solve this problem sanely; people who recommend using sleep N are not thinking about this problem correctly (N is not going to work for everyone, given different models of routers, network configurations, use/disuse of VLANs, etc.).

    I dealt with a very similar situation on FreeBSD not too long ago (daemons like ntpd and named coming up before the actual network usable -- ifconfig shows interface up but the ACTUAL NETWORK isn't working yet), and as such I wrote a very extensive and well-tested script to solve the problem which was committed to FreeBSD officially. It's called netwait.

    Politely (no negative intentions, honest!): you gotta think about all these things when working on embedded systems.

    You should try changing your script to this (honestly), reboot the router, then see what /tmp/output contains:

    Code:
    touch /tmp/output
    ls -ld /opt >> /tmp/output 2>&1
    ls -l /opt >> /tmp/output 2>&1
    ls -l /opt/sbin >> /tmp/output 2>&1
    ls -l /opt/etc/privoxy/config >> /tmp/output 2>&1
    
    You might be surprised at the outcome.

    P.S. -- Do not, under any circumstance, bring GNU screen into the picture! privoxy starts as a daemon unless you run it with --no-daemon (here's the documentation) so there is literally no purpose to using GNU screen to "background the process". Furthermore, if you want to background a process on Linux, use the nohup command. On FreeBSD, use the daemon command (it behaves differently than nohup; rather not explain the difference, outside of the context of this thread).

    P.P.S -- You should really be making use of the --pidfile argument (to write a pidfile to /var/run, e.g. /var/run/privoxy.pid) and use kill `cat /var/run/privoxy.pid` in your stop script, and avoid use of killall. Using killall as root can be deadly; it kills all processes on the system (not just one!), for all users, that match whatever substring you give it. killall is "convenient", but is a very bad utility to get in the habit of using. And on Solaris, killall kills ALL SYSTEM PROCESSES, including init (which then reboots the machine) -- it does not behave anywhere near Linux and BSD killall. So again, don't use killall; this is what pidfiles are for! :)

    P.P.P.S. -- You have variables in your script which aren't double-quoted (such as $DAEMON). You should fix that. It matters if someone ever tries to use your script with a path that has spaces in the filename and is good practise.
     
  7. Prophet

    Prophet Networkin' Nut Member

    Thanks for the help. I went the cowardly way and croned the initscript :) hey I just wanna be able to read my feedemons without ads ;-)

    Thanks for the help. YOu might be right that opt isnt mounted though. I cant seem to find any logs on this either .:/
     

Share This Page