2 # Copyright (C) The Arvados Authors. All rights reserved.
4 # SPDX-License-Identifier: AGPL-3.0
9 . /usr/local/lib/arvbox/common.sh
10 . /usr/local/lib/arvbox/go-setup.sh
12 cd /usr/src/arvados/services/api
14 if test -s /var/lib/arvados/api_rails_env ; then
15 export RAILS_ENV=$(cat /var/lib/arvados/api_rails_env)
17 export RAILS_ENV=development
22 uuid_prefix=$(cat /var/lib/arvados/api_uuid_prefix)
24 if ! test -s /var/lib/arvados/api_secret_token ; then
25 ruby -e 'puts rand(2**400).to_s(36)' > /var/lib/arvados/api_secret_token
27 secret_token=$(cat /var/lib/arvados/api_secret_token)
29 if ! test -s /var/lib/arvados/blob_signing_key ; then
30 ruby -e 'puts rand(2**400).to_s(36)' > /var/lib/arvados/blob_signing_key
32 blob_signing_key=$(cat /var/lib/arvados/blob_signing_key)
34 if ! test -s /var/lib/arvados/management_token ; then
35 ruby -e 'puts rand(2**400).to_s(36)' > /var/lib/arvados/management_token
37 management_token=$(cat /var/lib/arvados/management_token)
39 sso_app_secret=$(cat /var/lib/arvados/sso_app_secret)
41 if test -s /var/lib/arvados/vm-uuid ; then
42 vm_uuid=$(cat /var/lib/arvados/vm-uuid)
44 vm_uuid=$uuid_prefix-2x53u-$(ruby -e 'puts rand(2**400).to_s(36)[0,15]')
45 echo $vm_uuid > /var/lib/arvados/vm-uuid
48 if ! test -f /var/lib/arvados/api_database_pw ; then
49 ruby -e 'puts rand(2**128).to_s(36)' > /var/lib/arvados/api_database_pw
51 database_pw=$(cat /var/lib/arvados/api_database_pw)
53 if ! (psql postgres -c "\du" | grep "^ arvados ") >/dev/null ; then
54 psql postgres -c "create user arvados with password '$database_pw'"
56 psql postgres -c "ALTER USER arvados WITH SUPERUSER;"
58 if test -a /usr/src/arvados/services/api/config/arvados_config.rb ; then
59 rm -f config/application.yml config/database.yml
61 cat >config/application.yml <<EOF
63 uuid_prefix: $uuid_prefix
64 secret_token: $secret_token
65 blob_signing_key: $blob_signing_key
66 sso_app_secret: $sso_app_secret
67 sso_app_id: arvados-server
68 sso_provider_url: "https://$localip:${services[sso]}"
70 workbench_address: "https://$localip/"
71 websocket_address: "wss://$localip:${services[websockets-ssl]}/websocket"
72 git_repo_ssh_base: "git@$localip:"
73 git_repo_https_base: "http://$localip:${services[arv-git-httpd]}/"
74 new_users_are_active: true
75 auto_admin_first_user: true
76 auto_setup_new_users: true
77 auto_setup_new_users_with_vm_uuid: $vm_uuid
78 auto_setup_new_users_with_repository: true
79 default_collection_replication: 1
80 docker_image_formats: ["v2"]
81 keep_web_service_url: https://$localip:${services[keep-web-ssl]}/
82 ManagementToken: $management_token
85 (cd config && /usr/local/lib/arvbox/yml_override.py application.yml)
86 sed "s/password:.*/password: $database_pw/" <config/database.yml.example >config/database.yml
89 if ! test -f /var/lib/arvados/api_database_setup ; then
90 bundle exec rake db:setup
91 touch /var/lib/arvados/api_database_setup
94 if ! test -s /var/lib/arvados/superuser_token ; then
95 superuser_tok=$(bundle exec ./script/create_superuser_token.rb)
96 echo "$superuser_tok" > /var/lib/arvados/superuser_token
102 bundle exec rake db:migrate