This project contains the files used to serve TicTrainer™ via node.js. TicTrainer™ is a web tool meant to help people build their ability to fight their tics. It was built to implement the RE-ERP strategy proposed by Kevin Black (see description here).
Also included now is TicTimer Web, which runs on the same server and is accessed at webroot/tsp/. TicTimer is a program designed to automate record keeping and reward delivery during tic suppression research. This web-based version of TicTimer allows for sessions to be performed remotely and without the bulky token dispenser hardware that was used with the previous version of TicTimer. See description here.
- Download this git repository to the server
$ git clone --depth 1 -b master https://github.com/jonkb/TicTrainer-node.git
- alternatively, download and scp those files
- Install mysql 8.0 Guide
- Install node.js 12 Guide Better? Guide
- Run
$ npm install
From the /src folder to install dependencies from package.json
- Run
- Set up mysql database
- If restoring from a backup, do that and skip the following. Backup/Restore Guide
- Start the mysql database if not already running
$ mysqld
- Log in as root
$ mysql -u root -p
- Create the nodejs user and the tictrainer database as described in Project_Files/sql/setup.sql
- Can copy and paste everything except the password
- Execute the other .sql files in that folder. Order matters Guide
- Create accounts tables (admins.sql, trainers.sql, users.sql)
- Create links table (links.sql)
- Create survey_state table (survey_state.sql)
- Create session index table (sessions.sql)
- Add the keys.json file to the parent directory of the git repository
keys.json:
{
"sql": "[mysql_password]",
"ckses": "[cookie_key]"
}
- Alter settings if needed (src/settings.json)
- A clear description of each of the settings is in the file src/settings_description.txt
- The constant "testing" should be set as false for the server to use the normal ports (80 and 443). Otherwise, it will run on port 8888.
- Be sure to keep the proper formatting of the json file.
- Hosting-specific things (This is not generalizable, but this is how we did it)
- Open ports 80 and 443 in the firewall settings
- Set up certbot for Let's Encrypt. Guide here, but don't follow whole thing
$ yum install epel-release
$ yum install certbot
- Get certificate from Let's Encrypt.
sudo certbot certonly --force-renewal -d tictrainer.com -d www.tictrainer.com --standalone --cert-name tictrainer.com --preferred-challenges http
- Port 80 needs to be free (i.e. don't have the server running)
- The domain name needs to be set up to redirect to the server.
- Create crontab jobs
- Let's Encrypt auto-renewing certificate:
$ sudo crontab -e
32 04 3 1,3,5,7,9,11 * /home/ec2-user/TicTrainer-node/util_scripts/renew_cert.sh
- This auto-renews the certificate every odd month. On the inside, this script runs the same command from 4.iii.a
- FreeDNS update IP:
$ crontab -e
- If your server IP address is changing unpredictably:
3,8,13,18,23,28,33,38,43,48,53,58 * * * * sleep 22 ; curl -s http://sync.afraid.org/u/xRVpcm1UCjJvfgRsjJsTHT37/ >> /tmp/freedns_tictrainer_mooo_com.log 2>/dev/null
- If your server IP address is more stable:
21 2,14 * * * sleep 17; curl -s http://sync.afraid.org/u/xRVpcm1UCjJvfgRsjJsTHT37/ >> /tmp/freedns_tictrainer_mooo_com.log 2>/dev/null
- If your server IP address is changing unpredictably:
- Let's Encrypt auto-renewing certificate:
Run the script /util_scripts/runTT.sh (making sure that the pathnames are correct there)
or
- cd to the "/src" directory.
path/to/Tt_repository/src$ sudo nohup node server.js &> logs/log.txt &
- "sudo" because it needs to be run as root to use ports 80 and 443
- "nohup" lets the server continue running after closing the ssh session
- "&>" pipes output to log.txt