-
Notifications
You must be signed in to change notification settings - Fork 22
/
Copy pathinstall.sh
executable file
·144 lines (124 loc) · 4.12 KB
/
install.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
#!/usr/bin/env bash
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.
#
set -e
if [ $(whoami) != root ]; then
echo "Please run as root"
exit 1
fi
SCHEDULER=pbspro
INSTALL_PYTHON3=0
INSTALL_VIRTUALENV=0
VENV=/opt/cycle/${SCHEDULER}/venv
CRON_METHOD=pbs_hook
mkdir -p /opt/cycle/${SCHEDULER}/server_dyn_res
cp server_dyn_res_wrapper.sh /opt/cycle/${SCHEDULER}/
chmod +x /opt/cycle/${SCHEDULER}/server_dyn_res_wrapper.sh
export PATH=$PATH:/root/bin
while (( "$#" )); do
case "$1" in
--install-python3)
INSTALL_PYTHON3=1
INSTALL_VIRTUALENV=1
shift
;;
--install-venv)
INSTALL_VIRTUALENV=1
shift
;;
--venv)
VENV=$2
shift 2
;;
--cron-method)
CRON_METHOD=$2
shift 2
;;
-*|--*=)
echo "Unknown option $1" >&2
exit 1
;;
*)
echo "Unknown option $1" >&2
exit 1
;;
esac
done
echo INSTALL_PYTHON3=$INSTALL_PYTHON3
echo INSTALL_VIRTUALENV=$INSTALL_VIRTUALENV
echo VENV=$VENV
# remove jetpack's python3 from the path
export PATH=$(echo $PATH | sed -e 's/\/opt\/cycle\/jetpack\/system\/embedded\/bin://g' | sed -e 's/:\/opt\/cycle\/jetpack\/system\/embedded\/bin//g')
set +e
which python3 > /dev/null;
if [ $? != 0 ]; then
if [ $INSTALL_PYTHON3 == 1 ]; then
yum install -y python3 || exit 1
else
echo Please install python3 >&2;
exit 1
fi
fi
set -e
if [ $INSTALL_VIRTUALENV == 1 ]; then
python3 -m pip install virtualenv
fi
set +e
python3 -m virtualenv --version 2>&1 > /dev/null
if [ $? != 0 ]; then
if [ $INSTALL_VIRTUALENV ]; then
python3 -m pip install virtualenv || exit 1
else
echo Please install virtualenv for python3 >&2
exit 1
fi
fi
set -e
python3 -m virtualenv $VENV
source $VENV/bin/activate
# not sure why but pip gets confused installing frozendict locally
# if you don't install it first. It has no dependencies so this is safe.
pip install packages/*
cat > $VENV/bin/azpbs <<EOF
#!$VENV/bin/python
from ${SCHEDULER}.cli import main
main()
EOF
chmod +x $VENV/bin/azpbs
azpbs -h 2>&1 > /dev/null || exit 1
if [ ! -e /root/bin ]; then
mkdir /root/bin
fi
ln -sf $VENV/bin/azpbs /root/bin/
INSTALL_DIR=$(dirname $VENV)
echo Installing "autoscale" hook
cat > $INSTALL_DIR/autoscale_hook_config.json<<EOF
{
"azpbs_path": "$VENV/bin/azpbs",
"autoscale_json": "$INSTALL_DIR/autoscale.json"
}
EOF
cp autoscale_hook.py $INSTALL_DIR/
cp logging.conf $INSTALL_DIR/
if [ "$CRON_METHOD" == "pbs_hook" ]; then
/opt/pbs/bin/qmgr -c "list hook autoscale" 1>&2 2>/dev/null || /opt/pbs/bin/qmgr -c "create hook autoscale" 1>&2
/opt/pbs/bin/qmgr -c "import hook autoscale application/x-python default $INSTALL_DIR/autoscale_hook.py"
/opt/pbs/bin/qmgr -c "import hook autoscale application/x-config default $INSTALL_DIR/autoscale_hook_config.json"
/opt/pbs/bin/qmgr -c "set hook autoscale event = periodic"
/opt/pbs/bin/qmgr -c "set hook autoscale freq = 15"
else
echo Installing cron job
cat > /etc/cron.d/azpbs_autoscale<<EOF
* * * * * root /opt/cycle/jetpack/system/bootstrap/cron_wrapper.sh $VENV/bin/azpbs autoscale --config $INSTALL_DIR/autoscale.json 2>$INSTALL_DIR/last_cron.log
* * * * * root sleep 15 && /opt/cycle/jetpack/system/bootstrap/cron_wrapper.sh $VENV/bin/azpbs autoscale --config $INSTALL_DIR/autoscale.json 2>$INSTALL_DIR/last_cron.log
* * * * * root sleep 30 && /opt/cycle/jetpack/system/bootstrap/cron_wrapper.sh $VENV/bin/azpbs autoscale --config $INSTALL_DIR/autoscale.json 2>$INSTALL_DIR/last_cron.log
* * * * * root sleep 45 && /opt/cycle/jetpack/system/bootstrap/cron_wrapper.sh $VENV/bin/azpbs autoscale --config $INSTALL_DIR/autoscale.json 2>$INSTALL_DIR/last_cron.log
EOF
fi
if [ -e /etc/profile.d ]; then
cat > /etc/profile.d/azpbs_autocomplete.sh<<EOF
which azpbs 2>/dev/null || export PATH=\$PATH:/root/bin
eval "\$(/opt/cycle/pbspro/venv/bin/register-python-argcomplete azpbs)" || echo "Warning: Autocomplete is disabled" 1>&2
EOF
fi