Re: how to check whether a linux process is running?

1,853 views
Skip to first unread message

Paul Tötterman

unread,
Feb 13, 2013, 3:04:58 AM2/13/13
to puppet...@googlegroups.com
Hi Oliver,

if process A is running, do nothing.

else mount share and install package A

This doesn't really sit well with the declarative nature of Puppet. It would be better if your package pre-installation scripts were to cleanly implement this imperative procedure. Something like shut down service, mount, install, start service back up.

If you really want to try doing this with puppet, look at exec and onlyif/unless ( unless => 'pgrep process' ) and dependencies.

Cheers,
Paul 

Matthew Burgess

unread,
Feb 13, 2013, 4:10:24 AM2/13/13
to puppet...@googlegroups.com
On Wed, Feb 13, 2013 at 3:53 AM, oliver zhang <oliver....@gmail.com> wrote:
> Hi Everyone,
>
> I'm new to puppet.
>
> How do I do this in puppet:
>
> if process A is running, do nothing.
>
> else mount share and install package A
>
> I couldn't find any reference about this.
>
> Thanks.

In addition to what Paul says, the way that something like this would
normally be handled in Puppet is:

1) If process A is not running, start process A (this could be done via an Exec)
2) Step 1 may fail, because the binary used to launch process A is not
installed. So, you'd also have a Package resource that would manage
the package that contains that binary. At this point, the Exec can be
told to depend on the Package such that trying to start process A will
automatically trigger the installation of the necessary Package if
it's not already installed.
3) The Package (or particular configuration thereof) may require a
mount point to be available. So, you'd also have a Mount resource
that would configure that mount point. At this point, the Package
resource configured in step 2 can be told to depend on the Mount
resource such that installing the Package will automatically set up
and mount the Mount point resource.
4) Your node's manifest would only contain the Exec set up in step 1;
everything else will automatically be configured through the defined
dependency relationships.

Regards,

Matt.

Matthias Viehweger

unread,
Feb 13, 2013, 4:41:32 AM2/13/13
to puppet...@googlegroups.com
Hi Oliver!

On Tue, Feb 12, 2013 at 07:53:55PM -0800, oliver zhang wrote:
> How do I do this in puppet:
>
> if process A is running, do nothing.
>
> else mount share and install package A
>
> I couldn't find any reference about this.

I would first ensure that the process is running (assuming that it's a
service). The service would require the package which would require the
share to be mounted.

A rough outline would be:

service { 'A':
ensure => running,
require => Package['A'];
}

package { 'A':
ensure => installed,
require => Exec['mount share'];
}

exec { 'mount share':
command => '...',
if => command to check if not mounted;
}

I may be wrong, of course, but this would be my first try to resolve
this.

Cheers,
Matthias
--
Serververwaltung und Softwareentwicklung

https://www.heute-kaufen.de
Prinzessinnenstraße 20 - 10969 Berlin
signature.asc

Peter Brown

unread,
Feb 13, 2013, 8:03:56 PM2/13/13
to puppet-users
On 13 February 2013 19:41, Matthias Viehweger <m.vie...@heute-kaufen.de> wrote:
Hi Oliver!

On Tue, Feb 12, 2013 at 07:53:55PM -0800, oliver zhang wrote:
> How do I do this in puppet:
>
> if process A is running, do nothing.
>
> else mount share and install package A
>
> I couldn't find any reference about this.

I would first ensure that the process is running (assuming that it's a
service). The service would require the package which would require the
share to be mounted.

+1

I was just about to recommend doing it in a similar way.
It's not too tricky to make a service in linux if your application isn't already one.

A rough outline would be:

  service { 'A':
    ensure => running,
    require => Package['A'];
  }

  package { 'A':
     ensure => installed,
     require => Exec['mount share'];
  }

  exec { 'mount share':
    command => '...',
    if => command to check if not mounted;
  }

I may be wrong, of course, but this would be my first try to resolve
this.

Nope not wrong at all.
I would probably recommend putting them in separate subclasses and then using class chaining or require => Class[blah::service] etc
to make it easier to add new packages or services later but the theory is the same.
Reply all
Reply to author
Forward
0 new messages