Deploy jetty module on client with puppet - jetty

I want to try to install the following module on my clients using puppet.
https://forge.puppetlabs.com/maestrodev/jetty
So I install the module on my master using:
puppet module install maestrodev-jetty
this seems to have worked
$ puppet module list
/home/puppetmaster/.puppet/modules
├── maestrodev-jetty (v1.1.2)
├── maestrodev-wget (v1.5.6)
└── puppetlabs-stdlib (v4.3.2)
What I want to do next is deploy jetty, set it up and deploy it on my clients.
I made the following manifest for this:
class { 'jetty':
version => "9.0.4.v20130625",
home => "/opt",
user => "jetty",
group => "jetty",
}
exec { 'stanbol-war-download':
command => "wget -0 /opt/jetty/webapps/my.war http://some.url/my.war",
path => "/usr/bin/",
creates => "/opt/jetty/webapps/my.war",
} ->
exec { 'jetty_start':
command => "java -jar /opt/jetty/my.jar jetty.port=8181 -Xmx2048m -XX:MaxPermSize=512M",
cwd => "/opt/jetty",
path => "/usr/bin/",
notify => Service["jetty"],
returns => [0, 254],
}
I have been trying for a while but I can't seem to get it installed and running on my clients without getting any sort of error, syntax or otherwise.

Related

CloudSQL JDBC Logstash implementation

Question
I need to query CloudSQL from Logstash but can't find any example out there.
Additional Context
I ran the build command for postgres jdbc driver
mvn -P jar-with-dependencies clean package -DskipTests
And provided it as Logstash JDBC driver (tried with dependencies jar too):
input {
jdbc {
jdbc_driver_library => "/Users/gustavollermalylarrain/Documents/proyectos/labs/cloud-sql-jdbc-socket-factory/jdbc/postgres/target/postgres-socket-factory-1.6.4-SNAPSHOT.jar"
jdbc_driver_class => "org.postgresql.Driver"
jdbc_connection_string => "jdbc:postgresql:///people?cloudSqlInstance=cosmic-keep-148903:us-central1:llermaly&socketFactory=com.google.cloud.sql.postgres.SocketFactory&user=postgres&password=postgres"
statement => "SELECT * FROM people;"
jdbc_user => "postgres"
jdbc_password => "postgres"
}
}
output {
stdout {
codec => rubydebug {
}
}
}
I'm having this error:
Error: java.lang.ClassNotFoundException: org.postgresql.Driver. Are you sure you've included the correct jdbc driver in :jdbc_driver_library?
I'm missing something?
The steps to query Cloud SQL from Logstash are:
Build the jar driver:
From this repo: https://github.com/GoogleCloudPlatform/cloud-sql-jdbc-socket-factory. Clone and run mvn -P jar-with-dependencies clean package -DskipTests
Copy files
Copy the jar files from jdbc/postgres/target/ to logstash-core/lib/jars also download the postgres jdbc driver and copy the jar file to logstash-core/lib/jars as well
Configure Logstash
The configuration file will not include the jar's path because will look into the default folder logstash-core/lib/jars where you copied the jar files.
input {
jdbc {
jdbc_driver_class => "org.postgresql.Driver"
jdbc_connection_string => "jdbc:postgresql:///people?cloudSqlInstance=cosmic-keep-148903:us-central1:llermaly&socketFactory=com.google.cloud.sql.postgres.SocketFactory&user=postgres&password=postgres"
statement => "SELECT * FROM people;"
jdbc_user => "postgres"
jdbc_password => "postgres"
}
}
output {
stdout {
codec => rubydebug {
}
}
}
jdbc user and password are ignored and the ones you provide in the connection string are used instead. For Postgre Cloud SQL connector you can use both Postgre users or IAM accounts.
Note: You need to run this from a Compute Engine to automatically apply the gcp credentials or manually create the env variables

Gem 'whenever' in rails 4

I try to send message automatically by using whenever gem. I am in initial step. I install the gem 'whenever'. I done the following step.
1. Add "gem 'whenever', :require => false" to the gemfile.
2. bundle install.
3. wheneverize .
4. in schedule.rb add the following code,
set :output, "#{path}/log/cron.log"
#every 1.day, :at => '4:30 am' do
every 5.minutes do
runner "Payment.sendMessage", :environment => "development"
end
5.And model likes,
class Payment < ActiveRecord::Base
def sendMessage
puts"Hello"
end
end
6. When I use bundle exec whenever, I get like the following issue as
0,5,10,15,20,25,30,35,40,45,50,55 * * * * /bin/bash -l -c
'cd /home/prabha/rails_job && bundle exec bin/
rails runner -e development '\''Payment.sendMessage'\'' >>
/home/prabha/rails_job/log/cron.log 2>&1'
## [message] Above is your schedule file converted to cron syntax;
your crontab file was not updated.
## [message] Run `whenever --help' for more options.
I am stuck with this step. what I want to do the further proceed? Anyone guide me.
Thanks.
You need to update you crontab file.
Do the following -
whenever --update-crontab
For more information, please check whenever gem's Github ReadMe page.
1) sendMessage should be a class method.
2) You can use "whenever" command in your project directory to see the cron configuration and then copy into your crontab.

NoMethodError on 'release_path' during chef deployment

