Commit d79037ac by source_reader

added first use and cleanup script

parent 427424aa
#!/bin/bash
set -e
echo "MAKE SURE TO delete joule database and referesh installation on systemd!!"
userdel ubuntu
rm -rf /home/ubuntu
echo "1] Remove the databases"
sudo -u postgres psql <<END_OF_SQL
DROP DATABASE joule;
DROP DATABASE rails;
END_OF_SQL
echo "3] Erasing module and stream configurations"
rm /etc/joule/module_configs/*.conf
rm /etc/joule/stream_configs/*.conf
echo "4] Removing default key material"
rm /etc/joule/security/*
rm /opt/api/config/secrets.yml
echo "1] Creating PostgreSQL passwords"
RAILS_PWD="$(openssl rand -hex 8)"
JOULE_PWD="$(openssl rand -hex 8)"
sudo -u postgres psql <<END_OF_SQL
DROP DATABASE IF EXISTS joule;
DROP DATABASE IF EXISTS rails;
CREATE DATABASE joule;
CREATE DATABASE rails;
GRANT ALL PRIVILEGES ON DATABASE rails TO rails;
GRANT ALL PRIVILEGES ON DATABASE joule TO joule;
ALTER ROLE rails WITH PASSWORD '$RAILS_PWD';
ALTER ROLE joule WITH PASSWORD '$JOULE_PWD';
END_OF_SQL
echo "1] Creating Joule keys"
rm -f /etc/joule/main.conf
joule admin initialize --dsn joule:$JOULE_PWD@localhost:5432/joule
service joule restart
echo "2] Creating rails secret"
cd /opt/api
KEY="$(bundle exec rake secret)"
cd -
cat > /opt/api/config/secrets.yml <<EOF
production:
secret_key_base: $KEY
EOF
echo "3] Updating rails database.yml"
cat > /opt/api/config/database.yml <<EOF
production:
adapter: postgresql
database: rails
host: localhost
pool: 5
encoding: unicode
username: rails
password: $RAILS_PWD
EOF
echo "4] Migrating rails database"
export RAILS_ENV=production
cd /opt/api
#sudo -E -u rails bundle exec rake db:migrate
cd -
echo "5] Restarting Apache"
apache2ctl restart
......@@ -22,7 +22,7 @@ class rails_api {
provider => git,
source => 'https://git.wattsworth.net/wattsworth/control-api.git',
require => User['rails'],
notify => [Exec['bundle_install','db_migrate','local_bootstrap'], File['/opt/api/config/database.yml']],
notify => [Exec['bundle_install','db_migrate'], File['/opt/api/config/database.yml']],
owner => 'rails'
}
......@@ -30,7 +30,7 @@ class rails_api {
source => 'puppet:///modules/rails_api/database.yml',
owner => 'rails',
group => 'rails',
mode => '0644',
mode => '0640',
require => Vcsrepo['/opt/api']
}
......@@ -38,7 +38,7 @@ class rails_api {
content => template('rails_api/secrets.yml.erb'),
owner => 'rails',
group => 'rails',
mode => '0644',
mode => '0640',
require => Vcsrepo['/opt/api']
}
# remove bootsnap because it crashes on RPi's
......@@ -86,13 +86,13 @@ class rails_api {
}
#create initial models in the database
exec {'local_bootstrap':
command => 'bundle exec rake local:bootstrap',
cwd => '/opt/api',
environment => ['RAILS_ENV=production'],
path => ['/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin'],
user => 'rails',
refreshonly => true,
require => [Vcsrepo['/opt/api'],Package['bundler'],Exec['db_migrate']]
}
#exec {'local_bootstrap':
# command => 'bundle exec rake local:bootstrap',
# cwd => '/opt/api',
# environment => ['RAILS_ENV=production'],
# path => ['/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin'],
# user => 'rails',
# refreshonly => true,
# require => [Vcsrepo['/opt/api'],Package['bundler'],Exec['db_migrate']]
#}
}
......@@ -8,5 +8,5 @@ r10k puppetfile install --moduledir=./forge_modules
# run puppet
export FACTER_PLATFORM="rpi"
puppet apply --verbose --debug --modulepath=./forge_modules:./modules site.pp
puppet apply --verbose --modulepath=./forge_modules:./modules site.pp # --debug
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 sign in to comment