Ask Your Question
0

How to manage the service for web server and app?

asked 2016-07-30 03:47:32 -0600

kaizenCoder gravatar image

updated 2016-08-04 21:12:32 -0600

Hi there,

I have a use case where we currently manage a web server, and an app. Now this similar to deploying tomcat and a webapp or apache and a php app. Both the server and the app subscribe to the Package/File/Service pattern however I seem to have hit a problem managing the service (requiring the web server service to restart when the app config files changes).

This is the structure of the mdule (to manage the server & app as a defined type):

.

├── app 

│   ├── config.pp 

│   ├── install.pp 

│   ├── manage_credentials.pp (defined type)

│   └── params.pp 

├── app.pp (defined type)

├── config.pp 

├── init.pp 

├── install.pp 

├── params.pp 

└── service.pp

I've setup the web server in a typical Package/File/Service style and perhaps its also worth noting that in the manifest/config.pp file I notify Class['web_server::service'] for each file change.

In the app.pp defined type I have the following:

define web_server::app(
  $package_name,
  $repo_name,
  $package_version,
  $credentials
) {

   include web_server

    class{'web_server::app::install':

      package_name     => $package_name,
      repo_name        => $repo_name,
      package_version  => $package_version,
    } ->

    class { 'web_server::app::config': 
      credentials => $credentials, 
    } 

    contain ::web_server::app::install
    contain ::web_server::app::config

}

Inside the server::app::config file, I have a few Class['web_server::service'] notify statements to restart the service on app file changes. However this is causing dependency cycle errors.

Any idea where I'm going wrong with this? How do you generally manage this type of scenario? I looked at the apache forge module and it seems to be littered with Class['apache::service'] notify statements within classes/subclasses - what am I missing here?

Dependency Isssue Resolved:

I did manage to resolve the dependency issue by doing the following:

 define web_server::app(
      $package_name,
      $repo_name,
      $package_version,
      $credentials
    ) {

      # Force the webserver and its config to run before the app is installed
       require web_server::install
       require web_server::config

        class{'web_server::app::install':

          package_name     => $package_name,
          repo_name        => $repo_name,
          package_version  => $package_version,
        } ->

        class { 'web_server::app::config': 
          credentials => $credentials, 
          notify          => Class['web_server::service'],
        } 

        contain ::web_server::app::install
        contain ::web_server::app::config

}

EDIT:

Here is a link to the full module. Please note that it is prototype and not in a working state. I also didn't have the time to change the class names but the structure is exactly the same.

I have also included a file called mule_service.pp in the manifest directory. This is intended to be the profile.

edit retag flag offensive close merge delete

2 Answers

Sort by » oldest newest most voted
1

answered 2016-08-02 09:10:47 -0600

DarylW gravatar image

The secret to unlocking the cycle errors lies in understanding what the 'contain' keyword does, and how it interacts with the rest of your code. Here are some official docs.. ( https://docs.puppet.com/puppet/latest... )

I don't think you have enough code present to help you unravel your real problem.

One big red flag, however, is you have a 'define' that contains classes. The only real difference between a define (which acts like a resource) and a class is that a class can only be created once per manifest, but you can create as many of that define as long as the title/resources are unique. If you were to create two of your web_server::app defines, they would collide on all of the classes explicitly parameterized inside. I would suggest turning that portion into a class, as the main entry point.

If you provide both module, or more content from the files, we can help you shake out the behavior you are looking for.

Hope that Helps!

edit flag offensive delete link more

Comments

Thanks. You rightly pointed out the issue with classes within the `define` causing an issue. If i do make the entry point a class, wouldn't that still be an issue seeing as how I will only be able to declare the class once?

kaizenCoder gravatar imagekaizenCoder ( 2016-08-04 21:00:56 -0600 )edit

Sorry for the late reply. If you look at how the official apache module is implemented, they have a main 'class' and a vhost 'define' that is used. in some cases, your main class can be an empty class. https://jmangt.gitbooks.io/test-driven-puppet/content/profiles_as_defined_resources.html

DarylW gravatar imageDarylW ( 2016-09-14 08:36:28 -0600 )edit
0

answered 2016-08-01 06:04:40 -0600

Emerson Prado gravatar image

It would help if you provided the two classes also involved: server::app::config and web_server::service, so we can try to track dependency errors.
Also, could you pls post the error message?
Best regards.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2016-07-30 03:47:32 -0600

Seen: 130 times

Last updated: Aug 04 '16