homar
homar

Reputation: 595

How to make puppet run java program?

I am quite new to puppet and I am pretty sure I make some very silly mistakes. However I need to have puppet starting a druid cluster on the vagrant machine. I was not able to come with any better solution than this:

exec { "run_coordinator":
  cwd     => "/tmp/druid-services-0.6.160/",
  command => "java -Xmx256m -Duser.timezone=UTC -Dfile.encoding=UTF-8 -classpath lib/*:config/coordinator io.druid.cli.Main server coordinator",
  path    => ["/bin", "/usr/bin"],
  require => [ Exec["run_zooKeeper"] ],
}

exec { "run_historical":
  cwd     => "/tmp/druid-services-0.6.160/",
  command => "java -Xmx256m -Duser.timezone=UTC -Dfile.encoding=UTF-8 -classpath lib/*:config/historical io.druid.cli.Main server historical",
  path    => ["/bin", "/usr/bin"],
  require => [ Exec["run_coordinator"] ],
}

exec { "run_broker":
  cwd     => "/tmp/druid-services-0.6.160/",
  command => "java -Xmx256m -Duser.timezone=UTC -Dfile.encoding=UTF-8 -classpath lib/*:config/broker io.druid.cli.Main server broker",
  path    => ["/bin", "/usr/bin"],
  require => [ Exec["run_historical"] ],
}

When I run it I get /Stage[last]/Install_druid/Exec[run_coordinator]/returns: change from notrun to 0 failed: Command exceeded timeout at /xxx/base.pp:xxx I guess I could simply add & but I am sure this is not the cleanest way to do this. Any advices? Thanks in advance.

Upvotes: 1

Views: 1627

Answers (1)

Felix Frank
Felix Frank

Reputation: 8223

Adding & might work when you're using provider => shell.

But yes, it would be cleaner to build a simple script that wraps the actual call, and forks it into the background.

#!/bin/sh

if [ "$1" == "-d" ] ; then
    $0 &
    exit 0
fi

PATH=/bin:/usr/bin

cd /tmp/druid-services-0.6.160/
java -Xmx256m -Duser.timezone=UTC -Dfile.encoding=UTF-8 -classpath lib/*:config/broker io.druid.cli.Main server broker

It would be cleaner yet to build init scripts or similar service controllers and use a service resource.

service {
    'druid_broker':
        ensure => 'running',
        enable => true;
}

Don't run your services from /tmp though. That's just horrible.

Upvotes: 1

Related Questions