我想运行python脚本作为服务。因为我遵循指示here。在后台运行Python脚本作为服务
初始化脚本(myservice.sh),我照原样复制。
为myservice.py,
import sys, struct
from socket import *
SIZE = 1024 # packet size
hostName = gethostbyname('0.0.0.0')
mySocket = socket(AF_INET, SOCK_DGRAM)
mySocket.bind((hostName,18736))
repeat = True
while repeat:
(data,addr) = mySocket.recvfrom(SIZE)
data = struct.unpack('d',data)
data=int(data[0])
file = open("output.txt", "w")
file.write(str(data))
file.close()
当我启动服务 “命令/etc/init.d/myservice.sh开始”。 它成功启动。
当我发送udp数据,但没有任何事情发生到“output.txt”。这里有什么问题?
是端口18736监听? – hariK
[1]手动启动时,此脚本是否按预期工作? [2]尝试将输出文件更改为具有完整路径的文件,并将其更改为'/ tmp/output.txt'等众所周知的目录。 –
@ hariK是的,它听着18736 –