06 Nov 2024 04:55 PM
Good day everyone, I am currently working with EdgeConnect because I want to send commands to a Linux host to restart a process. I remember seeing an EdgeConnect application for workflows, is that correct?
If that app no longer exists, how can I send that command to my host through a workflow?
07 Nov 2024 03:19 AM
Hello @Jorge3229 using ansible does the trick.
with this you can create an action to launch a job template in Red Hat Ansible Automation Controller.
15 Nov 2024 08:44 AM
You can take a look at Kubernetes Automation: https://docs.dynatrace.com/docs/platform-modules/automations/workflows/actions/kubernetes-automation
This leverages EdgeConnect on Kubernetes, and you can leverage several actions (e.g., apply configuration or restart deployment) to perform certain tasks.
In theory you can also try to use a Kubernetes job/workload to execute a command on another host.
Please also refer to @DanielS post about using Red Hat Ansible, that's a perfect alternative.
15 Nov 2024 09:32 AM
You can use a server in your host to allow restarting the process.
I do prefer the Ansible solution as it is more scalable than this approach.
But something like this should work.
import ssl
from http.server import HTTPServer, BaseHTTPRequestHandler
import subprocess
class RequestHandler(BaseHTTPRequestHandler):
def do_POST(self):
if self.path == '/restart-process':
# Add authentication check here if needed
self.restart_process()
else:
self.send_error(404, "Not Found")
def restart_process(self):
try:
# Replace this with your actual restart command
subprocess.run(["systemctl", "restart", "your-process-name"], check=True)
self.send_response(200)
self.send_header('Content-type', 'text/plain')
self.end_headers()
self.wfile.write(b"Process restarted successfully")
except subprocess.CalledProcessError:
self.send_error(500, "Failed to restart process")
def run_server():
server_address = ('your-linux-host.internal', 443) # Use the appropriate hostname and port
httpd = HTTPServer(server_address, RequestHandler)
# SSL wrapping
context = ssl.SSLContext(ssl.PROTOCOL_TLS_SERVER)
context.load_cert_chain('server.crt', 'server.key')
httpd.socket = context.wrap_socket(httpd.socket, server_side=True)
print(f"Server running on https://{server_address[0]}:{server_address[1]}")
httpd.serve_forever()
if __name__ == '__main__':
run_server()
server.crt and server.key used for HTTPS
The restart_process method uses subprocess.run to execute the restart command. Replace "your-process-name" with the actual process name