执行脚本python ros apache2 [resolu]

时间:2014-01-27 20:25:42

标签: python apache raspbian apache2.2 ros

我想执行一个脚本python:

#!/usr/bin/env python
#include <actuatorSdk.h>
import os
os.environ['ROS_DISTRO']='fuerte'
os.environ['ROSLISP_PACKAGE_DIRECTORY']='/opt/ros/fuerte/share/common-lisp/ros'
os.environ['ROS_ETC_DIR']='/opt/ros/fuerte/etc/ros'
os.environ['ROS_IP']='192.168.0.30'
os.environ['ROS_MASTER_URI']='http://localhost:11311'
os.environ['ROS_PACKAGE_PATH']='/home/pi/fuerte_workspace/sandbox'
os.environ['ROS_PACKAGE_PATH']='/opt/ros/fuerte/stacks'
os.environ['ROS_PACKAGE_PATH']='opt/ros/fuerte/share'
os.environ['ROS_PACKAGE_PATH']='/opt/ros/fuerte/share/ros'
os.environ['ROS_ROOT']='/opt/ros/fuerte/share/ros'
os.environ['ROS_WORKSPACE']='/home/pi/fuerte_workspace'
os.environ['ROS_PACKAGE_PATH']='opt/ros/fuerte/lib/python2.7/dist-packages'


import roslib; roslib.load_manifest('aisoy_sdk_actuator')
roslib.load_manifest('aisoy_common')


from libaisoy_sdk_actuator import *
from libaisoy_common import * 

virtual = Actuator()
actuator = Actuator()
actuator. moveServoRelative(Servo.HeadHorizontal, 0.2)

和我的apache变种

# 

envvars - default environment variables for apache2ctl

    # this won't be correct after changing uid
    unset HOME

    # for supporting multiple apache2 instances
    if [ "${APACHE_CONFDIR##/etc/apache2-}" != "${APACHE_CONFDIR}" ] ; then
        SUFFIX="-${APACHE_CONFDIR##/etc/apache2-}"
    else
        SUFFIX=
    fi

    # Since there is no sane way to get the parsed apache2 config in scripts, some
    # settings are defined via environment variables and then used in apache2ctl,
    # /etc/init.d/apache2, /etc/logrotate.d/apache2, etc.
    export APACHE_RUN_USER=www-data
    export APACHE_RUN_GROUP=www-data
    export APACHE_PID_FILE=/var/run/apache2$SUFFIX.pid
    export APACHE_RUN_DIR=/var/run/apache2$SUFFIX
    export APACHE_LOCK_DIR=/var/lock/apache2$SUFFIX
    export ROSLISP_PACKAGE_DIRECTORY=/opt/ros/fuerte/share/common-lisp/ros
    export ROS_DISTRO=fuerte
    export ROS_ETC_DIR=/opt/ros/fuerte/etc/ros
    export ROS_IP="192.168.0.30"
    export ROS_MASTER_URI=http://localhost:11311
    export ROS_PACKAGE_PATH=$ROS_PACKAGE_PATH:/home/pi/fuerte_workspace/sandbox
    export ROS_PACKAGE_PATH=$ROS_PACKAGE_PATH:/opt/ros/fuerte/stacks
    export ROS_PACKAGE_PATH=$ROS_PACKAGE_PATH:/opt/ros/fuerte/share
    export ROS_PACKAGE_PATH=$ROS_PACKAGE_PATH:/opt/ros/fuerte/share/ros
    export ROS_PACKAGE_PATH=$ROS_PACKAGE_PATH:/home/pi/fuerte_workspace
    export ROS_ROOT=/opt/ros/fuerte/share/ros
    export ROS_WORKSPACE=/home/pi/fuerte_workspace
    #export PYTHONPATH=http://192.168.0.30/py/head-left1.py
    #export PYTHONPATH=/opt/ros/fuerte/lib/python2.7/dist-packages


    # Only /var/log/apache2 is handled by /etc/logrotate.d/apache2.
    export APACHE_LOG_DIR=/var/log/apache2$SUFFIX

    ## The locale used by some modules like mod_dav
    export LANG=C
    ## Uncomment the following line to use the system default locale instead:
    #. /etc/default/locale

    export LANG

    ## The command to get the status for 'apache2ctl status'.
    ## Some packages providing 'www-browser' need '--dump' instead of '-dump'.
    #export APACHE_LYNX='www-browser -dump'

    ## If you need a higher file descriptor limit, uncomment and adjust the
    ## following line (default is 8192):
    #APACHE_ULIMIT_MAX_FILES='ulimit -n 65536'


    ## If you would like to pass arguments to the web server, add them below
    ## to the APACHE_ARGUMENTS environment.
    export APACHE_ARGUMENTS=''
    export ROSLISP_PACKAGE_DIRECTORY="/opt/ros/fuerte/share/common-lisp/ros"
    export ROS_DISTRO="fuerte"
    export ROS_ETC_DIR="/opt/ros/fuerte/etc/ros"
    export ROS_IP="192.168.0.30"
    export ROS_MASTER_URI="http://localhost:11311"
    export ROS_PACKAGE_PATH="/home/pi/fuerte_workspace/sandbox:/opt/ros/fuerte/stacks:/opt/ros/fuerte/share:/opt/r#os/fuerte/share/ros"
    export ROS_ROOT="/opt/ros/fuerte/share/ros"
    export ROS_WORKSPACE="/home/pi/fuerte_workspace"
    export ROSLISP_PACKAGE_DIRECTORY=/opt/ros/fuerte/share/common-lisp/ros
    export ROS_DISTRO=fuerte
    export ROS_ETC_DIR=/opt/ros/fuerte/etc/ros
    export ROS_IP="192.168.0.30"
    export ROS_MASTER_URI=http://localhost:11311
    export ROS_PACKAGE_PATH=$ROS_PACKAGE_PATH:/home/pi/fuerte_workspace/sandbox
    export ROS_PACKAGE_PATH=$ROS_PACKAGE_PATH:/opt/ros/fuerte/stacks
    export ROS_PACKAGE_PATH=$ROS_PACKAGE_PATH:/opt/ros/fuerte/share
    export ROS_PACKAGE_PATH=$ROS_PACKAGE_PATH:/opt/ros/fuerte/share/ros
    export ROS_PACKAGE_PATH=$ROS_PACKAGE_PATH:/home/pi/fuerte_workspace
    export ROS_ROOT=/opt/ros/fuerte/share/ros
    export ROS_WORKSPACE=/home/pi/fuerte_workspace
    #export PYTHONPATH=$ROS_PACKAGE_PATH/http://192.168.0.30/py/head-left1.py
    #export PYTHONPATH=/opt/ros/fuerte/lib/python2.7/dist-packages

