bosh-gen 0.24.0 → 0.90.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +2 -362
- data/bosh-gen.gemspec +2 -1
- data/lib/bosh/gen/cli.rb +0 -8
- data/lib/bosh/gen/generators/errand_generator/templates/jobs/%job_name%/templates/bin/run.tt +2 -1
- data/lib/bosh/gen/generators/job_generator.rb +0 -5
- data/lib/bosh/gen/generators/job_generator/templates/jobs/%job_name%_simple/monit.tt +2 -2
- data/lib/bosh/gen/generators/job_generator/templates/jobs/%job_name%_simple/spec.tt +24 -0
- data/lib/bosh/gen/generators/job_generator/templates/jobs/%job_name%_simple/templates/bin/ctl.tt +1 -1
- data/lib/bosh/gen/generators/job_generator/templates/jobs/%job_name%_simple/templates/helpers/ctl_setup.sh +0 -26
- data/lib/bosh/gen/generators/new_release_generator.rb +7 -8
- data/lib/bosh/gen/generators/new_release_generator/templates/README.md.tt +13 -63
- data/lib/bosh/gen/generators/new_release_generator/templates/jobs/{just_install_packages → %project_name%}/monit.tt +0 -0
- data/lib/bosh/gen/generators/new_release_generator/templates/jobs/{just_install_packages → %project_name%}/spec.tt +1 -1
- data/lib/bosh/gen/generators/new_release_generator/templates/jobs/{just_install_packages → %project_name%}/templates/ignoreme +0 -0
- data/lib/bosh/gen/generators/new_release_generator/templates/manifests/%project_name%.yml.tt +38 -0
- data/lib/bosh/gen/generators/new_release_generator/templates/manifests/operators/dev.yml.tt +6 -0
- data/lib/bosh/gen/version.rb +1 -1
- metadata +28 -191
- data/.travis.yml +0 -13
- data/lib/bosh/cli/commands/share_release.rb +0 -80
- data/lib/bosh/gen/generators/bosh_cli_plugin_generator.rb +0 -33
- data/lib/bosh/gen/generators/bosh_cli_plugin_generator/templates/lib/bosh/cli/commands/%underscore_plugin_name%.rb.tt +0 -9
- data/lib/bosh/gen/generators/job_generator/templates/jobs/%job_name%_nginx_rack/monit.tt +0 -13
- data/lib/bosh/gen/generators/job_generator/templates/jobs/%job_name%_nginx_rack/templates/bin/%job_name%_rack_ctl.tt +0 -59
- data/lib/bosh/gen/generators/job_generator/templates/jobs/%job_name%_nginx_rack/templates/bin/ctl_db_utils.sh.erb +0 -54
- data/lib/bosh/gen/generators/job_generator/templates/jobs/%job_name%_nginx_rack/templates/bin/ctl_nginx.sh.erb +0 -17
- data/lib/bosh/gen/generators/job_generator/templates/jobs/%job_name%_nginx_rack/templates/bin/ctl_redis_utils.sh.erb +0 -18
- data/lib/bosh/gen/generators/job_generator/templates/jobs/%job_name%_nginx_rack/templates/bin/ctl_setup.sh.erb +0 -48
- data/lib/bosh/gen/generators/job_generator/templates/jobs/%job_name%_nginx_rack/templates/bin/ctl_start.sh.erb +0 -57
- data/lib/bosh/gen/generators/job_generator/templates/jobs/%job_name%_nginx_rack/templates/bin/ctl_utils.sh +0 -147
- data/lib/bosh/gen/generators/job_generator/templates/jobs/%job_name%_nginx_rack/templates/bin/monit_debugger +0 -13
- data/lib/bosh/gen/generators/job_generator/templates/jobs/%job_name%_nginx_rack/templates/bin/nginx_ctl.tt +0 -40
- data/lib/bosh/gen/generators/job_generator/templates/jobs/%job_name%_nginx_rack/templates/bin/rails_ctl_setup.sh.erb +0 -39
- data/lib/bosh/gen/generators/job_generator/templates/jobs/%job_name%_nginx_rack/templates/config/database.yml.erb +0 -17
- data/lib/bosh/gen/generators/job_generator/templates/jobs/%job_name%_nginx_rack/templates/config/mime.types +0 -73
- data/lib/bosh/gen/generators/job_generator/templates/jobs/%job_name%_nginx_rack/templates/config/nginx.conf.erb +0 -150
- data/lib/bosh/gen/generators/job_generator/templates/jobs/%job_name%_nginx_rack/templates/config/nginx_proxy.conf +0 -11
- data/lib/bosh/gen/generators/job_generator/templates/jobs/%job_name%_nginx_rack/templates/config/redis.yml.erb +0 -6
- data/lib/bosh/gen/generators/job_generator/templates/jobs/%job_name%_simple/templates/data/properties.sh.erb +0 -10
- data/lib/bosh/gen/generators/new_release_generator/templates/templates/deployment.yml.tt +0 -31
- data/lib/bosh/gen/generators/new_release_generator/templates/templates/infrastructure-aws-ec2.yml.tt +0 -33
- data/lib/bosh/gen/generators/new_release_generator/templates/templates/infrastructure-warden.yml.tt +0 -37
- data/lib/bosh/gen/generators/new_release_generator/templates/templates/jobs.yml.tt +0 -21
- data/lib/bosh/gen/generators/new_release_generator/templates/templates/make_manifest.tt +0 -83
- data/lib/bosh/gen/generators/new_release_generator/templates/templates/stub.yml.tt +0 -14
- data/lib/bosh/gen/models.rb +0 -9
- data/lib/bosh/gen/models/bosh_config.rb +0 -15
- data/lib/bosh/gen/models/deployment_manifest.rb +0 -107
- data/lib/bosh/gen/models/release_detection.rb +0 -35
- data/lib/bosh/gen/utils/file_with_progress_bar.rb +0 -62
- data/spec/fixtures/bosh_config/multiple_boshes.yml +0 -34
- data/spec/fixtures/deployment_manifests/2_jobs_1_ip_8196_disk.yml +0 -67
- data/spec/fixtures/deployment_manifests/2_jobs_1_ip_8196_disk_with_numeric.yml +0 -67
- data/spec/fixtures/deployment_manifests/2_jobs_2_ips_no_disk.yml +0 -67
- data/spec/fixtures/releases/bosh-sample-release/.gitignore +0 -9
- data/spec/fixtures/releases/bosh-sample-release/LICENSE +0 -8094
- data/spec/fixtures/releases/bosh-sample-release/NOTICE +0 -12
- data/spec/fixtures/releases/bosh-sample-release/README +0 -53
- data/spec/fixtures/releases/bosh-sample-release/config/final.yml +0 -9
- data/spec/fixtures/releases/bosh-sample-release/jobs/mysql/monit +0 -5
- data/spec/fixtures/releases/bosh-sample-release/jobs/mysql/spec +0 -17
- data/spec/fixtures/releases/bosh-sample-release/jobs/mysql/templates/my.bootstrap.erb +0 -6
- data/spec/fixtures/releases/bosh-sample-release/jobs/mysql/templates/my.cnf.erb +0 -46
- data/spec/fixtures/releases/bosh-sample-release/jobs/mysql/templates/my.shutdown.erb +0 -5
- data/spec/fixtures/releases/bosh-sample-release/jobs/mysql/templates/mysql_ctl.erb +0 -56
- data/spec/fixtures/releases/bosh-sample-release/jobs/nginx/monit +0 -5
- data/spec/fixtures/releases/bosh-sample-release/jobs/nginx/spec +0 -10
- data/spec/fixtures/releases/bosh-sample-release/jobs/nginx/templates/mime.types +0 -73
- data/spec/fixtures/releases/bosh-sample-release/jobs/nginx/templates/nginx.conf.erb +0 -65
- data/spec/fixtures/releases/bosh-sample-release/jobs/nginx/templates/nginx_ctl +0 -28
- data/spec/fixtures/releases/bosh-sample-release/jobs/wordpress/monit +0 -5
- data/spec/fixtures/releases/bosh-sample-release/jobs/wordpress/spec +0 -12
- data/spec/fixtures/releases/bosh-sample-release/jobs/wordpress/templates/httpd.conf.erb +0 -422
- data/spec/fixtures/releases/bosh-sample-release/jobs/wordpress/templates/php.ini.erb +0 -1918
- data/spec/fixtures/releases/bosh-sample-release/jobs/wordpress/templates/wordpress_ctl +0 -39
- data/spec/fixtures/releases/bosh-sample-release/jobs/wordpress/templates/wp-config.php.erb +0 -90
- data/spec/fixtures/releases/bosh-sample-release/packages/apache2/packaging +0 -15
- data/spec/fixtures/releases/bosh-sample-release/packages/apache2/spec +0 -5
- data/spec/fixtures/releases/bosh-sample-release/packages/mysql/packaging +0 -14
- data/spec/fixtures/releases/bosh-sample-release/packages/mysql/spec +0 -5
- data/spec/fixtures/releases/bosh-sample-release/packages/mysqlclient/packaging +0 -12
- data/spec/fixtures/releases/bosh-sample-release/packages/mysqlclient/spec +0 -4
- data/spec/fixtures/releases/bosh-sample-release/packages/nginx/packaging +0 -23
- data/spec/fixtures/releases/bosh-sample-release/packages/nginx/spec +0 -6
- data/spec/fixtures/releases/bosh-sample-release/packages/php5/packaging +0 -24
- data/spec/fixtures/releases/bosh-sample-release/packages/php5/spec +0 -7
- data/spec/fixtures/releases/bosh-sample-release/packages/wordpress/packaging +0 -14
- data/spec/fixtures/releases/bosh-sample-release/packages/wordpress/spec +0 -5
- data/spec/fixtures/releases/s3test-boshrelease/.gitignore +0 -18
- data/spec/fixtures/releases/s3test-boshrelease/README.md +0 -51
- data/spec/fixtures/releases/s3test-boshrelease/Rakefile +0 -15
- data/spec/fixtures/releases/s3test-boshrelease/config/blobs.yml +0 -1
- data/spec/fixtures/releases/s3test-boshrelease/config/final.yml +0 -5
- data/spec/fixtures/releases/s3test-boshrelease/jobs/.gitkeep +0 -0
- data/spec/fixtures/releases/s3test-boshrelease/jobs/s3test/monit +0 -5
- data/spec/fixtures/releases/s3test-boshrelease/jobs/s3test/spec +0 -13
- data/spec/fixtures/releases/s3test-boshrelease/jobs/s3test/templates/bin/monit_debugger +0 -13
- data/spec/fixtures/releases/s3test-boshrelease/jobs/s3test/templates/bin/s3test_ctl +0 -36
- data/spec/fixtures/releases/s3test-boshrelease/jobs/s3test/templates/config/.gitkeep +0 -0
- data/spec/fixtures/releases/s3test-boshrelease/jobs/s3test/templates/config/s3test.conf.erb +0 -5
- data/spec/fixtures/releases/s3test-boshrelease/jobs/s3test/templates/data/properties.sh.erb +0 -10
- data/spec/fixtures/releases/s3test-boshrelease/jobs/s3test/templates/helpers/ctl_setup.sh +0 -81
- data/spec/fixtures/releases/s3test-boshrelease/jobs/s3test/templates/helpers/ctl_utils.sh +0 -156
- data/spec/fixtures/releases/s3test-boshrelease/packages/.gitkeep +0 -0
- data/spec/fixtures/releases/s3test-boshrelease/src/.gitkeep +0 -0
- data/spec/fixtures/releases/s3test-boshrelease/templates/deployment.yml +0 -35
- data/spec/fixtures/releases/s3test-boshrelease/templates/infrastructure-aws-ec2.yml +0 -40
- data/spec/fixtures/releases/s3test-boshrelease/templates/infrastructure-warden.yml +0 -107
- data/spec/fixtures/releases/s3test-boshrelease/templates/jobs.yml +0 -34
- data/spec/fixtures/releases/s3test-boshrelease/templates/make_manifest +0 -54
- data/spec/fixtures/releases/s3test-boshrelease/templates/stub.yml +0 -13
- data/spec/fixtures/releases/some_dev_releases/config/dev.yml +0 -3
- data/spec/fixtures/releases/some_dev_releases/dev_releases/index.yml +0 -6
- data/spec/fixtures/releases/some_dev_releases/dev_releases/myrelease-1.yml +0 -11
- data/spec/fixtures/releases/some_dev_releases/dev_releases/myrelease-10.yml +0 -13
- data/spec/fixtures/releases/some_dev_releases/dev_releases/myrelease-2.yml +0 -13
- data/spec/generators/job_generator_spec.rb +0 -56
- data/spec/generators/new_release_generator_spec.rb +0 -93
- data/spec/models/bosh_config_spec.rb +0 -11
- data/spec/models/deployment_manifest_spec.rb +0 -40
- data/spec/models/release_detection_spec.rb +0 -23
- data/spec/spec_helper.rb +0 -30
- data/spec/support/generator_spec_helper.rb +0 -155
data/.travis.yml
DELETED
@@ -1,80 +0,0 @@
|
|
1
|
-
require 'bosh/gen/utils/file_with_progress_bar'
|
2
|
-
|
3
|
-
module Bosh::Cli::Command
|
4
|
-
class ShareRelease < Base
|
5
|
-
usage "share release"
|
6
|
-
desc "upload release tarball to blobstore"
|
7
|
-
def share_release(tarball_path)
|
8
|
-
# need to be in release dir to get blobstore credentials
|
9
|
-
check_if_release_dir
|
10
|
-
|
11
|
-
unless File.exist?(tarball_path)
|
12
|
-
err("Release tarball file doesn't exist")
|
13
|
-
end
|
14
|
-
|
15
|
-
tarball = Bosh::Cli::ReleaseTarball.new(tarball_path)
|
16
|
-
say("\nVerifying release...")
|
17
|
-
tarball.validate(:allow_sparse => true)
|
18
|
-
nl
|
19
|
-
|
20
|
-
unless tarball.valid?
|
21
|
-
err('Release is invalid, please fix, verify and upload again')
|
22
|
-
end
|
23
|
-
|
24
|
-
upload_name = "boshrelease-#{tarball.release_name}-#{tarball.version}.tgz"
|
25
|
-
|
26
|
-
f = ::FileWithProgressBar.open(tarball_path, 'r')
|
27
|
-
f.out = Bosh::Cli::Config.output
|
28
|
-
|
29
|
-
raw_blobstore_client = unwrap_blobstore_client(blobstore)
|
30
|
-
bucket_name = raw_blobstore_client.instance_variable_get("@bucket_name")
|
31
|
-
|
32
|
-
fog = fog_storage(raw_blobstore_client)
|
33
|
-
unless dir = fog.directories.get(bucket_name)
|
34
|
-
err("S3 bucket #{bucket_name} is missing")
|
35
|
-
end
|
36
|
-
|
37
|
-
say("\nUploading release...")
|
38
|
-
if file = dir.files.new(key: upload_name, body: f)
|
39
|
-
file.public = true
|
40
|
-
file.save
|
41
|
-
nl
|
42
|
-
say(file.public_url)
|
43
|
-
else
|
44
|
-
err('Failed to upload file to blobstore')
|
45
|
-
end
|
46
|
-
end
|
47
|
-
|
48
|
-
private
|
49
|
-
def unwrap_blobstore_client(blobstore)
|
50
|
-
if blobstore.is_a?(Bosh::Blobstore::RetryableBlobstoreClient)
|
51
|
-
unwrap_blobstore_client(blobstore.instance_variable_get("@client"))
|
52
|
-
elsif blobstore.is_a?(Bosh::Blobstore::Sha1VerifiableBlobstoreClient)
|
53
|
-
unwrap_blobstore_client(blobstore.instance_variable_get("@client"))
|
54
|
-
else
|
55
|
-
blobstore
|
56
|
-
end
|
57
|
-
end
|
58
|
-
|
59
|
-
def fog_storage(blobstore)
|
60
|
-
blobstore_options = blobstore.instance_variable_get("@options")
|
61
|
-
if blobstore.is_a?(Bosh::Blobstore::S3BlobstoreClient)
|
62
|
-
require "fog/aws"
|
63
|
-
return Fog::Storage.new(
|
64
|
-
provider: 'AWS',
|
65
|
-
aws_access_key_id: blobstore_options[:access_key_id],
|
66
|
-
aws_secret_access_key: blobstore_options[:secret_access_key],
|
67
|
-
)
|
68
|
-
# elsif blobstore.is_a?(Bosh::Blobstore::SwiftBlobstoreClient)
|
69
|
-
# require "fog/openstack"
|
70
|
-
# return Fog::Storage.new(
|
71
|
-
# provider: 'OpenStack',
|
72
|
-
# aws_access_key_id: blobstore_options[:access_key_id],
|
73
|
-
# aws_secret_access_key: blobstore_options[:secret_access_key],
|
74
|
-
# )
|
75
|
-
else
|
76
|
-
err('Not yet implemented for #{blobstore.class} blobstore')
|
77
|
-
end
|
78
|
-
end
|
79
|
-
end
|
80
|
-
end
|
@@ -1,33 +0,0 @@
|
|
1
|
-
require 'thor/group'
|
2
|
-
require 'active_support/core_ext/string'
|
3
|
-
|
4
|
-
module Bosh::Gen
|
5
|
-
module Generators
|
6
|
-
class BoshCliPluginGenerator < Thor::Group
|
7
|
-
include Thor::Actions
|
8
|
-
|
9
|
-
argument :plugin_name
|
10
|
-
|
11
|
-
def self.source_root
|
12
|
-
File.join(File.dirname(__FILE__), "bosh_cli_plugin_generator", "templates")
|
13
|
-
end
|
14
|
-
|
15
|
-
def install_plugin
|
16
|
-
directory "lib"
|
17
|
-
end
|
18
|
-
|
19
|
-
private
|
20
|
-
def underscore_plugin_name
|
21
|
-
plugin_name.gsub(/\W+/, '_')
|
22
|
-
end
|
23
|
-
|
24
|
-
def spaced_plugin_name
|
25
|
-
plugin_name.gsub(/\W+/, ' ')
|
26
|
-
end
|
27
|
-
|
28
|
-
def camelcase_plugin_name
|
29
|
-
underscore_plugin_name.camelcase
|
30
|
-
end
|
31
|
-
end
|
32
|
-
end
|
33
|
-
end
|
@@ -1,13 +0,0 @@
|
|
1
|
-
check process <%= job_name %>
|
2
|
-
with pidfile /var/vcap/sys/run/<%= job_name %>/<%= job_name %>.pid
|
3
|
-
start program "/var/vcap/jobs/<%= job_name %>/bin/monit_debugger <%= job_name %>_ctl '/var/vcap/jobs/<%= job_name %>/bin/<%= job_name %>_rack_ctl start'"
|
4
|
-
stop program "/var/vcap/jobs/<%= job_name %>/bin/monit_debugger <%= job_name %>_ctl '/var/vcap/jobs/<%= job_name %>/bin/<%= job_name %>_rack_ctl stop'"
|
5
|
-
group vcap
|
6
|
-
|
7
|
-
<%% if properties.<%= job_name %> && properties.<%= job_name %>.use_nginx %>
|
8
|
-
check process nginx
|
9
|
-
with pidfile /var/vcap/sys/run/<%= job_name %>/nginx.pid
|
10
|
-
start program "/var/vcap/jobs/<%= job_name %>/bin/monit_debugger nginx_ctl '/var/vcap/jobs/<%= job_name %>/bin/nginx_ctl start'"
|
11
|
-
stop program "/var/vcap/jobs/<%= job_name %>/bin/monit_debugger nginx_ctl '/var/vcap/jobs/<%= job_name %>/bin/nginx_ctl stop'"
|
12
|
-
group vcap
|
13
|
-
<%% end %>
|
@@ -1,59 +0,0 @@
|
|
1
|
-
#!/bin/bash
|
2
|
-
|
3
|
-
set -e # exit immediately if a simple command exits with a non-zero status
|
4
|
-
set -u # report the usage of uninitialized variables
|
5
|
-
|
6
|
-
# Setup env vars and folders for the webapp_ctl script
|
7
|
-
source /var/vcap/jobs/<%= job_name %>/bin/ctl_setup.sh
|
8
|
-
|
9
|
-
export PORT=${PORT:-5000}
|
10
|
-
export LANG=en_US.UTF-8
|
11
|
-
|
12
|
-
# Setup HTTP_PROXY, HTTPS_PROXY, NO_PROXY as necessary
|
13
|
-
source $JOB_DIR/bin/ctl_nginx.sh
|
14
|
-
|
15
|
-
# Setup for Rails application
|
16
|
-
source $JOB_DIR/bin/rails_ctl_setup.sh
|
17
|
-
|
18
|
-
# Helpers for PostgresDB
|
19
|
-
source $JOB_DIR/bin/ctl_db_utils.sh
|
20
|
-
|
21
|
-
# Helpers for Redis
|
22
|
-
source $JOB_DIR/bin/ctl_redis_utils.sh
|
23
|
-
|
24
|
-
case $1 in
|
25
|
-
|
26
|
-
start)
|
27
|
-
pid_guard $PIDFILE $JOB_NAME
|
28
|
-
|
29
|
-
cd $WEBAPP_DIR
|
30
|
-
|
31
|
-
# link database.yml config to application
|
32
|
-
link_sql_db_config
|
33
|
-
|
34
|
-
# if redis enabled, link it to application
|
35
|
-
link_redis_config yaml config/redis.yml
|
36
|
-
|
37
|
-
# Migrations, if requested
|
38
|
-
run_migrations $WEBAPP_DIR
|
39
|
-
|
40
|
-
# TODO what is 'ulimit -c unlimited' for; when not to use it?
|
41
|
-
ulimit -c unlimited
|
42
|
-
|
43
|
-
# Start the rack app using requested appstack
|
44
|
-
source $JOB_DIR/bin/ctl_start.sh
|
45
|
-
|
46
|
-
echo "Running $JOB_NAME on $PORT"
|
47
|
-
;;
|
48
|
-
|
49
|
-
stop)
|
50
|
-
kill_and_wait $PIDFILE
|
51
|
-
|
52
|
-
;;
|
53
|
-
*)
|
54
|
-
echo "Usage: <%= job_name %>_rack_ctl {start|stop}"
|
55
|
-
|
56
|
-
;;
|
57
|
-
|
58
|
-
esac
|
59
|
-
exit 0
|
@@ -1,54 +0,0 @@
|
|
1
|
-
<% if properties.postgres %>
|
2
|
-
PG_PACKAGE_DIR=/var/vcap/package/postgres
|
3
|
-
function database_ready() {
|
4
|
-
DB_HOST='<%= properties.postgres.host %>'
|
5
|
-
DB_PORT='<%= properties.postgres.port || 5432 %>'
|
6
|
-
DB_USER='<%= properties.postgres.user %>'
|
7
|
-
DB_PASSWORD='<%= properties.postgres.password %>'
|
8
|
-
DB_NAME='<%= properties.postgres.database %>'
|
9
|
-
echo Testing postgresl: psql -d $DB_NAME -p $DB_PORT -U vcap -c "select 1;"
|
10
|
-
LD_LIBRARY_PATH=$PG_PACKAGE_DIR/lib $PG_PACKAGE_DIR/bin/psql -d $DB_NAME -p $DB_PORT -U $DB_USER -c "select 1;"
|
11
|
-
}
|
12
|
-
<% else %>
|
13
|
-
# No database or SQLite database
|
14
|
-
function database_ready() {
|
15
|
-
true
|
16
|
-
}
|
17
|
-
<% end %>
|
18
|
-
|
19
|
-
function wait_for_database() {
|
20
|
-
while [[ ! database_ready ]]
|
21
|
-
do
|
22
|
-
echo "Waiting for database availability"
|
23
|
-
sleep 1;
|
24
|
-
done
|
25
|
-
}
|
26
|
-
|
27
|
-
# Look for known types of config files
|
28
|
-
# and if found, symlink into target location
|
29
|
-
# in application
|
30
|
-
#
|
31
|
-
# config/wp-config.php -> wp-config.php
|
32
|
-
# config/database.yml -> config/database.yml
|
33
|
-
function link_sql_db_config() {
|
34
|
-
possible_job_config=(config/database.yml config/wp-config.php)
|
35
|
-
target_app_config=(config/database.yml wp-config.php)
|
36
|
-
list_size=${#possible_job_config[@]}
|
37
|
-
found_config='none'
|
38
|
-
for (( i = 0; i < $list_size; i++ )); do
|
39
|
-
job_config=${possible_job_config[i]}
|
40
|
-
app_config=${target_app_config[i]}
|
41
|
-
if [[ -f $JOB_DIR/${job_config} ]]
|
42
|
-
then
|
43
|
-
link_job_file_to_package ${job_config} ${app_config}
|
44
|
-
found_config=${app_config}
|
45
|
-
fi
|
46
|
-
done
|
47
|
-
|
48
|
-
if [[ "${found_config}" = "none" ]]
|
49
|
-
then
|
50
|
-
echo "ERROR: link_sql_db_config - job does not contain a supported db config file"
|
51
|
-
echo "Please add to job $JOB_NAME a template from: ${possible_job_config[@]}"
|
52
|
-
exit 1
|
53
|
-
fi
|
54
|
-
}
|
@@ -1,17 +0,0 @@
|
|
1
|
-
# Setup HTTP_PROXY, HTTPS_PROXY, NO_PROXY as necessary
|
2
|
-
|
3
|
-
# https://github.com/pmirshad/cgit-on-nginx/wiki/Installing-cgit-with-nginx-on-Ubuntu-11.10
|
4
|
-
<% if properties.env %>
|
5
|
-
<% if properties.env.http_proxy %>
|
6
|
-
export HTTP_PROXY='<%= properties.env.http_proxy %>'
|
7
|
-
export http_proxy='<%= properties.env.http_proxy %>'
|
8
|
-
<% end %>
|
9
|
-
<% if properties.env.https_proxy %>
|
10
|
-
export HTTPS_PROXY='<%= properties.env.https_proxy %>'
|
11
|
-
export https_proxy='<%= properties.env.https_proxy %>'
|
12
|
-
<% end %>
|
13
|
-
<% if properties.env.no_proxy %>
|
14
|
-
export NO_PROXY='<%= properties.env.no_proxy %>'
|
15
|
-
export no_proxy='<%= properties.env.no_proxy %>'
|
16
|
-
<% end %>
|
17
|
-
<% end %>
|
@@ -1,18 +0,0 @@
|
|
1
|
-
#!/usr/bin/env bash
|
2
|
-
|
3
|
-
REDIS='<%= properties.redis ? 1 : 0 %>'
|
4
|
-
|
5
|
-
# Usage: link_redis_config yaml config/redis.yml
|
6
|
-
function link_redis_config() {
|
7
|
-
format=$1 # e.g. yaml
|
8
|
-
target_file=${2:-config/redis.yml} # e.g. config/redis.yml
|
9
|
-
if [[ "${format}" != "yaml" ]]
|
10
|
-
then
|
11
|
-
echo "ERROR: 'link_redis_config ${format}' is not supported. Only supported format: yaml"
|
12
|
-
exit 1
|
13
|
-
fi
|
14
|
-
if [[ "$REDIS" = '1' ]]
|
15
|
-
then
|
16
|
-
link_job_file_to_package ${app_config}
|
17
|
-
fi
|
18
|
-
}
|
@@ -1,48 +0,0 @@
|
|
1
|
-
#!/usr/bin/env bash
|
2
|
-
|
3
|
-
# Setup env vars and folders for the ctl script
|
4
|
-
# This helps keep the ctl script as readable
|
5
|
-
# as possible
|
6
|
-
|
7
|
-
set -e # exit immediately if a simple command exits with a non-zero status
|
8
|
-
set -u # report the usage of uninitialized variables
|
9
|
-
|
10
|
-
export JOB_NAME='<%= name %>'
|
11
|
-
export JOB_DIR=/var/vcap/jobs/$JOB_NAME
|
12
|
-
chmod 755 $JOB_DIR # to access file via symlink
|
13
|
-
|
14
|
-
# the package that contains the application code
|
15
|
-
WEBAPP_PACKAGE='<%= properties.webapp && properties.webapp.package %>'
|
16
|
-
WEBAPP_DIR=/var/vcap/packages/$WEBAPP_PACKAGE
|
17
|
-
if [[ "$WEBAPP_PACKAGE" = '' ]]
|
18
|
-
then
|
19
|
-
echo 'ERROR: $WEBAPP_PACKAGE not set before bin/ctl_setup.sh'
|
20
|
-
exit 1
|
21
|
-
fi
|
22
|
-
|
23
|
-
source $JOB_DIR/bin/ctl_utils.sh
|
24
|
-
redirect_output $JOB_NAME
|
25
|
-
|
26
|
-
export HOME=${HOME:-/home/vcap}
|
27
|
-
|
28
|
-
# Add all packages' /bin & /sbin into $PATH
|
29
|
-
for package_bin_dir in $(ls -d /var/vcap/packages/*/{,s}bin)
|
30
|
-
do
|
31
|
-
export PATH=${package_bin_dir}:$PATH
|
32
|
-
done
|
33
|
-
|
34
|
-
# Setup log, run and tmp folders
|
35
|
-
|
36
|
-
RUN_DIR=/var/vcap/sys/run/$JOB_NAME
|
37
|
-
LOG_DIR=/var/vcap/sys/log/$JOB_NAME
|
38
|
-
TMPDIR=/var/vcap/sys/tmp/$JOB_NAME
|
39
|
-
for dir in $RUN_DIR $LOG_DIR $TMPDIR
|
40
|
-
do
|
41
|
-
mkdir -p ${dir}
|
42
|
-
chown vcap:vcap ${dir}
|
43
|
-
done
|
44
|
-
|
45
|
-
export C_INCLUDE_PATH=/var/vcap/packages/mysqlclient/include/mysql:/var/vcap/packages/sqlite/include:/var/vcap/packages/libpq/include
|
46
|
-
export LIBRARY_PATH=/var/vcap/packages/mysqlclient/lib/mysql:/var/vcap/packages/sqlite/lib:/var/vcap/packages/libpq/lib
|
47
|
-
|
48
|
-
PIDFILE=$RUN_DIR/$JOB_NAME.pid
|
@@ -1,57 +0,0 @@
|
|
1
|
-
#!/usr/bin/env bash
|
2
|
-
|
3
|
-
# Either:
|
4
|
-
# properties:
|
5
|
-
# webapp:
|
6
|
-
# appstack: puma
|
7
|
-
# puma:
|
8
|
-
# threads:
|
9
|
-
# min: 0
|
10
|
-
# max: 16
|
11
|
-
#
|
12
|
-
# Or PHP-FPM:
|
13
|
-
# properties:
|
14
|
-
# webapp:
|
15
|
-
# appstack: php-fpm
|
16
|
-
#
|
17
|
-
# Or (default)
|
18
|
-
# properties:
|
19
|
-
# webapp:
|
20
|
-
# appstack: rackup
|
21
|
-
#
|
22
|
-
# Requires env variables:
|
23
|
-
# * $WEBAPP_DIR
|
24
|
-
# * $PIDFILE
|
25
|
-
# * $PORT
|
26
|
-
appstack='<%= properties.webapp && properties.webapp.appstack %>'
|
27
|
-
|
28
|
-
echo "Launching $JOB_NAME within $WEBAPP_DIR with ${appstack}"
|
29
|
-
wait_for_database
|
30
|
-
|
31
|
-
if [[ "${appstack}" = "puma" ]]
|
32
|
-
then
|
33
|
-
<% puma_threads = properties.webapp.puma && properties.webapp.puma.threads %>
|
34
|
-
MIN_THREADS=<%= (puma_threads && puma_threads.min) || 0 %>
|
35
|
-
MAX_THREADS=<%= (puma_threads && puma_threads.max) || 16 %>
|
36
|
-
exec bundle exec puma --pidfile $PIDFILE -p $PORT -t $MIN_THREADS:$MAX_THREADS \
|
37
|
-
>>$LOG_DIR/webapp.stdout.log 2>&1 || exit 1
|
38
|
-
|
39
|
-
elif [[ "${appstack}" = "rackup" ]]
|
40
|
-
then
|
41
|
-
exec bundle exec rackup -D -P $PIDFILE -p $PORT \
|
42
|
-
>>$LOG_DIR/webapp.stdout.log 2>&1 || exit 1
|
43
|
-
|
44
|
-
elif [[ "${appstack}" = "phpfpm" || "${appstack}" = "php-fpm" ]]
|
45
|
-
then
|
46
|
-
/var/vcap/packages/php5/sbin/php-fpm \
|
47
|
-
-c $JOB_DIR/etc/php.ini \
|
48
|
-
--fpm-config $JOB_DIR/etc/php-fpm.conf \
|
49
|
-
--pid $PIDFILE
|
50
|
-
|
51
|
-
# else invalid appstack requested
|
52
|
-
else
|
53
|
-
echo "ERROR: properties.webapp.appstack = ${appstack}. Valid values: puma, rackup"
|
54
|
-
exit 1
|
55
|
-
fi
|
56
|
-
|
57
|
-
chown vcap:vcap $PIDFILE
|
@@ -1,147 +0,0 @@
|
|
1
|
-
# Helper functions used by ctl scripts
|
2
|
-
|
3
|
-
# links a file (probably a config file) into a package
|
4
|
-
# Example usage:
|
5
|
-
# link_job_file_to_package config/redis.yml [config/redis.yml]
|
6
|
-
# link_job_file_to_package config/wp-config.php wp-config.php
|
7
|
-
link_job_file_to_package() {
|
8
|
-
source_job_file=$1
|
9
|
-
target_package_file=${2:-$source_job_file}
|
10
|
-
|
11
|
-
full_job_file=$JOB_DIR/${source_job_file}
|
12
|
-
full_package_file=$WEBAPP_DIR/${target_package_file}
|
13
|
-
echo link_job_file_to_package $full_job_file $full_package_file
|
14
|
-
if [[ ! -f ${full_job_file} ]]
|
15
|
-
then
|
16
|
-
echo "File to link ${full_job_file} does not exist"
|
17
|
-
else
|
18
|
-
# Create/recreate the symlink to current job file
|
19
|
-
# If another process is using the file, it won't be
|
20
|
-
# deleted, so don't attempt to create the symlink
|
21
|
-
echo "Linking ${source_job_file} -> ${full_package_file}"
|
22
|
-
mkdir -p $(dirname ${full_package_file})
|
23
|
-
ln -nfs ${full_job_file} ${full_package_file}
|
24
|
-
fi
|
25
|
-
}
|
26
|
-
|
27
|
-
|
28
|
-
# If loaded within monit ctl scripts then pipe output
|
29
|
-
# If loaded from 'source ../utils.sh' then normal STDOUT
|
30
|
-
redirect_output() {
|
31
|
-
SCRIPT=$1
|
32
|
-
mkdir -p /var/vcap/sys/log/monit
|
33
|
-
exec 1>> /var/vcap/sys/log/monit/$SCRIPT.log 2>&1
|
34
|
-
}
|
35
|
-
|
36
|
-
pid_guard() {
|
37
|
-
pidfile=$1
|
38
|
-
name=$2
|
39
|
-
|
40
|
-
if [ -f "$pidfile" ]; then
|
41
|
-
pid=$(head -1 "$pidfile")
|
42
|
-
|
43
|
-
if [ -n "$pid" ] && [ -e /proc/$pid ]; then
|
44
|
-
echo "$name is already running, please stop it first"
|
45
|
-
exit 1
|
46
|
-
fi
|
47
|
-
|
48
|
-
echo "Removing stale pidfile..."
|
49
|
-
rm $pidfile
|
50
|
-
fi
|
51
|
-
}
|
52
|
-
|
53
|
-
wait_pid() {
|
54
|
-
pid=$1
|
55
|
-
try_kill=$2
|
56
|
-
timeout=${3:-0}
|
57
|
-
force=${4:-0}
|
58
|
-
countdown=$(( $timeout * 10 ))
|
59
|
-
|
60
|
-
echo wait_pid $pid $try_kill $timeout $force $countdown
|
61
|
-
if [ -e /proc/$pid ]; then
|
62
|
-
if [ "$try_kill" = "1" ]; then
|
63
|
-
echo "Killing $pidfile: $pid "
|
64
|
-
kill $pid
|
65
|
-
fi
|
66
|
-
while [ -e /proc/$pid ]; do
|
67
|
-
sleep 0.1
|
68
|
-
[ "$countdown" != '0' -a $(( $countdown % 10 )) = '0' ] && echo -n .
|
69
|
-
if [ $timeout -gt 0 ]; then
|
70
|
-
if [ $countdown -eq 0 ]; then
|
71
|
-
if [ "$force" = "1" ]; then
|
72
|
-
echo -ne "\nKill timed out, using kill -9 on $pid... "
|
73
|
-
kill -9 $pid
|
74
|
-
sleep 0.5
|
75
|
-
fi
|
76
|
-
break
|
77
|
-
else
|
78
|
-
countdown=$(( $countdown - 1 ))
|
79
|
-
fi
|
80
|
-
fi
|
81
|
-
done
|
82
|
-
if [ -e /proc/$pid ]; then
|
83
|
-
echo "Timed Out"
|
84
|
-
else
|
85
|
-
echo "Stopped"
|
86
|
-
fi
|
87
|
-
else
|
88
|
-
echo "Process $pid is not running"
|
89
|
-
echo "Attempting to kill pid anyway..."
|
90
|
-
kill $pid
|
91
|
-
fi
|
92
|
-
}
|
93
|
-
|
94
|
-
wait_pidfile() {
|
95
|
-
pidfile=$1
|
96
|
-
try_kill=$2
|
97
|
-
timeout=${3:-0}
|
98
|
-
force=${4:-0}
|
99
|
-
countdown=$(( $timeout * 10 ))
|
100
|
-
|
101
|
-
if [ -f "$pidfile" ]; then
|
102
|
-
pid=$(head -1 "$pidfile")
|
103
|
-
if [ -z "$pid" ]; then
|
104
|
-
echo "Unable to get pid from $pidfile"
|
105
|
-
exit 1
|
106
|
-
fi
|
107
|
-
|
108
|
-
wait_pid $pid $try_kill $timeout $force
|
109
|
-
|
110
|
-
rm -f $pidfile
|
111
|
-
else
|
112
|
-
echo "Pidfile $pidfile doesn't exist"
|
113
|
-
fi
|
114
|
-
}
|
115
|
-
|
116
|
-
kill_and_wait() {
|
117
|
-
pidfile=$1
|
118
|
-
# Monit default timeout for start/stop is 30s
|
119
|
-
# Append 'with timeout {n} seconds' to monit start/stop program configs
|
120
|
-
timeout=${2:-25}
|
121
|
-
force=${3:-1}
|
122
|
-
if [[ -f ${pidfile} ]]
|
123
|
-
then
|
124
|
-
wait_pidfile $pidfile 1 $timeout $force
|
125
|
-
else
|
126
|
-
# TODO assume $1 is something to grep from 'ps ax'
|
127
|
-
pid="$(ps auwwx | grep "$1" | awk '{print $2}')"
|
128
|
-
wait_pid $pid 1 $timeout $force
|
129
|
-
fi
|
130
|
-
}
|
131
|
-
|
132
|
-
check_nfs_mount() {
|
133
|
-
opts=$1
|
134
|
-
exports=$2
|
135
|
-
mount_point=$3
|
136
|
-
|
137
|
-
if grep -qs $mount_point /proc/mounts; then
|
138
|
-
echo "Found NFS mount $mount_point"
|
139
|
-
else
|
140
|
-
echo "Mounting NFS..."
|
141
|
-
mount $opts $exports $mount_point
|
142
|
-
if [ $? != 0 ]; then
|
143
|
-
echo "Cannot mount NFS from $exports to $mount_point, exiting..."
|
144
|
-
exit 1
|
145
|
-
fi
|
146
|
-
fi
|
147
|
-
}
|