I'm pretty new to Chef deployments, and I'm trying to deploy a rails app with OpsWorks. The trouble is with asset precompilation.
I have this recipe to perform precompilations:
execute "rake assets:precompile" do
cwd release_path
command "bundle exec rake assets:precompile --trace"
environment "RAILS_ENV" => "production"
end
When I deploy with Chef, I get the following error:
ERROR: undefined method `release_path' for Chef::Resource::Execute
What's weird is that every example recipe I can find makes use of the release_path helper. How could it not be defined here?
Here is how I do precompile on a rails application on opsworks:
This code is placed in your applications deploy folder, in a file called "before_migrate.rb" in /approot/deploy/before_migrate.rb.
The environment variables are created in the application defined in opsworks.
rails_env = new_resource.environment["RAILS_ENV"]
secret_key_base = new_resource.environment["SECRET_KEY_BASE"]
devise_secret_key = new_resource.environment["DEVISE_SECRET_KEY"]
Chef::Log.info("Precompiling assets for RAILS_ENV=#{rails_env}...")
Chef::Log.info("SECRET_KEY_BASE=#{secret_key_base}, DEVISE_SECRET_KEY=#{devise_secret_key}")
execute "rake assets:precompile" do
cwd release_path
command "RAILS_ENV=#{rails_env} bundle exec rake assets:precompile"
environment "RAILS_ENV" => rails_env
environment "SECRET_KEY_BASE" => secret_key_base
environment "DEVISE_SECRET_KEY" => devise_secret_key
end
I fixed this by using node[:deploy]['appshortname'][:deploy_to]. My full recipe is below:
node[:deploy].each do |application, deploy|
execute "rake assets:precompile" do
cwd "#{deploy[:deploy_to]}/current"
command "bundle exec rake assets:precompile --trace"
environment deploy[:environment_variables].merge(
"RAILS_ENV" => deploy[:rails_env]
)
end
end

Chef Solo Jetty Cookbook Attributes

I'm having an issue where my chef.json attributes in my Vagrantfile seem to be getting ignored/overwritten.
Environment: Mac OS X 10.8 host, Ubuntu 12.04 guest virtualized in VirtualBox 4.18. Using Berkshelf for cookbook dependencies and the Opscode cookbooks for all of the recipes.
The box is spinning up fine, but I'm trying to configure more like it would look if I downloaded Jetty and un-tarred the archive, rather than a bunch of symlinks from /usr/share/jetty to all over the filesystem the way it seems to be defaulting to.
Here's the chef portion of my Vagrantfile:
config.vm.provision :chef_solo do |chef|
chef.json = { :java => {
:install_flavor => "oracle",
:jdk_version => '7',
:oracle => {
:accept_oracle_license_terms => true
}
},
:jetty => {
:port => '8080',
:home => '/opt/jetty',
:config_dir => '/opt/jetty/conf',
:log_dir => '/opt/jetty/log',
:context_dir => '/opt/jetty/context',
:webapp_dir => '/opt/jetty/webapp'
}
}
chef.add_recipe "apt"
chef.add_recipe "mongodb::default"
chef.add_recipe "java"
chef.add_recipe "jetty"
end
Chef seems to be reading the chef.json because I can change Jetty's port in the Vagrantfile.
I've tried to change these attributes in attributes/default.rb of the Jetty cookbook, but that didn't help either.
What am I missing?
If you take a look at the below block in jetty/recipes/default.rb
jetty_pkgs = value_for_platform(
["debian","ubuntu"] => {
"default" => ["jetty","libjetty-extra"]
},
["centos","redhat","fedora"] => {
"default" => ["jetty6","jetty6-jsp-2.1","jetty6-management"]
},
"default" => ["jetty"]
)
jetty_pkgs.each do |pkg|
package pkg do
action :install
end
end
For Debian/Ubuntu, the default recipe uses DEB packages from official repository instead of what you want (download binary from official website, untar it into your preferred location).
Because DEB packages have their own specifications (run dpkg -L jetty to see their files/directories structure), I reckon that's why your attribute overrides in chef.json did not work.
You can enable debugging output to see more information when you run provision again
VAGRANT_LOG=debug vagrant up
NOTE: It's probably better off writing your own cookbook to download the binary and untar set permissions and do other stuff if you want Jetty to be installed the way you like;-)

puppet exec vagrant plugin install not working

I have successfully installed vagrant-aws on a centos VM, and I am trying to 'puppetize' this task. My relevant puppet code is below:
exec { 'install_aws':
command => '/usr/bin/vagrant plugin install vagrant-aws',
#require => [Exec['install_dependent'], Package['vagrant']],
}
When I provision the machine, it says the Exec[install_aws]/returns: executed successfully, but the plugin is not installed, and I have to run the command manually for it to work. Never seen this behaviour with puppet, can someone help?
exec { 'install_aws':
command => '/usr/bin/sudo /usr/bin/vagrant plugin install vagrant-aws',
require => [Exec['install_dependent'], Package['vagrant']],
}
Fixed the code above. Good point, needed to run the command as superuser. Seems like a silly mistake, thanks for pointing it out ^^.
Instead of using sudo to run that command (as you pointed out in your answer), I would add the user paramater to the exec and run it as root (or any other user with suitable permissions)
exec { 'install_aws':
user => 'root',
command => '/usr/bin/vagrant plugin install vagrant-aws',
require => [Exec['install_dependent'], Package['vagrant']],
}