Skip to content

Instantly share code, notes, and snippets.

@wreiske
Created May 10, 2019 00:16
Show Gist options
  • Save wreiske/b474c57a3597c8f976057a292b6fe498 to your computer and use it in GitHub Desktop.
Save wreiske/b474c57a3597c8f976057a292b6fe498 to your computer and use it in GitHub Desktop.
multi-instance rocket.chat upgrade and restart
# Upstreams
upstream backendChat {
server 127.0.0.1:3000;
server 127.0.0.1:3001;
server 127.0.0.1:3002;
server 127.0.0.1:3003;
}
# HTTPS Server
log_format upstreamlog '[$time_local] $remote_addr - $remote_user - $server_name to: $upstream_addr: $request upstream_response_time $upstream_response_time msec $msec request_time $request_time';
server {
listen 443 ssl http2;
server_name chat.website.com;
client_max_body_size 200M;
access_log /var/log/nginx/rocketchat.access.log upstreamlog;
error_log /var/log/nginx/rocketchat.error.log;
ssl on;
ssl_password_file /etc/nginx/certs/passfile;
ssl_certificate /etc/nginx/certs/cert.crt;
ssl_certificate_key /etc/nginx/certs/key.key;
ssl_prefer_server_ciphers on;
ssl_protocols TLSv1.1 TLSv1.2 TLSv1.3;
ssl_ciphers EECDH+aRSA+AESGCM:EECDH+aRSA+SHA256:EECDH+aRSA+SHA384:EECDH:ECDH+AES128:ECDH+AESGCM:ECDH+AES256:ECDH:EDH+aRSA:RSA+AESGCM:RSA+AES:CAMELLIA128:CAMELLIA256:!eNULL:!aNULL:!SEED:!PSK:!MD5:!LOW:!EXP:!ECDSA:!DSS:!RC4:!DH;
location /packages {
root /opt/Rocket.Chat/programs/web.browser; # this should point at the content from the public folder
access_log off;
expires max;
add_header Pragma public;
add_header Cache-Control "public";
}
location ~* "^/[a-z0-9]{40}\.(css|js)$" {
root /opt/Rocket.Chat/programs/web.browser;
access_log off;
expires max;
}
location / {
sub_filter '<head>' '<head><!-- EXECUTED ON $http_host -->';
sub_filter_types *;
sub_filter_once off;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forward-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forward-Proto http;
proxy_set_header X-Nginx-Proxy true;
proxy_redirect off;
proxy_pass http://backendChat/;
}
}
[Unit]
Description=The Rocket.Chat server
After=network.target remote-fs.target nss-lookup.target nginx.target mongod.target
[Service]
ExecStart=/usr/local/bin/node /opt/Rocket.Chat/main.js
StandardOutput=syslog
StandardError=syslog
SyslogIdentifier=rocketchat
User=root
Environment=LD_PRELOAD=/opt/Rocket.Chat/programs/server/npm/node_modules/sharp/vendor/lib/libz.so
Environment=MONGO_URL=mongodb://rocket:password@localhost:27017/rocketchat?replicaSet=my_mongodb_0&authSource=admin
Environment=MONGO_OPLOG_URL=mongodb://rocketoplog:password@localhost:27017/local?replicaSet=my_mongodb_0&authSource=admin
Environment=ROOT_URL=https://chat.website.com
Environment=PORT=3000
Restart=always
[Install]
WantedBy=multi-user.target
[Unit]
Description=The Rocket.Chat server
After=network.target remote-fs.target nss-lookup.target nginx.target mongod.target
[Service]
ExecStart=/usr/local/bin/node /opt/Rocket.Chat/main.js
StandardOutput=syslog
StandardError=syslog
SyslogIdentifier=rocketchat
User=root
Environment=LD_PRELOAD=/opt/Rocket.Chat/programs/server/npm/node_modules/sharp/vendor/lib/libz.so
Environment=MONGO_URL=mongodb://rocket:password@localhost:27017/rocketchat?replicaSet=my_mongodb_0&authSource=admin
Environment=MONGO_OPLOG_URL=mongodb://rocketoplog:password@localhost:27017/local?replicaSet=my_mongodb_0&authSource=admin
Environment=ROOT_URL=https://chat.website.com
Environment=PORT=%I
Restart=always
[Install]
WantedBy=rocketchat.service
cd /opt
rm -rf Rocket.Chat.old
mv Rocket.Chat Rocket.Chat.old
echo "Downloading latest Rocket.Chat build"
curl -L https://releases.rocket.chat/latest/download -o rocket.chat.tar.gz
tar zxvf rocket.chat.tar.gz
mv bundle Rocket.Chat
cd Rocket.Chat/programs/server
echo "Running NPM install.."
npm install
cd ../..
echo "Removing rocket.chat.tar.gz"
rm /opt/rocket.chat.tar.gz
echo "Killing old rocket.chat services..."
systemctl stop rocketchat.service
systemctl stop rocketchat@3001.service
systemctl stop rocketchat@3002.service
systemctl stop rocketchat@3003.service
echo "Starting rocket.chat"
systemctl start rocketchat.service
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment