stop service after install

39 views
Skip to first unread message

Anton Gorlov

unread,
May 13, 2017, 5:46:03 AM5/13/17
to puppet...@googlegroups.com
Hi.

I need stop service (apache) after it install from puppet.
platform is debian 9 and puppet version is 4.8.2

I my class i wrote:

========
class webpackages {

exec { 'apachechk':
command => "/bin/systemctl stop apache2;",
onlyif => "/bin/grep -c 'Listen 80' /etc/apache2/ports.conf",
}

package { 'libapache2-mpm-itk':
ensure => latest,
}

package { 'apache2':
require => Exec['apachechk'],
ensure => latest,
}

package { 'apache2-dev':
ensure => latest,
}
package { 'apache2-suexec-pristine':
ensure => latest,
}
package { 'apache2-utils':
ensure => latest,
}
package { 'apache2-bin':
ensure => latest,
}
package { 'apachetop':
ensure => latest,
}
package { 'libapache2-mod-rpaf':
ensure => latest,
}
package { 'nginx-light':
require => Exec['apachechk'],
ensure => latest,
}

}
===

but apache not stopping and install nginx is fail because port is busy
by apache

May 13 12:21:29 debian9-lab3 nginx[19538]: nginx: [emerg] listen() to
[::]:8…se)
May 13 12:21:29 debian9-lab3 nginx[19538]: nginx: [emerg] listen() to
0.0.0.…se)
May 13 12:21:29 debian9-lab3 nginx[19538]: nginx: [emerg] listen() to
[::]:8…se)
May 13 12:21:30 debian9-lab3 nginx[19538]: nginx: [emerg] listen() to
0.0.0.…se)
May 13 12:21:30 debian9-lab3 nginx[19538]: nginx: [emerg] listen() to
[::]:8…se)
May 13 12:21:30 debian9-lab3 nginx[19538]: nginx: [emerg] still could
not bind()

What is wrong and what is right way to do it?

Poil

unread,
May 14, 2017, 9:10:49 AM5/14/17
to puppet...@googlegroups.com, Anton Gorlov
Why do you want to stop it ? I think you want to change the listen port.

So I think something like this will do the job :

package { 'apache2': ensure => installed, }

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

file { '/etc/apache2/conf.d/listen_port.conf':
content => "your_template.conf.erb",
require => Package['apache2'],
notify => Service['apache2'], # Refresh apache after the listen_port
is changed
}

