Ask Your Question

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

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

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


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

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

2 Answers

Sort by ยป oldest newest most voted

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

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

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


Here is a the official documentation to your inquiry: 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 $?


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

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


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


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

DarylW gravatar imageDarylW ( 2016-10-17 08:57:40 -0600 )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 -0600 )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



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

Seen: 301 times

Last updated: Oct 18 '16