I have figured this out. I put it in an LXC container for isolation and security. I would welcome advice on better ways of doing these steps.
lxc launch ubuntu:18.04/amd64 codimd
lxc exec codimd -- apt update
lxc exec codimd -- apt install -y nodejs npm sqlite3
lxc exec codimd -- npm install -g node-gyp
lxc exec codimd -- npm install -g yarn
lxc exec codimd -- git clone https://github.com/codimd/server.git
lxc exec codimd -- bash -c 'cd server && bin/setup'
VMIP=$(lxc list codimd -c4 --format=csv |grep -o '^\S*'); echo $VMIP # use this IP below
lxc exec codimd -- vi server/config.json
# in vi, under "production", set "domain" to the IP displayed above
# in vi, copy 4 "db" lines from "development" to "production", add final comma
# in vi, delete 8 "db" lines for "postgres"
# in vi, delete 15 "saml" lines
lxc exec codimd -- vi server/.sequelizerc
# in vi, set "url" to 'sqlite://./db.codimd.sqlite'
lxc exec codimd -- vi server/lib/config/default.js
# in vi, set port to 80
lxc exec codimd -- bash -c 'cd server && npm run build'
#test it: lxc exec codimd -- bash -c 'cd server && npm start --production'
lxc exec codimd -- bash -c '(crontab -l 2>/dev/null; echo @reboot /bin/bash -c \""cd /root/server && npm start --production"\") |sudo crontab'
lxc stop codimd && sleep 3 && lxc start codimd
firefox "http://$VMIP"
Update 2020-04-26: I have come a long way with CodiMD, but still love it. The steps below are my 'new-and-improved' install process. In particular, one should not edit .js
files as I did above, use Postgres instead of SQLite, and https.
Finally, if anyone is interested in a global search feature, I've added it to my CodiMD fork on Github. However, it needs 2 important caveats: it breaks the CodiMD permissions model because it allows any logged-in user to find other users' pages; and I consider it 'alpha' quality (though I've been using it for 7 months without issue).
Here is my updated installation procedure.
sudo apt install -y lxd
sudo lxd init --auto --storage-backend=dir
- create and update container:
lxc launch ubuntu:18.04 codimd
lxc exec codimd -- apt update && lxc exec codimd -- apt upgrade -y
lxc exec codimd -- apt install -y git nodejs npm postgresql
lxc exec codimd -- npm install -g node-gyp
lxc exec codimd -- npm install -g yarn
lxc exec codimd -- git clone https://github.com/codimd/server.git
lxc exec codimd -- bash -c 'cd server && bin/setup'
lxc exec codimd -- sudo -i -u postgres createuser --createdb codimd
lxc exec codimd -- sudo -i -u postgres createdb codimd
lxc exec codimd -- useradd codimd
lxc exec codimd -- mkdir /home/codimd
lxc exec codimd -- chown -R codimd:codimd /home/codimd
lxc exec codimd -- sudo -i -u codimd psql --command='\password codimd' # set password to <pgpass>
lxc exec codimd -- sudo -i -u codimd psql --command='\conninfo' # verify
- generate self-signed TLS certificate (source):
lxc exec codimd -- openssl req -x509 -nodes -days 3650 -newkey rsa:2048 -keyout /etc/ssl/private/codimdselfsigned.key -out /etc/ssl/certs/codimdselfsigned.crt # use defaults except Common Name: $MYURL
lxc exec codimd -- openssl dhparam -dsaparam -out /etc/ssl/dhparam.pem 4096
lxc exec codimd -- bash -c 'cd server && npm run build'
- enable firewall (block outbound internet so we are sure it is not needed):
lxc exec codimd -- ufw enable
lxc exec codimd -- ufw default allow incoming # allow inbound https, ssh
lxc exec codimd -- ufw default deny outgoing
- run once to check for errors (ctrl-c to quit):
#test it: lxc exec codimd -- bash -c 'cd server && npm start --production'
lxc exec codimd -- bash -c "cd server && NODE_ENV=production bin/manage_users --pass $USERPASSW --add $EMAIL1"
lxc exec codimd -- bash -c "cd server && NODE_ENV=production bin/manage_users --pass $USERPASSW --add $EMAIL2"
lxc exec codimd -- bash -c "cd server && NODE_ENV=production bin/manage_users --pass $USERPASSW --add $EMAIL3"
cd /tmp
printf "[Unit]\nDescription=CodiMD collaborative markdown notes\n" >codimd.service
printf "Documentation=https://github.com/codimd/server\nAfter=network.target\nAfter=postgresql.service\n\n" >>codimd.service
printf "[Service]\nType=exec\nRestartSec=2s\nUser=root\nGroup=root\nWorkingDirectory=/root/server\n" >>codimd.service
printf "ExecStart=/usr/bin/npm start --production\nRestart=always\nPrivateTmp=true\nPrivateDevices=true\n\n" >>codimd.service
printf "[Install]\nWantedBy=multi-user.target\n" >>codimd.service
lxc file push codimd.service codimd/lib/systemd/system/codimd.service
lxc exec codimd -- systemctl enable /lib/systemd/system/codimd.service
lxc exec codimd -- systemctl daemon-reload
lxc exec codimd -- systemctl enable codimd
- for debugging, view
log.console()
output via:
lxc exec codimd -- systemctl stop codimd
lxc exec codimd -- bash -c 'cd server && npm start --production'
#... monitor output; ctrl-c to quit
lxc stop codimd; sleep 5; lxc start codimd
lxc stop codimd; sleep 5; lxc start codimd
firefox "https://$MYURL"
- in Firefox, accept the self-signed certificate and sign in
sqlite:///root/server/db.codimd.sqlite
" in my case. After other changes, CodiMD now runs, but there are still major config issues. I'll post here when I learn more.