2

CodiMD is great for collaborative work, but I would like to use it for personal notes on my laptop (Ubuntu 18.04), configured so that it works without an internet connection and uses as few resources as possible. The manual installation seems like a good starting point, but the instructions assume knowledge of Node, npm, database admin, etc. which I am not familiar with. I don't need TLS, user authentication, or connections to cloud services.

This is what I have so far:

sudo apt install -y nodejs npm sqlite3
sudo npm install -g node-gyp
sudo npm install -g yarn
# broken: sudo apt install -y libssl-dev
git clone https://github.com/codimd/server.git
cd server
sudo bin/setup
sudo vi config.json .sequelizerc
# in vi, copy 4 "db" lines from "development" to "production"
# in vi, disable "hsts" and "csp"
# in vi, what should go in the "url" line?
# in vi, what else needs modificaiton?
sudo npm run build
sudo npm start --production  # fails:  sequelize db:migrate && node app.js
# what is the best way to start CodiMD at boot?

In short, I'm looking for detailed instructions for seting up a minimum 1-user CodiMD on Ubuntu.

3
  • For the URL you could use an alias via the /etc/hosts file as the.name.you.want to 127.0.0.1 for example, or use localhost (it's already an alis to 127.0.0.1). Also give the full output of the fail please. May 14, 2019 at 12:21
  • Thanks. As it turns out, the "url" is for the database, so "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.
    – bitinerant
    May 14, 2019 at 12:49
  • I'd say you better not run it as root. You better have the sqlite file somewhere in your home for example. May 14, 2019 at 13:30

1 Answer 1

3

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.

  • install LXD:
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
  • install CodiMD:
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'
  • install PostgreSQL:
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
  • build:
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'
  • add user accounts:
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
  • restart and connect:
lxc stop codimd; sleep 5; lxc start codimd
firefox "https://$MYURL"
  • in Firefox, accept the self-signed certificate and sign in
2
  • How have you found CodiMD for your personal notes? I have it installed but it seems better suited to transient notes rather than keeping a sort of wiki or library of notes.
    – Jeff
    Apr 25, 2020 at 18:30
  • @Jeff - I still love it. It's the core of my to-do list and huge database of notes and how-to's. But I've added 'search'; see above.
    – bitinerant
    Apr 26, 2020 at 7:32

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .