circus-tent / circus

A Process & Socket Manager built with zmq
http://circus.readthedocs.org/
Other
1.55k stars 258 forks source link

Circus environment variable reference #1082

Closed CarlosEssun closed 6 years ago

CarlosEssun commented 6 years ago

Environment

pyenv python==3.5.2 paho-mqtt==1.3.1 circus==1.3.0

Description

My own script file, which references paho-mqtt, runs without problems when using the command line.

[socket:web] host = 0.0.0.0 port = 9999

* mqtt.ini

[watcher:mqtt] working_dir = /opt/sengled/reliabilityOps/Firmware/light/firmware cmd = python args = -u mqtt_service.py numprocesses = 1

copy_env = True

copy_path = True

virtulenv = /opt/pyenv/versions/firmware

stderr_stream.class = FileStream stdout_stream.class = FileStream stdout_stream.filename = /var/log/sengled/mqtt/mqtt-stdout.log stderr_stream.filename = /var/log/sengled/mqtt/mqtt-stderr.log stdout_stream.max_bytes = 1073741824

 but when I use the service reference watcher mqtt, I always find that I can't find it.
Traceback (most recent call last):
  File "mqtt_service.py", line 16, in <module>
    import paho.mqtt.client as mqtt
ImportError: No module named paho.mqtt.client
but I don't have this problem on the command line.
```bash
(firmware) [root@ip-172-31-117-206 Firmware]# circusd --log-level debug /etc/circus/conf.d/mqtt.ini
2018-09-29 07:07:53 circus[14449] [INFO] Starting master on pid 14449
2018-09-29 07:07:53 circus[14449] [DEBUG] Initializing watchers
2018-09-29 07:07:53 circus[14449] [DEBUG] cmd: python
2018-09-29 07:07:53 circus[14449] [DEBUG] args: -u mqtt_service.py
2018-09-29 07:07:53 circus[14449] [DEBUG] process args: ['python', '-u', 'mqtt_service.py']
2018-09-29 07:07:53 circus[14449] [DEBUG] running mqtt process [pid 14519]
2018-09-29 07:07:53 circus[14449] [INFO] Arbiter now waiting for commands
2018-09-29 07:07:53 circus[14449] [INFO] mqtt started
import sys
import time
import os
import json
import random
from functools import wraps
import threading
import requests
#import configparser
import paho.mqtt.client as mqtt
from flogging.log import FirmwareLog
from catch.ExceptionHandler import catch_exception
from stream.stream import Stream
from task_timer import TaskInterval
from downlink_channel import FirmwareDownlink
from uplink_channel import FirmwareUplink
from work_protocol_service import Firmware_Socket_Client

#cf = configparser.ConfigParser()
sys.path[0] = '/'.join(sys.path[0].split('/')[:-1])
from middleware.redis_connect import redisConnect
from element.element_build_net import DeviceWithRequest
.....

Other configuration file [ini] references have no such problem I think it may be an environmental path problem, but I did not find a specific solution! Thank you

k4nar commented 6 years ago

I'm not sure to understand your problem, but I would say that you probably need to uncomment copy_env = True so that your process runs in the right virtualenv.

CarlosEssun commented 6 years ago

@k4nar Enable copy_env=True I got it. Thanks