Adding Services to Chksrvd for Monitoring
- Written by Vanessa Vasile
- Published in Hacks, Howto
- 4 Comments
Chkservd is a driver of Tailwatchd, which is the service in cPanel that checks to make sure that services are running and restarts them if necessary. It’s also responsible for the ‘Service Manager’ section in cPanel, which is an interface where added services can be easily checked on and off.
Service files are in /etc/chkserv.d/
To add a new service, create a line in ”’/etc/chkserv.d/chkservd.conf’” in the same format as the others:
1 means the service should be enabled, 0 means it’s off.
In ”’/etc/chkserv.d”’ each service has its own file. Create a file called as the name of the service you are monitoring. The contents of the file are in the format of:
#SERVICE = PORT, SEND, RESPONSE, RE-START COMMAND
There are two ways that cPanel checks services with chkservd:
– Connection-based monitoring: By default, cPanel will try to connect to the service’s specified port, issue a command, and if a response is received within 10 seconds it will consider the service to be online. For instance, FTP:
– Process-based monitoring: cPanel will check for a specific process to determine whether it is online. For instance, named:
If you have more than one restart command, you can separate them with semicolons in order of preference that they should be run. Output of these commands will be logged to the chkservd.log
After you’ve created the service’s configuration file, restart chkservd:
You should then see the service listed in WebHost Manager in the ‘service manager section’
Chkservd logs are in /var/log/chkservd.log. Checks are done every 8 minutes (though this is configurable in WHM -> Tweak Settings), and every online service gets a +, offline services get a -. If the service is determined to be offline, the restart command(s) specified in that service’s chkservd configuration file is issued and the output is logged.
I just wanted to add a few bits of information to remove some ambiguities:
in the process-based monitoring it’s important to understand those comma delimited parameters:
where the first three don’t apply, which is why they are “x”
#4 is the command to start the service. My personal beef with it, by the way, is that I suspect it runs under user name “cpanel” which is usually not in your normal list of sudoers – important if the command needs to be run as a different user – I’m still doing a research on this.
#5 is basically NOT not command name and rather a search term for grep (I don’t know if searchd actually uses grep but the result is the same)
so, if you are monitoring “named” but you have this command running ” pico /etc/init.d/named”, it will think “named” itself is running – have to be very careful with it, especially if the command name is rather common
#6 is also rather tricky – it is the user that runs the command given in in #5. If the command is present but it’s run by, say, “root” instead of “named”, it will NOT match, even if “named” (the command) is actually running. And the notation you have in your example means that it will match if the “named” (a command name match) is run by either “named” (the user) or “bind”
Hope that can help someone from running in circles – there is very little info on that on the Net.
If someone knows exactly how chkservd runs the commands (as “root”, as “cpanel”, how to control paths etc.), please add some info here for the full(est) coverage of this little sucker I’ve seen anywhere, including cPanel’s own documentation.
Cheers everyone, keep up great work!
I am adding the configuration for memcached, if anyone needs it:
[2012-12-15 19:29:16 +0100] Service check ….syslogd [[check command:+][socket connect:N/A]]…sshd [[check command:+][socket connect:N/A]]…spamd [[check command:+][socket connect:N/A]]…queueprocd [[check command:+][socket connect:N/A]]…pop [[check command:N/A][socket connect:+]]…named [[check command:+][socket connect:N/A]]…mysql [[check command:+][socket connect:N/A]]…memcached [[check command:N/A][socket connect:+]]…lfd [[check command:+][socket connect:N/A]]…imap [[socket_service_auth:1][check command:+][socket connect:+]]…httpd [[check command:N/A][socket connect:+]]…exim [[check command:+][socket connect:+]]…cpsrvd [[http_service_auth:1][check command:N/A][socket connect:+]]…cpanellogd [[check command:+][socket connect:N/A]]…Done
Service Check Finished
I just got a simple version working with memcached:
service[memcached]=11211,verbosity 1,OK,/etc/init.d/memcached start
Pingback: FarhanFaisal | Add new service to be monitored under chkservd (cPanel)