package {'nginx':
ensure => installed,
require => Service['apache2'], # Install nginx after apache have been
restarted with another config

Ramin K

unread,
May 14, 2017, 3:07:59 PM5/14/17
to puppet...@googlegroups.com
I'd guess that installing new modules are restarting the service. You
probably need something with better ordering.

class apache {
contain ::apache::install
contain ::apache::config
contain ::apache::service
Class['::apache::install'] ->
Class['::apache::config'] ~>
Class['::apache::config']
}
class apache::install {
package { 'libapache2-mpm-itk':
ensure => latest,
}
package { 'apache2':
ensure => latest,
}
# etc etc
}
class apache::config {
file { '/etc/apache2/ports.conf':
ensure => file,
content => "Listen 8080\n",
}
}
class apache::service {
service { 'apache':
ensure => running
enable => true,
}
}
class nginx {
package { 'nginx-light':
ensure => latest,
}
}
class profile::webstack {
include ::apache
include ::nginx
Class['::apache'] -> Class['nginx']

Rob Nelson

unread,
May 14, 2017, 3:57:55 PM5/14/17
to puppet...@googlegroups.com
It might be worth pointing out that puppetlabs/apache is a component module that helps address some of these common issues, and using it instead of writing your own apache module is probably worth considering in this case.

--
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+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/puppet-users/1da0051d-a3d1-6472-2ad6-3af335f7503a%40badapple.net.
For more options, visit https://groups.google.com/d/optout.

Anton Gorlov

unread,
May 15, 2017, 7:52:57 AM5/15/17
to puppet...@googlegroups.com
Hi.
At the current moment I need bind  the apache to localhost:80 and nginx to external_ip:80.
I cannot change nginx config before it installed and debian start nginx automatic after install  package with  default configuration (bind to *:80) => conflict.

So first I stop  the apache service, after install nginx and go update config's...


14.05.2017 16:10, Poil пишет:

R.I.Pienaar

unread,
May 15, 2017, 8:16:38 AM5/15/17
to puppet...@googlegroups.com


On Mon, May 15, 2017, at 13:52, Anton Gorlov wrote:
> Hi.
> At the current moment I need bind the apache to localhost:80 and nginx
> to external_ip:80.
> I cannot change nginx config before it installed and debian start nginx
> automatic after install package with default configuration (bind to
> *:80) => conflict.
>
> So first I stop the apache service, after install nginx and go update
> config's...

debian will not overwrite configs on package install - suggest you put a
config down that does what you want first.

Debian is just by design stupid, thinks starting all services
unconfigured on install is a good idea, suggest you use a OS designed to
be used on servers and not peoples basements.

Anton Gorlov

unread,
May 15, 2017, 8:36:49 AM5/15/17
to puppet...@googlegroups.com
15.05.2017 15:16, R.I.Pienaar пишет:
Debian is just by design stupid, thinks starting all services
unconfigured on install is a good idea, suggest you use a OS designed to
be used on servers and not peoples basements.

Yes this is true...
But I can't change OS at current time.


Question why does not work exec in package install

Anton Gorlov

unread,
May 17, 2017, 8:38:25 AM5/17/17
to puppet...@googlegroups.com
Hi.
At the current moment I need bind  the apache to localhost:80 and nginx to external_ip:80.
I cannot change nginx config before it installed and debian start nginx automatic after install  package with  default configuration (bind to *:80) => conflict.

So first I stop  the apache service, after install nginx and go update config's...


14.05.2017 16:10, Poil пишет:
Why do you want to stop it ? I think you want to change the listen port.

John Gelnaw

unread,
May 17, 2017, 1:21:19 PM5/17/17
to Puppet Users
On Monday, May 15, 2017 at 8:16:38 AM UTC-4, R.I. Pienaar wrote:

debian will not overwrite configs on package install - suggest you put a
config down that does what you want first.

Or, I dunno, maybe he could could tie the service to the config file, and restart apache when the config file changes, and "require" the apache2 class as part of his nginx setup.

So Puppet would install apache (starting the service), install the config file (restarting apache), and then install nginx.

class apache2  {

  $pkglist
= ['apache2', 'apache2-dev', .... ]

 
package { $pkglist:
     
ensure   => latest,
     
alias    => 'apache2'
 
}
  file
{ '/etc/apache2/conf.d/ports.conf':
    content
=> 'Listen 127.0.0.1:80',

   
require => Package['apache2'],
    notify  
=> Service['apache2']
 
}

  service
{ 'apache2':
   
ensure      => running,

    refreshonly
=> true
 
}
}

class nginx  {

 
require apache2

 
package { ... }

  service
{ ... }

}

That's just off the top of my head, and isn't really The Right Way, but it's got all the components.
 
Debian is just by design stupid, thinks starting all services
unconfigured on install is a good idea, suggest you use a OS designed to
be used on servers and not peoples basements.

That is probably the single worst piece of advice I've seen on this forum.  It's hostile, short-sighted, and not terribly useful.

Debian has been a better "server" OS for years, in that it supports in-place upgrades, and makes it easier to control which packages are installed from which repositories.

Our environment has about 200 web and database servers, about 60% of which are Red Hat, and the rest are Debian.  They're both perfectly good operating systems for production servers, but they do require the admin be open-minded enough to actually learn the differences between the two paradigms-- otherwise, you might as well run Windows.

Poil

unread,
May 17, 2017, 5:06:33 PM5/17/17
to puppet...@googlegroups.com, John Gelnaw
I'm agree with "Debian is just by design stupid, thinks starting all services"
All other integration are really fine, but  auto-starting after install is terrible for all configuration management :
Change a path (mysql binary log for example), a mount point (a LV for mysql) before installing : Nope you can't
You have to write a hack to remove all autostart from the package before installing it that's incredible.

I dream about a Debian mix with RedHat, RPM, no auto-start but all the configuration system from Debian (splited-conf for apache php ... and tools to manage your modules)
--
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/a3979ccc-0761-4a26-8a3d-26d38ff7f6bb%40googlegroups.com.

John Gelnaw

unread,
May 17, 2017, 6:27:50 PM5/17/17
to Puppet Users, jge...@gmail.com
On Wednesday, May 17, 2017 at 5:06:33 PM UTC-4, Poil wrote:
I'm agree with "Debian is just by design stupid, thinks starting all services"
All other integration are really fine, but  auto-starting after install is terrible for all configuration management :
Change a path (mysql binary log for example), a mount point (a LV for mysql) before installing : Nope you can't
You have to write a hack to remove all autostart from the package before installing it that's incredible.

I dream about a Debian mix with RedHat, RPM, no auto-start but all the configuration system from Debian (splited-conf for apache php ... and tools to manage your modules

Well, what you're complaining about is the package maintainers, not the OS-- it's the post install scripts that start up the services.  You might want to look into openSuSE-- RPM based, but package configuration tends to be more modular than Red Hat.  The openSuSE build service is also a nice feature.

You'll still run into the same thing with openSuSE and Red Hat-- RHEL7, if you install "nfs-utils" (traditionally the "nfs client" package-- but now it's the server package too), for example, you get the NFS server installed, running, set to auto-start, with portmapper running.

And I'm sure for every person who gripes about package X installing itself as 'autostart', you'll find at least one person who complains that they've got to enable the service after installation.

Personally, I don't care-- ultimately, I use puppet to ensure the package is installed, configured, and the service is enabled how *I* want it.  Nearly all of my configuration changes are linked to the service, so if I update a config file, the service is automatically restarted.  That's kind of the whole point of puppet.

Calling an OS "stupid" because they made decisions you disagree with is short-sighted.
Reply all
Reply to author
Forward
0 new messages