Ask Your Question
0

How to make sure a service is running on a specific port..!?

asked 2016-10-13 23:37:03 -0500

rohithmn03 gravatar image

For Example:

AppService1 should run on port 15000, if not restart the service and again check whether it started now with the port 15000. If this fails puppet should send a mail.

How can i achieve this..!? Please help.

edit retag flag offensive close merge delete

Comments

Distribute the proper configuration files telling AppService1 to listen on :15000.

Kai Burghardt gravatar imageKai Burghardt ( 2016-10-14 14:48:56 -0500 )edit

2 Answers

Sort by ยป oldest newest most voted
1

answered 2016-10-18 10:36:41 -0500

pascal gravatar image

The only time a service should be started with command line parameters instead of config files, is for testing. So to make sure, your service is running on port 15000, manage that line of the config file with a file, file_line or augeas resource and let it notify the service resource to restart/reload with the new configuration.

file_line { "something_port_15000" :
    line  => "Port 15000",
    match => "Port",
    path  => "/etc/something.conf",
    notify => Service["somethingd",
}

service { "somethingd" :
     ensure => running,
}

Note: I am still stuck on Puppet 3. Code written from head, syntax may be off a bit.

You could use an exec resource and chain netstat, grep and other stuff inside, but using that when not absolutely necessary will soon lead to very nasty behaviors and errors. By now I removed almost all execs from our modules, even where I needed to write my own resource types. It keeps my developers from introducing funny stuff and the logs are clear on what goes wrong.

edit flag offensive delete link more
0

answered 2016-10-15 16:02:35 -0500

Hi,

Here is a the official documentation to your inquiry: https://docs.puppet.com/puppet/4.7/re... In the paragraph you will find some hints. For your case, though you will need to have some custom status evaluation, if you are not able to identify the service as a process, which is preferable. Imagine the case, where something else listens on port 15000.

Anyway here is an example for your inquiry:

[---@ps4-rrze ~]> netstat -annup | grep ":123 " > /dev/nul

[---@ps4-rrze ~]> echo $?

0

[---@ps4-rrze ~]> netstat -annup | grep ":1500 " > /dev/nul

[---@ps4-rrze ~]> echo $?

1

So you can see that I have a running service on port 123 and should notice that grep correctly sets up the exit status,. So these checks can be directly used/applied in Puppet manifests.

Regards, Ivan Garnizov

edit flag offensive delete link more

Comments

Be careful with your match.. grep ":80" will also match ":8080", ":8090" etc...

DarylW gravatar imageDarylW ( 2016-10-17 08:57:40 -0500 )edit

I certainly do not understand this comment. where in my examples do I have such greps? Most likely you are also missing the blank space in my examples.

IvanGarnizov gravatar imageIvanGarnizov ( 2016-10-18 15:29:34 -0500 )edit

Your Answer

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

Add Answer

Question Tools

2 followers

Stats

Asked: 2016-10-13 23:37:03 -0500

Seen: 73 times

Last updated: Oct 18 '16