Search code examples
pythonbashinit.dsysv

Executing python script in background in init.d


to interact with my iPhone, i have created a python script that sends and recives data through a socket, the script must be started after emule in order to work, i have thought of something like this:

PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
DAEMON=/usr/local/bin/amuled
WEB=/usr/local/bin/amuleweb
NAME=amuled
DESC=amuled
RUNAMULE=no
USER=piros
# ADDED FOR iPhone
SOCKET= /home/piros/amule_scripts/aMuleSocket/aMuleSocket.py
#

And then

case "$1" in
start)
  echo -n "Starting $DESC: "
   su $USER -c "$DAEMON -f"
   while ! netstat -l -n -p -t | grep -q amuled ; do sleep 1 ; done
   su $USER -c "$WEB --quiet & "
   ##iPhone
   su $USER -c "$SOCKET & "
   ##
echo "$NAME."
;;

The big problem is, although i specified the & sign the process dosen't want to run in background :( any ideas??

Thanks!


Solution

  • Put the su process in the background, not its child. For example:

    su $USER -c "$WEB --quiet" &
    

    Notice that the ampersand is outside the quotes.