Is there a way to stop and start a service running on linux from grpc microservice


I have a scenario where I need to call grpc micro service which will control the stop/start of a service running on Linux system.

Will be calling grpc micro service from java code.
Additional Info: Current code is calling “systemctl is-enabled/is-active/start/stop service_name” from java code and it works as long as this is running on host. But, am working on containerization where code is running in a pod container, hence systemctl is failing. Requirement here is to create grpc service, to control these “is-enabled/is-active/start/stop” actions and call grpc service from java code to achieve the desired result.
Can you someone suggest me the process of doing this from micro service.

cmd.Exec should just work for your use case, as long as the go program runs on the host that runs systemd.

This base requirement isn’t any different from the java service.

Thanks NobbZ for the comments.
This worked.
I am not sure if grpc client running on pod container, will have any issue if I use cmd.exec on grpc service. any comments on this ?

The program that runs systemctl needs to run on the actual host that runs systemd.

I’m not aware of a way to use systemctl to control the systemd on another system, unless of course you run it through SSH.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.