istio.io/istio@v0.0.0-20240520182934-d79c90f27776/pkg/ctrlz/topics/signals.go (about) 1 // Copyright 2019 Istio Authors 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 package topics 16 17 import ( 18 "net/http" 19 "os" 20 "syscall" 21 22 "istio.io/istio/pkg/ctrlz/fw" 23 "istio.io/istio/pkg/ctrlz/topics/assets" 24 ) 25 26 type signalsTopic struct{} 27 28 // SignalsTopic returns a ControlZ topic that sends command signals to the process 29 func SignalsTopic() fw.Topic { 30 return signalsTopic{} 31 } 32 33 func (signalsTopic) Title() string { 34 return "Signals" 35 } 36 37 func (signalsTopic) Prefix() string { 38 return "signal" 39 } 40 41 func (signalsTopic) Activate(context fw.TopicContext) { 42 tmpl := assets.ParseTemplate(context.Layout(), "templates/signals.html") 43 44 _ = context.HTMLRouter().StrictSlash(true).NewRoute().Path("/").HandlerFunc(func(w http.ResponseWriter, req *http.Request) { 45 fw.RenderHTML(w, tmpl, nil) 46 }) 47 48 _ = context.JSONRouter().StrictSlash(true).NewRoute().Methods("PUT", "POST").Path("/SIGUSR1").HandlerFunc(func(w http.ResponseWriter, req *http.Request) { 49 err := syscall.Kill(os.Getpid(), syscall.SIGUSR1) 50 if err != nil { 51 w.WriteHeader(http.StatusInternalServerError) 52 return 53 } 54 w.WriteHeader(http.StatusAccepted) 55 }) 56 }