Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
canone4
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
puma
server
canone4
Commits
1e23b54b
Commit
1e23b54b
authored
1 month ago
by
Lucio Zambon
Browse files
Options
Downloads
Patches
Plain Diff
Add new file
parent
c73dc69b
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
launcher.py
+54
-0
54 additions, 0 deletions
launcher.py
with
54 additions
and
0 deletions
launcher.py
0 → 100644
+
54
−
0
View file @
1e23b54b
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)
This diff is collapsed.
Click to expand it.
Preview
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment