└── readme.md
/readme.md:
--------------------------------------------------------------------------------
1 | # How to install Nightscout on Linux
2 | ## Table of contents
3 | * [Why yet another tutorial for installing Nightscout?](#introduction)
4 | * [Before we get started](#before-we-get-started)
5 | * [Installation and configuration](#installation-and-configuration)
6 | * [Install required packages](#install-required-packages)
7 | * [Configure MongoDB](#configure-mongodb)
8 | * [Download and install Nightscout](#install-nightscout)
9 | * [Run Nightscout](#run-nightscout)
10 | * [Enable SSL support](#enable-ssl)
11 | * [Create a service](#create-service)
12 |
13 |
14 | ## Why yet another tutorial for installing Nightscout?
15 |
16 | When I found out about [Nightscout](http://www.nightscout.info/) I felt like drowning by the huge amount of info pages out there on the Internet. I read a lot about the existing solutions with [Azure](http://www.azure.com/), [Hiroku](https://www.heroku.com/) or [Vagrant](https://www.vagrantup.com/). The reason I don't use these is that I have been running my own private (web) server for a long time and therefore I wanted to install it on my existing server. Thus I became interested in how to setup Nightscout on Linux. Unfortunately I did not find an article for the setup, so I decided to adapt [this](https://github.com/jaylagorio/Nightscout-on-Windows-Server) installation guide and rewrite it for Linux.
17 |
18 | If you are heading for a quick development setup, you might prefer to use a [docker image](https://github.com/nightscout/nightscout-docker).
19 |
20 |
21 | ## Before we get started
22 |
23 | As I mentioned above, this documentation is based on the docs for [Nightscout on Windows Server](https://github.com/jaylagorio/Nightscout-on-Windows-Server). I am going to show you how to install Nightscout on [Arch Linux](https://www.archlinux.org/). I assume that you have installed Linux on your system already.
24 |
25 | **For those who are using a different Linux distribution:**
26 |
27 | The instructions in the examples may differ from other Linux distributions like Debian/Fedora/OpenSuse. Basically you have to do the same steps but probably with different commands or system tools. I am using the [pacman package manager](https://wiki.archlinux.org/index.php/pacman). In your distribution it may be `apt-get` or `yum`. For service managing I use [systemd](https://wiki.archlinux.org/index.php/Systemd). Your distro might use `init.d`. A detailed comparison of Arch to other Linux distributions can be found [here](https://wiki.archlinux.org/index.php/Arch_compared_to_other_distributions#General).
28 |
29 |
30 |
31 | ## Installation and configuration
32 |
33 |
34 | ### Install required packages
35 | There are a couple of packages that need to be installed:
36 | - [MonboDB](https://wiki.archlinux.org/index.php/MongoDB) and tools
37 | - [git](https://wiki.archlinux.org/index.php/git)
38 | - [Python](https://wiki.archlinux.org/index.php/python)
39 | - [Node.js](https://wiki.archlinux.org/index.php/Node.js_) and npm
40 | - [GNU C++ Compiler](https://www.archlinux.org/packages/core/i686/gcc/)
41 |
42 | ```
43 | # pacman -S mongodb mongodb-tools git python nodejs npm gcc
44 | ```
45 |
46 |
47 | ### Configure MongoDB
48 | After installation, start/enable the `mongodb.service` daemon:
49 | ```
50 | # systemctl enable mongodb.service
51 | # systemctl start mongodb.service
52 | ```
53 | Then create a new database and a new user:
54 | ```
55 | $ mongo
56 | > use Nightscout
57 | > db.createUser({user: "username", pwd: "password", roles:["readWrite"]})
58 | > quit()
59 | ```
60 |
61 |
62 | ### Download and install Nightscout
63 |
64 | Create a folder for your nightscout installation. Then clone the Nightscout repository. If you have your own fork, use the URL to your git repository instead.
65 |
66 | ```
67 | $ cd your/favorite/path/for/nightscout
68 | $ git clone https://github.com/nightscout/cgm-remote-monitor.git
69 | $ cd cgm-remote-monitor
70 | $ npm install
71 | ```
72 |
73 | Finally set up the environment variables. There are [several ways](https://wiki.archlinux.org/index.php/environment_variables#Per_user) to do so. However the easiest way is just to create a startup script for your Nightscout server. Create a new file `start.sh` and open it with an editor of your choice:
74 |
75 | ```
76 | $ nano start.sh
77 | ```
78 | Paste those lines (a detailed description of the variables is [here](https://github.com/jaylagorio/Nightscout-on-Windows-Server#installation-and-configuration)):
79 | ```
80 | #!/usr/bin/bash
81 |
82 | # environment variables
83 | export DISPLAY_UNITS="mg/dl"
84 | export MONGO_CONNECTION="mongodb://username:password@localhost:27017/Nightscout"
85 | export BASE_URL="https://YOUR.WEBPAGE.URL"
86 | export PORT=80
87 | export API_SECRET="YOUR_API_SECRET_HERE"
88 |
89 | export PUMP_FIELDS="reservoir battery status"
90 | export DEVICESTATUS_ADVANCED=true
91 | export ENABLE="careportal iob cob openaps pump bwg rawbg basal"
92 |
93 | export TIME_FORMAT=24
94 |
95 | # start server
96 | node server.js
97 | ```
98 |
99 |
100 | ### Run Nightscout
101 |
102 | You can now run Nightscout by entering `./start.sh`. If you have used a different way to configure the system variables, just type `node server.js` to start the server.
103 |
104 |
105 | ### Enable SSL support
106 |
107 | You can obtain your own trusted SSL certificate at [LetsEncrypt.org](https://letsencrypt.org/).
108 |
109 | First of all, you need to install the `https` package for NodeJS:
110 | ```
111 | $ npm install https
112 | ```
113 |
114 | Enable Nightscout's SSL support by just adding the following environment variables to your start script:
115 | ```
116 | export SSL_KEY=privkey.pem
117 | export SSL_CERT=fullchain.pem
118 | export SSL_CA=fullchain.pem
119 | ```
120 |
121 | Please recognize that I've used the fullchain for both `SSL_CERT` and `SSL_CA`. Before that, I tried it with `SSL_CERT=cert.pem` which later led me to an error in xDrip+:
122 |
123 | ```
124 | Unable to do REST API Download javax.net.ssl.SSLHandshakeException:
125 | java.security.cert.CertPathValidatorException: Trust anchor for certification path not found.
126 | ```
127 |
128 | Setting the `SSL_CERT` to `fullchain.pem` worked for me.
129 |
130 |
131 | ### Create a service
132 |
133 | I recommend using a systemd service which automatically starts Nightscout on system startup. To do so, create ``/etc/systemd/system/nightscout.service`` and paste the following configuration:
134 | ```
135 | [Unit]
136 | Description=Nightscout Service
137 | After=network.target
138 |
139 | [Service]
140 | Type=simple
141 | WorkingDirectory=/your/nightscout/path/cgm-remote-monitor
142 | ExecStart=/your/nightscout/path/cgm-remote-monitor/start.sh
143 |
144 | [Install]
145 | WantedBy=multi-user.target
146 | ```
147 |
148 | Reload systemd:
149 | ```
150 | # systemctl daemon-reload
151 | ```
152 |
153 | Start and enable
154 | ```
155 | # systemctl enable nightscout.service
156 | # systemctl start nightscout.service
157 | ```
158 |
159 | Finally check if the service is running:
160 | ```
161 | # systemctl status nightscout.service
162 | ```
163 |
--------------------------------------------------------------------------------