Skip to content
Snippets Groups Projects
Commit 1e23b54b authored by Lucio Zambon's avatar Lucio Zambon
Browse files

Add new file

parent c73dc69b
No related branches found
No related tags found
No related merge requests found
import subprocess
import sys
import psutil
import socket
host = socket.gethostname()
import urllib.request
if len(sys.argv)<2:
sys.exit('Error: missing executable name')
sys.argv[1] = sys.argv[1].replace('puma://', '')
feedback = "http://puma-01.elettra.eu/knob/index.php?host="+host+"&pid="
# Path to the executable
executable_path = ('/runtime/bin/'+sys.argv[1]).replace('/bin/elettra/', '/elettra/bin/')
def is_process_running(process_name, params):
"""Check if a process with the given name and parameters is running."""
for proc in psutil.process_iter(['name', 'cmdline']):
try:
# Check if the process name matches
if proc.info['name'] == process_name:
# Check if the command line arguments match
if params == proc.info['cmdline'][1:]: # Skip the first element (the executable name)
return True
except (psutil.NoSuchProcess, psutil.AccessDenied, psutil.ZombieProcess):
pass
return False
process_name = sys.argv[1].replace('elettra/', '')
params = sys.argv[2:]
if is_process_running(process_name, params):
print(f"The process '{process_name}' with parameters {params} is already running.")
sys.argv[1] = executable_path
# processInfo = subprocess.Popen('/usr/bin/python3 /home/elettra/tmp/lz/vibration.py '+' '.join(sys.argv[1:]), shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
# print(processInfo.stdout.read())
f = urllib.request.urlopen(feedback+'0')
myfile = f.read()
else:
print(f"The process '{process_name}' with parameters {params} is not running.")
try:
sys.argv[1] = executable_path
process = subprocess.Popen(sys.argv[1:])
pid = process.pid
print(f"The PID of the launched process is: {pid}")
f = urllib.request.urlopen(feedback+str(pid))
myfile = f.read()
#print(myfile)
except Exception as e:
print(e)
f = urllib.request.urlopen(feedback+'-1&err='+str(e))
myfile = f.read()
#print(myfile)
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment