Stop and Start Services running on Puppet Master or Agent Machine

2,619 views
Skip to first unread message

Satish Katuru

unread,
Jun 20, 2014, 6:02:01 AM6/20/14
to puppet...@googlegroups.com
Hi,

I am new to Puppet and We are trying to stop and start any one of the services running on the Puppet master /agent machine.

Here is the Scenario:


1. we have a Jboss service running on Puppet master and I am trying to kill this service thru puppet.(this service is runnning with my userid)

Service name is "java".

2. In /etc/puppet/manifests/nodes.pp I have written code like this

node "servername"
{

Service {

"java":
ensure = >"Stopped",

}
}

after this I ran this command

puppet apply nodes.pp

Nothing has happend.Still the process is running.(I am able to see the process id : ps -ef|grep java)

3.After this i created a module and place this code in init.pp in /etc/puppet/modues/httpd/

node "servername"
{
inlcude httpd
}

puppet apply nodes.pp


Nothing happend.

Can you please guide us how to kill a process?








Christopher Wood

unread,
Jun 20, 2014, 1:25:14 PM6/20/14
to puppet...@googlegroups.com
Roughly speaking the service name is the init script name, so if you would manually stop/stop with /etc/init.d/java, then your service name in puppet is also java.


node "servername" {
Service { "java":
ensure = >"Stopped",
}
}

Using "Resource" (initial capital) instead of "resource" (all lower case) is for defaults. You probably want to use "service" there.

You probably also want enable => false, so that the service will not start on boot.

Using debug/verbose will help you:

puppet apply --debug manifest.pp
puppet apply --verbose manifest.pp
> --
> You received this message because you are subscribed to the Google Groups
> "Puppet Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [1]puppet-users...@googlegroups.com.
> To view this discussion on the web visit
> [2]https://groups.google.com/d/msgid/puppet-users/c81e168e-38f0-416c-b0c2-bd0124c9e760%40googlegroups.com.
> For more options, visit [3]https://groups.google.com/d/optout.
>
> References
>
> Visible links
> 1. mailto:puppet-users...@googlegroups.com
> 2. https://groups.google.com/d/msgid/puppet-users/c81e168e-38f0-416c-b0c2-bd0124c9e760%40googlegroups.com?utm_medium=email&utm_source=footer
> 3. https://groups.google.com/d/optout

Brian Mathis

unread,
Jun 20, 2014, 6:26:43 PM6/20/14
to puppet-users
Summary: Do not try to control processes directly with Puppet and instead properly integrate your service into your operating system.

-----

It sounds like you are misunderstanding how Puppet integrates into the rest of the system.  Puppet should not "kill processes" directly like you would with the 'kill' command (actually, it can, but this is almost certainly NOT what you want).  I think you may also be misunderstanding some basic concepts of running a Linux/Unix server.

A process is not the same thing as a service.  A single service may have many processes, and they are typically controlled by a script in the /etc/init.d directory (or maybe somewhere else if you are on a newfangled system running systemd).  If your process does not have a control script in /etc/init.d, then is is NOT a "service", it's just a process you happen to have running for a long time.  For Puppet to consider it a service, it must be controllable using the 'service' command (on RedHat based systems), or the equivalent for your version of Linux/Unix.

What you really want is to be making and installing a bash script to control your java process in /etc/init.d.  Once written, you can use Puppet to install the script by using the "file" resource.  After you have that done, then you can use the "service" resource to control the service as you are tying to do.  The name of the service will be the name that you call your script in /etc/init.d, for example: /etc/init.d/my_service.  Please do not call your service "java", as it makes no sense to name a service after the programming language it is written in.  If it's an accounting system for example, call the service "accounting_system", or something like that.


You are bound to get some other replies telling you how to use an 'exec' resource to call the "kill" command, etc..., since this is *possible* with Puppet, but it is grossly abusive of its capabilities and you really should not be doing that.  Please do this correctly by setting up your software as a real service and then control it correctly with the "service" resource in Puppet.

I strongly suggest you walk through the Puppet tutorials at https://puppetlabs.com/learn before trying to control your own custom applications with it.


❧ Brian Mathis
@orev


--
You received this message because you are subscribed to the Google Groups "Puppet Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to puppet-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/puppet-users/c81e168e-38f0-416c-b0c2-bd0124c9e760%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Satish Katuru

unread,
Jun 23, 2014, 2:40:26 AM6/23/14
to puppet...@googlegroups.com
Thanks Brian Mathis.I will try this and will get back to you once we come across any blocking.

Satish Katuru

unread,
Jun 23, 2014, 8:06:07 AM6/23/14
to puppet...@googlegroups.com


On Saturday, June 21, 2014 3:56:43 AM UTC+5:30, Brian Mathis wrote:

Satish Katuru

unread,
Jun 23, 2014, 8:06:56 AM6/23/14
to puppet...@googlegroups.com
Hi Brian Mathis,
I followed your instructions and it is working fine.Thanks a lot for your information.

Regards,
Sathish.


On Saturday, June 21, 2014 3:56:43 AM UTC+5:30, Brian Mathis wrote:

Satish Katuru

unread,
Jun 26, 2014, 8:47:35 AM6/26/14
to puppet...@googlegroups.com
Hi Brian Mathis,

I tired to copy the jar files and Zip files from Master to agent machine but i am unable to do this.
My init.pp looks like below:

class httpd
{


file { "/home/katusa02/soa/jboss-soa-p-5/jboss-as/server/default/deploy/ParserService-1.0.esb":
ensure => present,
owner => "katusa02",
group => "katusa02",
mode => "0777",
source => "puppet://$puppetserver/modules/httpd/ParserService-1.0.esb",

}

}

I tired with ensure => file and ensure =>"present" but didn't work.
Can you please guide me how to do this?

Moreover I got following error message:


Error: /Stage[main]/Httpd/File[/home/katusa02/soa/jboss-soa-p-5/jboss-as/server/default/deploy/ParserService]: Could not evaluate: Could not retrieve information from environment production source(s) puppet://dayrhetamp076.enterprisenet.org/modules/httpd/ParserService

Regards,
Sathish.

On Saturday, June 21, 2014 3:56:43 AM UTC+5:30, Brian Mathis wrote:

Brian Mathis

unread,
Jun 26, 2014, 2:47:06 PM6/26/14
to puppet-users
Your "source" line needs 3 slashes after "puppet:"
    source => "puppet:///$puppetserver/modules/httpd/ParserService-1.0.esb",


❧ Brian Mathis
@orev


Satish Katuru

unread,
Jun 30, 2014, 3:03:32 AM6/30/14
to puppet...@googlegroups.com
Hi Brian Mathis,

I think no need to put 3 slashes after "puppet" because i have declared this variable in site.pp
$server="..." .
Event I tried with placing 3 slashes and it was throwing an error message.
Am I missing any thing here?


My site.pp :

import 'nodes.pp'
$puppetserver = 'dayrhetamp076.enterprisenet.org'

and in the nodes.pp I have declared node.

Regards,
Sathish.

Rich Burroughs

unread,
Jun 30, 2014, 4:10:54 AM6/30/14
to puppet...@googlegroups.com
I think you're right about the two slashes, if you're specifying the hostname.

One thing you might try is running puppet parser validate on your manifest, if you haven't. I'm not sure what the problem is based on your code examples, it's not jumping out at me, but that might point it out. There's some info on that here:


We use a git hook where I work so that command runs before we're able to commit code.

Also you might try substituting the actual server name in that puppet URL, I'd be curious if that works. 

You could also put a notify in your manifest to print the value of $puppetserver if you want to make sure that's getting picked up. There are some examples of that here:


And you can always run the agent with --debug.


Rich

Satish Katuru

unread,
Jun 30, 2014, 8:06:22 AM6/30/14
to puppet...@googlegroups.com
Hi Brain,

Here is the detailed steps:


Error: /Stage[main]/Httpd/File[/etc/puppet/modules/hello.txt]: Could not evaluate: Could not retrieve information from environment production source(s) puppet://dayrhetamp076.enterprisenet.org/modules/httpd/hello


In Master Server it couldn't identify the path of the source file.


Here are my nodes.pp,site.pp and init.pp

{

include httpd

}
---

import 'nodes.pp'

----

class httpd
{

file 
{
"/etc/puppet/modules/hello.txt":
ensure => file,
owner => "katusa02",
group => "katusa02",
mode => "0640",
source =>"puppet://$puppetserver/modules/httpd/hello",

}
}

And on the Agent Machine(*077) I have included below code in the config file

        autosign = true
        server = dayrhetamp076.enterprisenet.org

------
I folllowed all the steps
a) Stopped Master process on Master machine
b) Removed SSL folder and restarted Puppet Master Service
c) Removed SSL folder from Agent Machine
d) Executed the command sudo  puppet agent -t --waitforcert=60 (Certificate has been generated and singed)

Please help me out to resolve this?

Regards,
Sathish.

Martin Alfke

unread,
Jun 30, 2014, 8:42:14 AM6/30/14
to puppet...@googlegroups.com
Hi Brian,

braindead question:
is a file with name hello in modules/httpd/files/ available??

- Martin


On 30 Jun 2014, at 14:06, Satish Katuru <satish...@gmail.com> wrote:

> Hi Brain,
>
> Here is the detailed steps:
>
>
> Error: /Stage[main]/Httpd/File[/etc/puppet/modules/hello.txt]: Could not evaluate: Could not retrieve information from environment production source(s)puppet://dayrhetamp076.enterprisenet.org/modules/httpd/hello
> To view this discussion on the web visit https://groups.google.com/d/msgid/puppet-users/63906ca4-8493-4260-8683-120c2d3334af%40googlegroups.com.

jcbollinger

unread,
Jun 30, 2014, 9:22:34 AM6/30/14
to puppet...@googlegroups.com


On Monday, June 30, 2014 7:06:22 AM UTC-5, Satish Katuru wrote:
Hi Brain,

Here is the detailed steps:


Error: /Stage[main]/Httpd/File[/etc/puppet/modules/hello.txt]: Could not evaluate: Could not retrieve information from environment production source(s) puppet://dayrhetamp076.enterprisenet.org/modules/httpd/hello


In Master Server it couldn't identify the path of the source file.


Here are my nodes.pp,site.pp and init.pp

{

include httpd

}
---

import 'nodes.pp'

----

class httpd
{

file 
{
"/etc/puppet/modules/hello.txt":
ensure => file,
owner => "katusa02",
group => "katusa02",
mode => "0640",
source =>"puppet://$puppetserver/modules/httpd/hello",

}
}



If you are trying to have the agent retrieve the file from the same master that serves its catalog, then you do not need or want to put the master's hostname in the URL.  In URI-speak, you specify an altogether empty 'authority', leaving 'path' adjacent to the '//', like so:

  puppet:///modules/httpd/hello.txt

That's how you get three adjacent slashes -- the empty authority is between (sort of) the second and the third.

 
And on the Agent Machine(*077) I have included below code in the config file

        autosign = true
        server = dayrhetamp076.enterprisenet.org



With that said, although I have never discovered a good use case for specifying an authority in a puppet:// URI, what you are doing with that looks like it should work.

Is it possible that the problem relates to the fact that you are trying to manage a file named "hello.txt", but you give a source URI for a file named simply "hello"?


John

Satish Katuru

unread,
Jul 1, 2014, 2:23:26 AM7/1/14
to puppet...@googlegroups.com
Yes It is.The file is available in the /modules/httd

Martin Alfke

unread,
Jul 1, 2014, 2:38:22 AM7/1/14
to puppet...@googlegroups.com
Next braindead question:

in your file resource you want the destination on the node to be /etc/puppet/modules/hello.txt.
Is the directory /etc/puppet/modules already present? (_on the node_ !!)

- Martin
> To view this discussion on the web visit https://groups.google.com/d/msgid/puppet-users/a69ea656-d176-476c-a8f0-bba7c7d31fc6%40googlegroups.com.

Satish Katuru

unread,
Jul 1, 2014, 4:32:12 AM7/1/14
to puppet...@googlegroups.com
Yes,the folder is present in the Agent machine.The thing is in the Master Server it is unable to locate the Source file itself.

jcbollinger

unread,
Jul 1, 2014, 9:20:02 AM7/1/14
to puppet...@googlegroups.com


On Tuesday, July 1, 2014 3:32:12 AM UTC-5, Satish Katuru wrote:
Yes,the folder is present in the Agent machine.The thing is in the Master Server it is unable to locate the Source file itself.

Not necessarily.  The master is unable to read the file, but that does not necessarily mean it cannot locate it.

The master will be looking for this file:

  <modulepath>/httpd/files/hello

Note the "files/" segment of the filesystem path, which does not appear in the URI.  Note also, again, that your source URI does not match the destination file name in that the source has no ".txt" extension.  The source URI doesn't need to match the destination name (at all), but typically it does.  The mismatch could be a sign that the URI does not match the actual name of the source file (which it does need to do, of course).

Supposing that the source file exists, in the correct location, and with a name matching the given source URI, the master still needs to be able to read it.  Check the ownership and permissions of the source file, and if SELinux is running in enforcing mode on the master then check that the source file is labelled such that Puppet can read it.  Note here that the master normally runs as an unprivileged user (often named "puppet").


John

Satish Katuru

unread,
Jul 2, 2014, 8:32:00 AM7/2/14
to puppet...@googlegroups.com
Hi,

You were correct.We should put our source files under Files folder.
Reply all
Reply to author
Forward
0 new messages