-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathpostinstall
executable file
·70 lines (65 loc) · 1.65 KB
/
postinstall
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#!/bin/bash
if ! [ `which rethinkdb` ]
then
echo -e "\e[01;31mERROR: RethinkDB is not installed\e[0m"
echo "Please go to http://rethinkdb.com/docs/install/ for downloads and installation instructions."
exit
fi
echo "Generating cert files...";
openssl req -x509 -nodes -batch -newkey rsa:2048 -keyout ./horizon-key.pem -out ./horizon-cert.pem -days 365 &&
mkdir -p /etc/trailbot-vault 2> /dev/null &&
mv ./horizon-*.pem /srv/ -f &&
(
cat > /etc/trailbot-vault/horizon.toml <<-EOM
project_name = "trailbot_vault"
key_file = "/srv/horizon-key.pem"
cert_file = "/srv/horizon-cert.pem"
allow_anonymous = true
token_secret = "$(head -c56 /dev/urandom | base64)"
start_rethinkdb = true
serve_static = "./dist"
bind = ["0.0.0.0"]
port = 8443
debug = true
EOM
) &&
cp ./schema.toml /etc/trailbot-vault/ &&
(
if [ `which systemd` ]
then
cat > /etc/systemd/system/trailbot-vault.service <<- EOM
[Unit]
Description=Trailbot Vault
Wants=network-online.target
After=network.target network-online.target
[Service]
ExecStart=$(pwd)/start
ExecStop=$(pwd)/stop
Restart=always
User=root
Group=root
WorkingDirectory=$(pwd)
[Install]
WantedBy=multi.user.target
EOM
systemctl enable trailbot-vault
else
cat > /etc/init/trailbot-vault.conf <<- EOM
#!upstart
description "Trailbot Vault"
respawn
start on (local-filesystems and net-device-up IFACE!=lo)
stop on shutdown
script
chdir $(pwd)
exec $(pwd)/start
end script
EOM
chmod +x /etc/init/trailbot-vault.conf
fi
) &&
echo "Setting schema...";
mkdir .hz 2> /dev/null;
hz set-schema /etc/trailbot-vault/schema.toml --force --config /etc/trailbot-vault/horizon.toml &&
service trailbot-vault start &&
echo "Trailbot Vault is now up and running!"