2017-01-11 6 views
1

私はキーボード入力を受け取り、csvファイルに入力するpythonスクリプトを持っています。同じタスクを実行するいくつかのラズベリーがあり、私は管理プロセスを見て、Pythonスクリプトがまだ実行中であることを確認したい。Supervisord - ターミナルと対話する必要があるPythonスクリプトを実行する

私はスクリプトを開始してスクリプトを遠隔監視することができました。しかし、スーパーバイザーがpythonスクリプトを起動すると、ターミナルとやりとりするのを止めます。したがって、キーボード入力はスクリプトによって取り上げられません。 Pythonコードを起動してコマンドラインと対話させる方法はありますか?

PSこれはコーディングの最初のビットですので、間違いなくNoob!


Supervisord.conf:


; Sample supervisor config file. 
; 
; For more information on the config file, please see: 
; http://supervisord.org/configuration.html 
; 
; Notes: 
; - Shell expansion ("~" or "$HOME") is not supported. Environment 
; variables can be expanded using this syntax: "%(ENV_HOME)s". 
; - Comments must have a leading space: "a=b ;comment" not "a=b;comment". 

[unix_http_server] 
file=/tmp/supervisor.sock ; (the path to the socket file) 
chmod=0700     ; socket file mode (default 0700) 
;chown=nobody:nogroup  ; socket file uid:gid owner 
;username=user    ; (default is no username (open server)) 
;password=123    ; (default is no password (open server)) 

[inet_http_server]   ; inet (TCP) server disabled by default 
port=*:9001  ; (ip_address:port specifier, *:port for all iface) 
username=user    ; (default is no username (open server)) 
password=pswd    ; (default is no password (open server)) 

[supervisord] 
logfile=/tmp/supervisord.log ; (main log file;default $CWD/supervisord.log) 
logfile_maxbytes=50MB  ; (max main logfile bytes b4 rotation;default 50MB) 
logfile_backups=10   ; (num of main logfile rotation backups;default 10) 
loglevel=info    ; (log level;default info; others: debug,warn,trace) 
pidfile=/tmp/supervisord.pid ; (supervisord pidfile;default supervisord.pid) 
nodaemon=false    ; (start in foreground if true;default false) 
minfds=1024     ; (min. avail startup file descriptors;default 1024) 
minprocs=200     ; (min. avail process descriptors;default 200) 
;umask=022     ; (process file creation umask;default 022) 
user=pi     ; (default is current user, required if root) 
;identifier=supervisor  ; (supervisord identifier, default is 'supervisor') 
;directory=/tmp    ; (default is not to cd during start) 
;nocleanup=true    ; (don't clean up tempfiles at start;default false) 
;childlogdir=/tmp   ; ('AUTO' child log dir, default $TEMP) 
;environment=KEY="value"  ; (key value pairs to add to environment) 
;strip_ansi=false   ; (strip ansi escape codes in logs; def. false) 

; the below section must remain in the config file for RPC 
; (supervisorctl/web interface) to work, additional interfaces may be 
; added by defining them in separate rpcinterface: sections 

[rpcinterface:supervisor] 
supervisor.rpcinterface_factory = supervisor.rpcinterface:make_main_rpcinterface 

[supervisorctl] 
serverurl=unix:///tmp/supervisor.sock ; use a unix:// URL for a unix socket 
;serverurl=http://10.55.0.102:9001 ; use an http:// url to specify an inet socket 
username=user    ; should be same as http_username if set 
password=pswd    ; should be same as http_password if set 
;prompt=mysupervisor   ; cmd line prompt (default "supervisor") 
;history_file=~/.sc_history ; use readline history if available 


[program:GIST] 
command=/usr/bin/sudo /usr/bin/python /home/pi/Main.py -DFOREGROUND 
;command=/home/pi/Main.py 
numprocs=1 
autostart=true 
startsecs=1 
startretries=3 
autorestart=unexpected 
exitcodes=0,2 
stopsignal=QUIT 
user=User 

; The below sample eventlistener section shows all possible 
; eventlistener subsection values, create one or more 'real' 
; eventlistener: sections to be able to handle event notifications 
; sent by supervisor. 



; The below sample group section shows all possible group values, 
; create one or more 'real' group: sections to create "heterogeneous" 
; process groups. 

;[group:thegroupname] 
;programs=progname1,progname2 ; each refers to 'x' in [program:x] definitions 
;priority=999     ; the relative start priority (default 999) 

; The [include] section can just contain the "files" setting. This 
; setting can list multiple files (separated by whitespace or 
; newlines). It can also contain wildcards. The filenames are 
; interpreted as relative to this file. Included files *cannot* 
; include files themselves. 

;[include] 
;files = relative/directory/*.ini 

のPythonスクリプト:


import sys, select, datetime, select, fcntl, socket, struct, time, os 

#t = datetime.datetime.now() 
#timenow = time.mktime(t.timetuple()) 

def getmac(interface): 
     try: 
       mac = open('/sys/class/net/'+interface+'/address').readline() 
     except: 
       mac = "00:00:00:00:00:00" 
     return mac[0:17] 
myMAC = getmac("wlan0") 

def get_ip_addr(ifname): 
     try: 
       s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) 
       return socket.inet_ntoa(fcntl.ioctl(
         s.fileno(), 
         0x8915, # SIOCGIFADDR 
         struct.pack('256s', ifname[:15]) 
        )[20:24]) 
     except: 
       () 

print get_ip_addr('wlan0') 
print myMAC 


IPAddr = get_ip_addr('wlan0') 

while True: 
     if os.path.lexists('/home/pi/GistLog.csv'): 

       i, o, e, = select.select([sys.stdin], [], [], 3600) 
       if (i): 
         id = sys.stdin.readline().strip() 
         if id == "exit": 
             break 
         t = datetime.datetime.now() 
         timenow = time.mktime(t.timetuple()) 

         with open("/home/pi/GistLog.csv", "a") as Log: 
           Log.write (id + "," +str(timenow)+ "," + str(myMAC) + "," + str(IPAddr) + "," + "\n") 

         print"Scan Successful" 
         print t 

       else: 
         print"Scan Error" 
     else: 
       i, o, e, = select.select([sys.stdin], [], [], 3600) 
       if (i): 
         id = sys.stdin.readline().strip() 
         if id == "exit": 
           break 
         t = datetime.datetime.now() 
         timenow = time.mktime(t.timetuple()) 

         with open("/home/pi/GistLog.csv", "a") as Log: 
           Log.write ("id,rfid,timestamp,MAC,IPAddr,\n" + id + "," +str(timenow)+ "," + str(myMAC) + "," + str(IPAddr) + "," + "\n") 
       else: 
         print"Scan Error" 

答えて

0

私はそれを動作するように管理する - 私はsupervisoを考え出しましたrctl fgコマンドを使用して、プロセスをフォアグラウンドに持ち込んで、私にそれをやりとりさせました。

また、これを/ etc/profileから自動起動してスーパーバイザプロセスを起動し、5をスリープしてからsupervisorctl fbコマンドを起動します。

クリス

関連する問題