Skip to content

Instantly share code, notes, and snippets.

@Lipton2777
Forked from siennathesane/services.sh
Created January 27, 2022 10:11
Show Gist options
  • Select an option

  • Save Lipton2777/3bb37493bd29304e38cb3f9003ad621d to your computer and use it in GitHub Desktop.

Select an option

Save Lipton2777/3bb37493bd29304e38cb3f9003ad621d to your computer and use it in GitHub Desktop.
Basic service interface for Kubernetes interfaces with SystemD.
#!/bin/sh -e
KUBELET=kube-kubelet.service
PROXY=kube-proxy.service
CONTAINERS=docker.service
startstop_service() {
cmd=$1
name=$2
systemctl $cmd $name
}
startstop_kubelet() {
cmd=$1
case $cmd in
stop) systemctl stop $KUBELET ;;
start) systemctl start $KUBELET ;;
restart)
systemctl restart $KUBELET
;;
esac
}
startstop_kubeproxy() {
cmd=$1
case $cmd in
stop) systemctl stop $PROXY ;;
start) systemctl start $PROXY ;;
restart)
systemctl restart $PROXY
;;
esac
}
startstop_docker() {
cmd=$1
case $cmd in
stop) systemctl stop $CONTAINERS ;;
start) systemctl start $CONTAINERS ;;
restart)
systemctl restart $CONTAINERS
;;
esac
}
case "$1" in
start|stop|restart) cmd=$1 ;;
*) echo "usage: $0 [start|stop|restart] kubernetes|kube-proxy|kubelet|docker|other_service"; exit 1
esac
shift
for name; do
case "$name" in
kubelet) startstop_kubelet $cmd ;;
kube-proxy) startstop_kubeproxy $cmd ;;
docker) startstop_docker $cmd ;;
kubernetes) startstop_docker $cmd && startstop_kubeproxy $cmd && startstop_kubelet $cmd ;;
*) startstop_service $cmd $name ;;
esac
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment