Skip to content
This repository has been archived by the owner on Jul 25, 2024. It is now read-only.

Server Setup

Nick Wu edited this page Jun 9, 2019 · 4 revisions

Digital Ocean server's IP: 46.101.83.66

New User

Based on the Digital Ocean article Initial Server Setup with Ubuntu 16.04.

  1. Create a new user

    $ adduser <username> 
  2. Give the user root privileges

    $ usermod -aG sudo <username>
  3. Password authentication is disabled so public key authentication is required. Copy your public key to TryLinks Server either using ssh-copy-id or manually copying ~/.ssh/id_rsa.pub into ~/.ssh/authorized_keys file on the remote server (details in the article on the top)

Apache Server

More commands and details can be found in the Digital Ocean article How To Install the Apache Web Server on Ubuntu 16.04

To install Apache on Ubuntu:

$ sudo apt-get update
$ sudo apt-get install apache2

One could create a separate Apache Virtual Host for TryLinks, however, it is not necessary as the server hosts only one website. Moreover, the server does not have any associated domain name yet.

Firewall

Firewalls are managed with UFW (Uncomplicated Firewall).

  1. Allow SSH connections

    $ sudo ufw allow OpenSSH
  2. Allow HTTP and HTTPS connections

    $ sudo ufw allow 'Apache Full'
  3. Allow TCP connections to TryLinks Node Server which will run on port 5000

    $ sudo ufw allow 5000/tcp
  4. In the tutorials the server will run Links server on some random empty port, which we do not know in advance. Therefore, incoming request to any port above 1023 need to be allowed

    $ sudo ufw allow 1024:49151/tcp

Client-side Code

The server needs to serve index.html file for any URL requested as routing is handled inside the Dart application. See Angular Guide on Deployment.

  1. Apache needs to be allowed to perform overriding. Open /etc/apache2/apache2.conf file, find the following snippet

    <Directory /var/www/>
        ...
        AllowOverride None
        ...
    </Directory> 
    

    and change AllowOverride None to AllowOverride All.

  2. Activate the Apache mod_rewrite module and restart the Apache service

    $ sudo a2enmod rewrite
    $ systemctl restart apache2
  3. Clone the TryLinks-Client directory.

    $ git clone https://github.com/links-lang/TryLinks-Client.git
  4. Build the Dart TryLinks-Client app (on a local machine)

    $ cd TryLinks-Client-v2 && npm install && ng build --prod
  5. Copy the content of a newly created ./dist directory to the website root directory on the server, /var/www/html. As stated before, no new virtual host was created as there are no more websites on that server, hence, the default is used.

Server-side Code

The server needs to be running constantly and restart itself in case it exits unexpectedly. This can be achieved with systemd

Systemd configuration file, trylinks-server.service, is located in /lib/systemd/system and looks as follows:

[Unit] 
Description=Run TryLinks node.js server 
After=network.target 

[Service]
Environment=OCAMLRUNPARAM=""
Type=simple
User=arek
WorkingDirectory=/home/arek/TryLinks-Server/ 
ExecStart=/usr/bin/npm start 
Restart=on-failure 

[Install] 
WantedBy=multi-user.target 

Environment parameter removes stack traces in error messages (Links 0.7.3 prints them by default).

Load the new configuration with

$ sudo systemctl daemon-reload

and start the service by executing

$ sudo systemctl start trylinks-server

To make the application start up when the server boots, run

$ sudo systemctl enable trylinks-server

Optionally, to see the log of the service, run

$ sudo journalctl -u trylinks-server --since "<time>"

<time> can be a phrase like today or 1 hour ago

Database

TryLinks uses PostgreSQL database. The database configuration is detailed in the wiki page TryLinks Database.

Links Installation

Links is installed as specified in the links-lang's wiki page here.

$ sudo apt install -y m4 libpq-dev opam
$ opam init -a
$ opam switch 4.06.0
$ eval `opam config env`
$ opam install –y links links-postgresql

If the last command throws an error, follow the suggestion, i.e. run command below and then try installing links again

$ opam depext conf-pkg-config.1.1 

shell = spawn('linx') in /api/interactive.js throws an error as it cannot find linx. To fix this create a link from where linx is installed (e.g. /home/arek/.opam/4.06.0/bin/linx) to /usr/local/bin/.

sudo ln -s /home/arek/.opam/4.06.0/bin/linx /usr/local/bin/ 

Currently, TryLinks-Server is located in arek's home directory and systemd config specifies this is the user arek who runs trylinks-server service. Consequently, arek user is the creator of all links processes started through TryLinks. In future, we might want to create a separate user, e.g. trylinks, with limited privileges, that is responsible for keeping TryLinks-Server code, running it and spawning new links processes upon the application users' compilation requests.

Clone this wiki locally