Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F31482722
raw.txt
No One
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Authored By
•
Bstorm
Dec 19 2019, 3:46 PM
2019-12-19 15:46:31 (UTC+0)
Size
2 KB
Referenced Files
None
Subscribers
None
raw.txt
View Options
#!/bin/bash
# This is intended to be run as a tool user
set -Eeuo pipefail
function usage {
echo -e "Usage (must be toolforge user account):\n"
echo "run_webservice.sh <start|stop>"
echo ""
echo "Example: run_webservice.sh start"
}
function startsvc {
echo "starting..."
cat <<EOF | kubectl apply -f -
apiVersion: apps/v1
kind: Deployment
metadata:
labels:
name: $1
toolforge: tool
tool.toolforge.org/service: "true"
name: $1
spec:
replicas: 1
selector:
matchLabels:
name: $1
toolforge: tool
tool.toolforge.org/service: "true"
template:
metadata:
labels:
name: $1
toolforge: tool
tool.toolforge.org/service: "true"
spec:
serviceAccountName: ${1}-obs
containers:
- command:
- /usr/bin/webservice-runner
- --type
- uwsgi-python
- --port
- "8000"
image: docker-registry.tools.wmflabs.org/toolforge-python37-sssd-web:latest
imagePullPolicy: Always
name: webservice
ports:
- containerPort: 8000
name: http
protocol: TCP
workingDir: /data/project/${1}/
EOF
cat <<EOF | kubectl apply -f -
apiVersion: v1
kind: Service
metadata:
labels:
name: $1
toolforge: tool
tool.toolforge.org/service: "true"
name: $1
spec:
ports:
- name: http
port: 8000
protocol: TCP
targetPort: 8000
selector:
name: $1
type: ClusterIP
EOF
cat <<EOF | kubectl apply -f -
apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
annotations:
nginx.ingress.kubernetes.io/rewrite-target: /$1/\$2
labels:
name: $1
toolforge: tool
tool.toolforge.org/service: "true"
name: $1
spec:
rules:
- host: tools.wmflabs.org
http:
paths:
- backend:
serviceName: $1
servicePort: 8000
path: /$1(/|$)(.*)
EOF
}
function stopsvc {
echo "stopping..."
echo "First the ingress"
kubectl delete ingress $1
echo "Now the service"
kubectl delete svc $1
echo "And the actual app"
kubectl delete deployment $1
}
wmcsproject=$(</etc/wmcs-project)
if ! [[ $USER == "${wmcsproject}."* ]]; then
printf >&2 '%s: user name does not start with "%s": %s\n' "$0" "$wmcsproject" "$USER"
usage
exit 1
fi
prefix=$(($(echo -n $wmcsproject | wc -c)+1))
tool="${USER:prefix}"
case $1 in
start)
startsvc "$tool"
;;
stop)
stopsvc "$tool"
;;
restart)
echo "For a restart, this seems kind of heavy"
echo "Why don't you just run \"kubectl get pods\" and the \"kubectl delete pods <podname>\"?"
;;
*)
echo "There must be an argument of start or stop"
usage
exit 1
;;
esac
File Metadata
Details
Attached
Mime Type
text/plain; charset=utf-8
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
8269494
Default Alt Text
raw.txt (2 KB)
Attached To
Mode
P9946 k8s_webservice.sh
Attached
Detach File
Event Timeline
Log In to Comment