7

I'm pretty new to Puppet, but I really like it thus far. Right now I'm currently setting it up to automate a small architecture.

I have one problem though -- I want to remove a package, and ensure that it is stopped. To accomplish this, I have the following entry in my manifest:

package { 'supervisor':
    ensure => absent,
}

service { 'supervisor':
    ensure     => stopped,
    enable     => false,
    hasstatus  => true,
}

The problem with this is that once the manifest been applied to the node once, I get the following error upon next run:

debug: Service[supervisor](provider=debian): Could not find supervisor in /etc/init.d
debug: Service[supervisor](provider=debian): Could not find supervisor.sh in /etc/init.d
err: /Stage[main]/Screenly_core/Service[supervisor]: Could not evaluate: Could not find init script for 'supervisor'

Is there any way to do some kind of conditional statement, such that the stop-procedure only gets executed if the package was indeed present (and then run prior to the package removal)?

vpetersson
  • 861
  • 1
  • 11
  • 22
  • believe you are asking about what in puppet terminology is called "subscribing". The same way in the examples ntp is restarted after being installed or updated, you can do what you want here. – Sirex Jan 08 '12 at 15:31
  • 2
    try here: http://docs.puppetlabs.com/learning/ordering.html – Sirex Jan 08 '12 at 15:32
  • 5
    Isn't it enough to just remove the package? It should be automatically stopped. – Khaled Jan 08 '12 at 17:03
  • @Khaled I'm not sure. Perhaps, but I'm rater be safe than sorry. – vpetersson Jan 09 '12 at 15:49
  • @Sirex Ordering does not help here. To stop a service you need an init script, which is usually part of the package. But you want to uninstall the package at the same time. For me it looks like it's not solvable with normal puppet means. – Slaven Rezic Nov 25 '15 at 14:23
  • @Khaled Maybe this is done in Debian packages, but other packaging systems may not work like this and don't stop the service automatically on uninstall. – Slaven Rezic Nov 25 '15 at 14:24

1 Answers1

3

On debian based systems (and I assume also on rpm systems) removing a package stops its services before deleting files (prerm phase in deb packages).

But what you ask can be achieved by inserting a dependency with 'require'

package { 'supervisor':
    ensure => absent,
    require => Service["supervisor"],
}

service { 'supervisor':
    ensure     => stopped,
    enable     => false,
    hasstatus  => true,
}
hayalci
  • 3,631
  • 3
  • 27
  • 37
  • Thanks @hayalci. I think it should be the other way around though: package { 'supervisor': ensure => absent, } service { 'supervisor': ensure => stopped, enable => false, hasstatus => true, require => Package["supervisor"], } However, I still get errors, just fewer of them. – vpetersson Jan 09 '12 at 15:53