I have a grpc server(golang) which I want to start and stop via command line tool, after stopping the server it should perform some housekeeping tasks and exit the process.
- I can do this by keeping a loop waiting for user input. Ex -
func main() {
for {
var input string
fmt.Scanln(&input)
//parse input
// if 'start' execute - go start()
// if 'stop' execute - stop() and housekeepingTask() and break
}
}
There can be different approaches. Is there any better idea or approach which can be used ?
I am looking for something similar how kafka/any db start and stop works. Any pointer to an existing solution or approach would be helpful.