0

In Jenkins,I start a job with Execute Windows batch command

  set BUILD_ID=DONTKILLME
  start cmd /k python Run.py

the daemon with name "python.exe". How can I restart the daemon?

or could help for other solutions..thanks

sheldon M
  • 3
  • 1

1 Answers1

0

If we can't make any assumptions about the started command, then we can only kill the process and restart it. Killing a process can be done with the Stop-Process command available in Powershell 6, or maybe with another python script.

However, if you kill a process by name then you may risk killing the wrong python script. A safer approach requires some cooperation from the launched script. For example, the script could get its process ID with os.getpid() and write it to a known file location somewhere at startup. Then the kill script could read this and kill the process with the correct ID.

Another solution would be to let the script listen for some kind of signal that it needs to stop, e.g. by listening on a socket, listening on a named pipe, or checking the file system for some condition.

Yet another option is to implement the script as a Windows Service. Then you can use the powershell commands Stop-Service and Start-Service.

Wim Coenen
  • 66,094
  • 13
  • 157
  • 251