i have constellation 3 involved scripts, written in php, shell , python. running on raspberry pi b+ latest raspbian.
the python script switches wireless socket lib: http://github.com/xkonni/raspberry-remote.git , following:
#!/usr/bin/env python import time import subprocess import rpi.gpio gpio import sys channelcode = sys.argv[1] unitcode = sys.argv[2] duration = sys.argv[3] # use pins on board. gpio.setmode(gpio.board) # pin 18 gpio.setup(12, gpio.in) while 1: if gpio.input(12) == gpio.low: subprocess.call('sudo send ' + channelcode + ' ' + unitcode + ' 1', shell=true) time.sleep(float(duration)) subprocess.call('sudo send ' + channelcode + ' ' + unitcode + ' 0', shell=true) # 1 sec sleep 1 low, instead of multiple because of high sensitivity. time.sleep(1) # don't slow down system because of endless loop. time.sleep(0.01)
the endless loop recognizing light-barrier interrupt , shall run still user interrupts via webinterface.
because of needed sudo privileges lib, created bash script, executed sudo www-data (only script - security).
the shell script starts python script endless loop or kills it:
#!/bin/bash # if true, python script shall activated, if false should killed. if [ $1 = "true" ] python /var/www/html/cat-feeder/app/resources/pi/light-barrier.py $2 $3 $4 & fi if [ $1 = "false" ] kill -9 `ps -ef | grep light-barrier.py | grep -v grep | awk '{print $2}'` fi exit 0
in php shell script executed arguments killing python script , end loop or start script:
if ($lightbarrieractive === true) { exec('sudo /var/www/html/cat-feeder/app/resources/pi/catfeeder-sudo-script.sh false &'); } else { exec('sudo /var/www/html/cat-feeder/app/resources/pi/catfeeder-sudo-script.sh true 11010 4 1 &'); }
now problem: php exec command kill work fine. exec command arguments shell script activating python script causes hanging of php script.
the weird thing: executing shell script command line exact same command working!
i tried executing nohup
command, same thing.
i tried this: php hanging while exec() bash script think doesn't trigger shell script, because doesn't produce output.
Comments
Post a Comment