Commit 4acae95a authored by tomogoma's avatar tomogoma

initial commit

parents
etc/**
usr/**
var/**
.idea
**.iml
# Cockroach DB Installer #
An auto-installer of cockroach DB Beta as a service in linux systems
## Install ##
Currently only systemd is supported
First download the cockroachdb tarball from https://binaries.cockroachdb.com or search for it in the website: https://www.cockroachlabs.com
```
$ git clone https://github.com/tomogoma/cockroach-installer
$ cd roach-installer
$ ./systemdInstaller.sh /path/to/downloaded/cockroach-tarbal.tz
```
## Install outcome ##
Start
`$ systemctl start cockroach.service`
Stop
`$ systemctl stop cockroach.service`
Check status
`$ systemctl status cockroach.service`
Install Directories
The cockroach db binary is installed into
`/usr/local/cockroachdb`
The db certs are located at
`/usr/local/cockroachdb/certs`
The data dir is located at
`/var/data/cockroachdb`
A systemd service unit file is created at
`/etc/systemd/system/cockroach.service`
## Uninstall ##
`$ cd /path/to/roach-installer`
`$ ./systemdUninstaller.sh`
## Configure a dependent systemd service ##
If your service depends on cockroach db, in the service’s unit file add the following lines:
```
[Unit]
...
After=cockroach.service
Requires=cockroach.service
...
```
## Get your app’s postgresql driver url ##
1. Start the cockroachdb service as described in Install Outcome
1. Check the status of the service as described in Install Outcome
1. Copy the url you see under the sql flag: e.g:
`sql: postgresql://[email protected]:26257?sslcert=%2FUsers%2F…`
Will yield the url:
`postgresql://[email protected]:26257?sslcert=%2FUsers%2F…`
[Unit]
Description=Cockroach db auto starter
[Service]
ExecStart=/usr/local/bin/cockroach start --ca-cert=/etc/cockroachdb/certs/ca.cert --cert=/etc/cockroachdb/certs/node.cert --key=/etc/cockroachdb/certs/node.key --store=/var/data/cockroachdb/ --port=26257 --http-port=7005
ExecStop=/usr/local/bin/cockroach quit --ca-cert=/etc/cockroachdb/certs/ca.cert --cert=/etc/cockroachdb/certs/root.cert --key=/etc/cockroachdb/certs/root.key --http-port=7005
SyslogIdentifier=cockroachdb
[Install]
WantedBy=multi-user.target
#!/bin/bash
APP_DIR="/usr/local/bin"
SYSTEMD_DIR="/etc/systemd/system"
DATA_DIR="/var/data/cockroachdb"
ETC="/etc/cockroachdb"
CERT_DIR="$ETC/certs"
function usage {
printf "Cockroachdb Installer\nUsage: $1 /path/to/cockroachdb.tgz [user]\n"
echo "download cockroachdb tgz file from https://www.cockroachlabs.com"
}
function extractRoach {
mkdir -p "$APP_DIR" || exit 1
tar -xzf "$1" || exit 1
}
function setInstallDirs {
filename=$(basename "$1")
extension="${filename##*.}"
filename="${filename%.*}"
mv -f "$filename/cockroach" "$APP_DIR/cockroach" || exit 1
rm -r "$filename"
mkdir -p "$DATA_DIR" || exit 1
}
function installCerts {
mkdir -p "$CERT_DIR" || exit 1
pushd "$CERT_DIR" || exit 1
"$APP_DIR/cockroach" cert create-ca --ca-cert=ca.cert --ca-key=ca.key || exit 1
"$APP_DIR/cockroach" cert create-node localhost $(hostname) --ca-cert=ca.cert --ca-key=ca.key --cert=node.cert --key=node.key || exit 1
"$APP_DIR/cockroach" cert create-client root --ca-cert=ca.cert --ca-key=ca.key --cert=root.cert --key=root.key || exit 1
popd
}
function changePerms {
usr=$1
if [ -z "$usr" ];then
return
fi
chown -R "$usr:$usr" "$ETC" #remove the need for sudo when accessing cockroachdb
}
function installService {
mkdir -p "$SYSTEMD_DIR" || exit 1
cp -f cockroach.service "$SYSTEMD_DIR" || exit 1
systemctl enable "$SYSTEMD_DIR/cockroach.service" || exit 1
}
#create cconnect script for easier access to the sql console
function outputConnectUtil {
touch "/usr/local/bin/cconnect"
echo "cockroach sql --ca-cert=/etc/cockroachdb/certs/ca.cert --cert=/etc/cockroachdb/certs/root.cert --key=/etc/cockroachdb/certs/root.key" > "/usr/local/bin/cconnect"
chmod +x "/usr/local/bin/cconnect"
}
## Begin processing script
if [ -z "$1" ]; then
usage $0
exit 1
fi
./systemdUninstaller.sh
echo "Installing..."
extractRoach $1
setInstallDirs $1
installCerts
changePerms $2
installService
outputConnectUtil
echo "Done!"
exit 0
#!/bin/bash
APP_FILE="/usr/local/bin/cockroach"
ETCD_DIR="/etc/cockroachdb"
CERT_DIR="$ETCD_DIR/certs"
SYSTEMD_FILE="/etc/systemd/system/cockroach.service"
DATA_DIR="/var/data/cockroachdb/"
echo "Uninstalling..."
if [ -f "$APP_FILE" ]; then
systemctl stop cockroach.service >/dev/null
rm -rf "$APP_FILE"
fi
if [ -f "$SYSTEMD_FILE" ]; then
rm -f "$SYSTEMD_FILE"
fi
if [ -d "$ETCD_DIR" ]; then
rm -rf "$ETCD_DIR"
fi
if [ -f "/usr/local/bin/cconnect" ]; then
rm "/usr/local/bin/cconnect"
fi
echo "Data at $DATA_DIR not removed, run 'rm $DATA_DIR' if you wish to delete"
echo "Done!"
`systemctl daemon-reload`
exit 0
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment