Search code examples
linuxubuntutor

Unable to open "/var/run/tor/tor0.pid" for writing: Permission denied after multiple instances


I am working on a tor server which need to load two instances (one hidden service and one relay). When i'am using one instances it's working fine... but with this tutorial I have a permission problem on the pid

With the original daemon it's working fine i'havent any problem of permission...

But if i use this one which add this :

# --- Multi-instance init ---

config="/etc/tor"
arrrgs="$ARGS"
command=$1
shift
instances=$*

instances() {
    case $instances in
        "")
            for c in $config/*.cfg
            do
                base=${c##*/}
                test -f "$c" && echo ${base%.cfg}
            done
            ;;
        *)
            echo "$instances"
            ;;
    esac
}

case "$command" in
    start|stop|restart|reload|force-reload|status)
        highest=0
        for i in $(instances)
        do
            NAME=$i
            DESC=$i
            TORPID="$TORPIDDIR/$i.pid"
            ARGS="$arrrgs -f $config/$i.cfg"
            execute $command
            status=$?
            test $status -gt $highest && highest=$status
        done
        exit $highest
        ;;
    *)
        execute
        exit 1
        ;;
esac

I have the error in the notice0/1.log

Sep 29 16:47:10.000 [warn] Unable to open "/var/run/tor/tor0.pid" for writing: Permission denied

So I-can't stop the instance of tor... How is-it possible ? How to correct-it ? What is the difference regarding permission between the first daemon (the original one) and the new one...

Thanks a lot by advance

EDIT :

If in config I have PidFile /var/run/tor/tor.pid it's working no permission problem but if I have PidFile /var/run/tor/tor0.pid permission error... What the ??


Solution

  • I just move all the pid file to /var/lib/tor/tor*.pid and it's now working...

    PATH=/sbin:/bin:/usr/sbin:/usr/bin
    DAEMON=/usr/bin/tor
    NAME=tor
    DESC="tor daemon"
    TORLOGDIR=/var/log/tor
    TORPIDDIR=/var/lib/tor
    TORPID=$TORPIDDIR/tor.pid
    DEFAULTSFILE=/etc/default/$NAME
    

    And modify in the config

    ## The directory for keeping all the keys/etc. By default, we store
    ## things in $HOME/.tor on Unix, and in Application Data\tor on Windows. DataDirectory /var/lib/tor/0 
    PidFile /var/lib/tor/tor0.pid
    Log notice file /var/log/tor/notices0.log
    

    If someone know why it's working now it will be great.

    Thanks