-
Notifications
You must be signed in to change notification settings - Fork 2
/
run_hyperion_in_podman.sh
executable file
·149 lines (127 loc) · 3.69 KB
/
run_hyperion_in_podman.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
#!/bin/bash
STOP=0
START=0
UP=0
IN_DEV=false
show_help() {
echo "$(basename $0) [options...]"
cat <<END
Script for the convenience of running a container image locally using podman-compose.
--dev Start a dev container bound against source folders that launches into a bash shell
-b, --beamline=BEAMLINE Overrides the BEAMLINE environment variable with the given beamline
Operations
--stop Used to stop a currently running instance of Hyperion. Will override any other operations
options
--start Specify that the script should start the server
--up Create the container for the service but do not start
--restart Specify that the script should stop and then start the server.
END
exit 0
}
for option in "$@"; do
case $option in
-b=*|--beamline=*)
BEAMLINE="${option#*=}"
shift
;;
--stop)
STOP=1
;;
--start)
START=1
;;
--up)
UP=1
START=0
;;
--logs)
LOGS=1
;;
--restart)
STOP=1
START=1
;;
--dev)
IN_DEV=true
;;
--help|--info|--h)
show_help
;;
-*|--*)
echo "Unknown option ${option}. Use --help for info on option usage."
exit 1
;;
esac
done
if [[ $START = 0 && $STOP = 0 && $UP = 0 ]]; then
echo "One of --start, --stop, --restart or --up must be specified"
show_help
fi
ensure_prerequisites() {
if [[ -z $VIRTUAL_ENV ]]; then
echo "Activating virtual environment"
. $RELATIVE_SCRIPT_DIR/.venv/bin/activate
fi
TYPE=$(type -t podman-compose)
if [[ $TYPE != file ]]; then
pip install podman-compose
fi
}
kill_active_apps () {
echo "Killing active instances of hyperion and hyperion-callbacks..."
podman compose -f ${COMPOSE_YAML} stop ${SERVICE}
echo "done."
}
check_user () {
if [[ $HOSTNAME != "${BEAMLINE}-control.diamond.ac.uk" || $USER != "gda2" ]]; then
echo "Must be run from beamline control machine as gda2"
echo "Current host is $HOSTNAME and user is $USER"
exit 1
fi
}
RELATIVE_SCRIPT_DIR=$( dirname -- "$0"; )
COMPOSE_YAML=${RELATIVE_SCRIPT_DIR}/utility_scripts/docker/${BEAMLINE}-compose.yml
EXTRA_ARGS=""
if [[ -z "${BEAMLINE}" ]]; then
echo "BEAMLINE parameter not set."
echo "If you would like to run on a dev machine set the option -b, --beamline=BEAMLNE to set it manually"
exit 1
fi
if [[ $IN_DEV == false ]]; then
SERVICE=hyperion
else
if [[ $UP == 1 ]]; then
echo "--up cannot be used with --dev"
exit 1
fi
SERVICE=hyperion-dev
fi
ensure_prerequisites
if [[ $LOGS == 1 ]]; then
podman compose -f ${COMPOSE_YAML} logs ${SERVICE}
exit 0
fi
if [[ $STOP == 1 ]]; then
if [[ $IN_DEV == false ]]; then
check_user
fi
kill_active_apps
echo "Hyperion stopped"
fi
if [[ $UP == 1 ]]; then
podman compose -f ${COMPOSE_YAML} down --remove-orphans
podman compose -f ${COMPOSE_YAML} up --no-start --no-build ${SERVICE}
fi
if [[ $START == 1 ]]; then
if [ $IN_DEV == false ]; then
check_user
fi
kill_active_apps
if [[ $IN_DEV == true ]]; then
echo "Starting with podman compose -f ${COMPOSE_YAML} run -v ${HOME}/.zocalo:/root/.zocalo ${SERVICE}"
podman compose -f ${COMPOSE_YAML} run -v ${HOME}/.zocalo:/root/.zocalo ${SERVICE}
else
echo "Starting with podman compose -f ${COMPOSE_YAML} start ${SERVICE}"
podman compose -f ${COMPOSE_YAML} start ${SERVICE}
fi
fi