7/8/2017 - 2:38 PM

how to install and setup sharelatex on ubuntu 16.04 (for my personal documentation, used on a gcloud vm)

how to install and setup sharelatex on ubuntu 16.04 (for my personal documentation, used on a gcloud vm)

# -*- coding: utf-8 -*-
import urllib2
import time


urllib2.urlopen("http://dynamicdns.park-your-domain.com/update?host=%s&domain=%s&password=%s" % ("$subdomain", "$domain", "$your_key"))
sleep 10s
service mongodb start
sleep 10s
service redis-server start
sleep 20s

docker start sharelatex

One liner to stop / remove all of Docker containers:

docker stop $(docker ps -a -q) docker rm $(docker ps -a -q)

Create new user:



database and stuff

sudo apt-get update
sudo apt-get install -y redis-server
sudo apt-get install -y mongodb


sudo apt-get install -y apt-transport-https ca-certificates
sudo apt-key adv --keyserver hkp://p80.pool.sks-keyservers.net:80 --recv-keys 58118E89F3A912897C070ADBF76221572C52609D
sudo vi /etc/apt/sources.list.d/docker.list
--> add: deb https://apt.dockerproject.org/repo ubuntu-trusty main (14.04)
--> add: deb https://apt.dockerproject.org/repo ubuntu-xenial main (16.04)
sudo apt-get update
sudo apt-get install -y docker-engine
sudo service docker start
sudo docker run hello-world


get docker internal ip

sudo docker run -d -p 80:80 nginx --name nginx
ip addr show docker0
sudo docker stop nginx

adjust mongodb and redis

sudo vi /etc/mongodb.conf
--> change: bind_ip =

sudo vi /etc/redis/redis.conf
--> change: bind

sudo service mongodb restart
sudo service redis-server restart

run sharelatex docker container

Be careful about the inner and outer port. Use 126 mailbox as SMTP server.

docker run -d \ -v ~/sharelatex_data:/var/lib/sharelatex \ --env SHARELATEX_EMAIL_FROM_ADDRESS="username@126.com" \ --env SHARELATEX_EMAIL_REPLY_TO="username@126.com" \ --env SHARELATEX_EMAIL_SMTP_HOST="smtp.126.com" \ --env SHARELATEX_EMAIL_SMTP_PORT=25 \ --env SHARELATEX_EMAIL_SMTP_SECURE=false \ --env SHARELATEX_EMAIL_SMTP_USER="username" \ --env SHARELATEX_EMAIL_SMTP_PASS="userpassword" \ --env SHARELATEX_EMAIL_SMTP_TLS_REJECT_UNAUTH=true \ --env SHARELATEX_EMAIL_SMTP_IGNORE_TLS=true \ --env SHARELATEX_CUSTOM_EMAIL_FOOTER="<div>This system is run by smart grid lab in XJTU </div> <div> If you have any questions please look at our faq <a href='https://www.xjtu.edu.cn'>here</a></div>" \ -p 5000:80 \ --name=sharelatex \ sharelatex/sharelatex

Close firewall if failed to create admin user.

sudo ufw disable

sudo docker exec sharelatex /bin/bash -c "cd /var/www/sharelatex/web; grunt create-admin --email joe@example.com"
sudo docker exec sharelatex tlmgr install scheme-full

sudo ufw enable

change environment variables after container has been created

Create a file with the name of the environment variable to set, the content is the variable value. Then copy the file to the docker container. For example to set SHARELATEX_SITE_URL (assuming the file is in the current working directory):

sudo docker cp ./SHARELATEX_SITE_URL sharelatex:/etc/container_environment/

crontab for boot scripts

sudo crontab -e --> add: PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/opt/aws/bin:/root/bin
--> add: @reboot /startup.sh >> /startupscript.log 2>&1
--> add: @reboot python /update_dns.py

add file update_dns.py to /update_dns.py
add file startup.py to /startup.sh
sudo chmod +x /startup.sh