和我的错误500 apache:

tail -f /var/log/apache2/error.log
[Mon Jan 27 20:05:01 2014] [error] python_init: Python executable found '/usr/bin/python'.
[Mon Jan 27 20:05:01 2014] [error] python_init: Python path being used '/usr/lib/python2.7/:/usr/lib/python2.7/plat-linux2:/usr/lib/python2.7/lib-tk:/usr/lib/python2.7/lib-old:/usr/lib/python2.7/lib-dynload'.
[Mon Jan 27 20:05:01 2014] [notice] mod_python: Creating 8 session mutexes based on 6 max processes and 25 max threads.
[Mon Jan 27 20:05:01 2014] [notice] mod_python: using mutex_directory /tmp
[Mon Jan 27 20:05:03 2014] [notice] Apache/2.2.22 (Debian) mod_python/3.3.1 Python/2.7.3 configured -- resuming normal operations
Traceback (most recent call last):
  File "/usr/lib/cgi-bin/head-left1.py", line 18, in <module>
    import roslib; roslib.load_manifest('aisoy_sdk_actuator')
ImportError: No module named roslib
[Mon Jan 27 20:05:34 2014] [error] [client 192.168.0.10] Premature end of script headers: head-left1.py,

ImportError:roslib,我认为路径错了..

我测试没有ros的脚本python,它可以工作。

1 个答案:

答案 0 :(得分:0)

待办事项:

h-left.py

 <?php
header('Location: /aisoy2/index.html');  # redirection vers page principal 
exec('python /home/pi/py/head-left.py');
?>

我的脚本python:

#!/usr/bin/env python
#include <actuatorSdk.h>
import roslib; roslib.load_manifest('aisoy_sdk_actuator')
roslib.load_manifest('aisoy_common')
from libaisoy_sdk_actuator import *;
from libaisoy_common import *


virtual = Actuator();
actuator = Actuator();
actuator. moveServoRelative(Servo.HeadHorizontal, 0.2);
virtual = Actuator();

并添加到/ etc / sudoers

www-data ALL = NOPASSWD:/ usr / bin / env python