Changing Working directory in OpenWrt init script

Hi there. My init service is as follows:

#!/bin/sh /etc/rc.common
SCRIPT_NAME="MyService"
SCRIPT_PATH="/project/main.py"
LOG_FILE="/project/service.log"
START=50
STOP=50
start(){
        echo "Starting $SCRIPT_NAME"
        $SCRIPT_PATH >> $LOG_FILE 2>&1 &
}
stop(){
        echo "Stopping $SCRIPT_NAME"
        killall `basename $SCRIPT_PATH`
}

This service runs main.py from project folder. But I want to run this same file from /tmp directory. Means I want to change the working directory. How to achieve this?

You would add:

cd /tmp

1 Like

I have done this but strangely it is not working.
But when I used logger also in this then it starts working.

#!/bin/sh /etc/rc.common
SCRIPT_NAME="MyService"
SCRIPT_PATH="/project/main.py"
LOG_FILE="/project/service.log"
START=50
STOP=50
start() {
        logger -p user.notice "Myservice starting..."
        cd /tmp/
        $SCRIPT_PATH &
        logger -p user.notice "Projectservice started"
}
stop(){
        echo "Stopping $SCRIPT_NAME"
        killall `basename $SCRIPT_PATH`
}

But then it does not works after reboot.