-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·140 lines (111 loc) · 3.65 KB
/
install.sh
File metadata and controls
executable file
·140 lines (111 loc) · 3.65 KB
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
#!/bin/bash
set -e
# set -x
PORT=5000
SSLLOC="/etc/nginx"
RUNDEFAULTIMPLEMETATION=false
MODELS_PATH="/home/rtpt"
Help() {
echo "Install script for aimodel deployment."
echo
echo "Syntax: sudo ./install.sh [-h|p|s]"
echo "h Print this help."
echo "p Port where the flask application will be running."
echo "r Run default implementation (gpt4all, and Mistral model if GPU available)"
echo "s Location where key and certificate will be stored, defaults to $SSLLOC"
echo
}
while getopts "hp:s:r" option; do
case $option in
h)
Help
exit
;;
p)
PORT=$OPTARG
echo "Set port to $PORT"
;;
s)
SSLLOC=$OPTARG
;;
r)
RUNDEFAULTIMPLEMETATION=true
;;
esac
done
# Location of the ssl certificate and key
SSLCERTIFICATE=$SSLLOC/aimodel_cert.pem
SSLKEY=$SSLLOC/aimodel_key.pem
# Force the user to run the script as sudo
if [[ $(id -u) -ne 0 ]]; then
echo "Please run this file as sudo user."
exit
fi
# Update the system
apt update
# Install python3.10 and pip
apt install -y python3.10-venv python3-pip
# Install pyopenssl to create certificates
sudo -u $SUDO_USER pip install pyopenssl
# Install nginx and gunicorn
apt install nginx
apt install -y gunicorn
# Create a self-signed certificate
openssl req -x509 -newkey rsa:4096 -nodes -out $SSLLOC/aimodel_cert.pem -keyout $SSLLOC/aimodel_key.pem -days 365 -subj="/C=CA/ST=Ontario/L=Ottawa/O=Carleton University/OU=RCS/CN=localhost"
# Change the owner of the certificate and key
sudo chown $SUDO_USER /etc/nginx/aimodel_*
# Create a new nginx configuration file
cat >/etc/nginx/sites-available/aimodel <<EOL
server {
listen 80;
listen 443 default_server ssl;
ssl_certificate $SSLCERTIFICATE;
ssl_certificate_key $SSLKEY;
server_name _;
location / {
proxy_pass https://localhost:$PORT;
proxy_connect_timeout 1200s;
proxy_send_timeout 1200s;
proxy_read_timeout 1200s;
send_timeout 1200s;
}
}
EOL
# Create a symbolic link to the sites-enabled directory
sudo ln -sf /etc/nginx/sites-available/aimodel /etc/nginx/sites-enabled/aimodel
# Check the configuration file
sudo nginx -t
# Restart the nginx service
sudo systemctl restart nginx
# Create a virtual environment
[ -d .venv ] &
echo ".venv already exists. skipping." | sudo -u $SUDO_USER python3 -m venv .venv
# Activate the virtual environment
if [[ "$VIRTUAL_ENV" != "" ]]; then
echo ".venv already active"
else
source .venv/bin/activate
fi
# Upgrade pip
python -m pip install --upgrade pip
# Install the requirements
pip install -e .
# Install gunicorn
pip install gunicorn
# Run the default implementation (gpt4all, and Mistral model if GPU available)
GUNICORNCMD="gunicorn --certfile $SSLCERTIFICATE --keyfile $SSLKEY -b 0.0.0.0:$PORT --threads 8 --timeout 0 'main:app()' --log-level DEBUG"
if [ "$RUNDEFAULTIMPLEMETATION" == true ]; then
echo "Running default implementation... $GUNICORNCMD"
$GUNICORNCMD
else
echo "To run the application, use the following command:"
echo "$GUNICORNCMD"
fi
source production.env
pm2 start gunicorn --interpreter .venv/bin/python --name flask_llm_server-- --certfile $SSLCERTIFICATE --keyfile $SSLKEY -b 0.0.0.0:$PORT --threads 8 -w 1 --timeout 0 'main:app()' --log-level DEBUG
pm2 save
pm2 startup systemd
sudo systemctl enable pm2-$SUDO_USER
#last used command:
# pm2 start gunicorn --interpreter .venv/bin/python --name flask_llm_server -- --certfile /etc/nginx/aimodel_cert.pem --keyfile /etc/nginx/aimodel_key.pem -b 0.0.0.0:5000 --threads 8 -w 1 --timeout 0 'main:app()' --log-level DEBUG
echo "Done!"