2017-11-23 05:49:12 +00:00
|
|
|
---
|
|
|
|
title: Bitwarden
|
|
|
|
---
|
|
|
|
|
|
|
|
### 1. Prepare the environment
|
2017-11-23 05:57:41 +00:00
|
|
|
1.1 Create custom webapp called `warden` in the control panel
|
|
|
|
1.2 Configure Ruby 2.4 by editing `~/.bash_aliases` and adding these aliases
|
2017-11-23 05:49:12 +00:00
|
|
|
```sh
|
|
|
|
alias ruby=ruby2.4
|
|
|
|
alias gem=gem2.4
|
|
|
|
```
|
2017-11-23 05:57:41 +00:00
|
|
|
1.3 Install the bundle gem
|
|
|
|
```sh
|
|
|
|
gem install bundle
|
|
|
|
```
|
2017-11-23 05:49:12 +00:00
|
|
|
### 2. Install Bitwarden Ruby into the directory
|
|
|
|
```sh
|
|
|
|
cd ~/webapps
|
|
|
|
clone https://github.com/jcs/bitwarden-ruby.git warden
|
|
|
|
cd warden
|
|
|
|
bundle install
|
|
|
|
```
|
2017-11-23 05:57:41 +00:00
|
|
|
### 3. Start / Stop / Restart and Cron scripts
|
|
|
|
3.1 `Start` script where `$PORT` is the port of the custom webapp
|
|
|
|
```sh
|
|
|
|
#!/bin/sh
|
|
|
|
pgrep -f "ruby2.4 /home/tanshu/gems/bin/rackup -p $PORT config.ru" > /dev/null 2>&1 && exit 0
|
|
|
|
mkdir -p /home/tanshu/webapps/warden/run
|
|
|
|
cd /home/tanshu/webapps/warden
|
|
|
|
nohup env RACK_ENV=production bundle exec rackup -p $PORT config.ru > /dev/null 2>&1 &
|
|
|
|
sleep 3
|
|
|
|
pgrep -f "ruby2.4 /home/tanshu/gems/bin/rackup -p $PORT config.ru" > /home/tanshu/webapps/warden/run/ruby.pid
|
2017-11-23 06:00:15 +00:00
|
|
|
```
|
|
|
|
3.2 `Stop` script where `$PORT` is the port of the custom webapp
|
|
|
|
```sh
|
|
|
|
#!/bin/sh
|
|
|
|
/usr/bin/pkill -f "ruby2.4 /home/tanshu/gems/bin/rackup -p $PORT config.ru" && rm -f /home/tanshu/webapps/warden/run/ruby.pid
|
|
|
|
```
|
|
|
|
3.3 `Restart` script
|
2017-11-23 06:00:53 +00:00
|
|
|
```sh
|
2017-11-23 06:00:15 +00:00
|
|
|
#!/bin/bash
|
|
|
|
$HOME/webapps/warden/bin/stop
|
|
|
|
sleep 3
|
|
|
|
$HOME/webapps/warden/bin/start
|
|
|
|
```
|
|
|
|
3.4 Edit crontab using `export VISUAL=nano; crontab -e` and add the following line
|
|
|
|
```sh
|
|
|
|
*/20 * * * * ~/webapps/warden/bin/start
|
2017-11-23 06:01:30 +00:00
|
|
|
```
|
|
|
|
### 4. Backup your database
|
2017-11-25 06:40:28 +00:00
|
|
|
#### Install gdrive
|
|
|
|
Install gdrive to backup the database to google account in case of data loss at webfaction
|
|
|
|
Go to `https://github.com/prasmussen/gdrive` and download `gdrive-linux-x64` in `~/bin/`
|
|
|
|
```sh
|
|
|
|
wget -o ~/bin/gdrive $URL_FOR_GDRIVE_LINUX_X64_BINARY
|
|
|
|
```
|
|
|
|
Make it executable `chmod +x ~/bin/gdrive`
|
2018-03-07 12:06:17 +00:00
|
|
|
|
|
|
|
#### Setup local directory for upload
|
|
|
|
|
|
|
|
```sh
|
|
|
|
mkdir -p ~/Data/warden
|
|
|
|
cd ~/Data/warden
|
|
|
|
ln -s ~/webapps/warden/db/production.sqlite3 production.sqlite3
|
|
|
|
```
|
|
|
|
|
2017-11-25 06:40:28 +00:00
|
|
|
#### Configure Google Drive
|
2017-11-25 06:44:35 +00:00
|
|
|
Link your gdrive to the account by running `gdrive list` and following the instructions.
|
|
|
|
|
2017-11-25 06:40:28 +00:00
|
|
|
Create a folder called `Bitwarden` and get its id by running `gdrive list`.
|
2017-11-25 06:44:48 +00:00
|
|
|
|
2017-11-26 04:18:01 +00:00
|
|
|
Create upload script named `bw.sh` in the home directory and make it executable `chmod +x ~/bw.sh`
|
2017-11-25 06:45:15 +00:00
|
|
|
```sh
|
2018-03-07 12:06:17 +00:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
cd ~/Data/warden
|
|
|
|
if sha512sum --status --check production.sha512sum;
|
|
|
|
then
|
|
|
|
echo "File already uploaded. No update needed"
|
|
|
|
else
|
|
|
|
echo "Files are different. Uploading"
|
2018-03-07 12:07:33 +00:00
|
|
|
~/bin/gdrive upload --parent $FOLDER_ID --name production_$(date +%F-%H:%M).sqlite3 ~/Data/warden/production.sqlite3
|
2018-03-07 12:06:17 +00:00
|
|
|
sha512sum production.sqlite3 > production.sha512sum
|
|
|
|
fi
|
2017-11-25 06:45:15 +00:00
|
|
|
```
|
|
|
|
|
2017-11-25 06:40:28 +00:00
|
|
|
#### Automate Backups
|
|
|
|
Edit crontab using `export VISUAL=nano; crontab -e` and add the following line
|
|
|
|
```sh
|
2017-11-26 04:18:01 +00:00
|
|
|
0 1 * * * ~/bw.sh
|
2017-11-25 06:40:28 +00:00
|
|
|
```
|