Linode Forum
Linode Community Forums
 FAQFAQ    SearchSearch    MembersMembers      Register Register 
 LoginLogin [ Anonymous ] 
Post new topic  Reply to topic
Author Message
PostPosted: Mon Jun 20, 2011 12:34 pm 
Offline
Senior Newbie

Joined: Sun Jan 23, 2011 2:33 pm
Posts: 5
I'd like to know of a way to output to a webpage whether specific processes are running or not. I host a few eggdrops, bncs and would like to be able to show if they're up or down.

I use Debian Squeeze and Nginx.

Help would be greatly appreciated. :)


Top
   
 Post subject:
PostPosted: Mon Jun 20, 2011 12:41 pm 
Offline
Senior Member

Joined: Fri May 02, 2008 8:44 pm
Posts: 1121
Code:
ps -C <process_name>

This will show a list of currently running processes. For example, if you want to know if the SSH server is running, you do "ps -C sshd".

Write a PHP script (or a script in any other language that you prefer) to execute this command and count the number of entries.


Top
   
 Post subject:
PostPosted: Mon Jun 20, 2011 12:58 pm 
Offline
Senior Newbie

Joined: Sun Jan 23, 2011 2:33 pm
Posts: 5
I appreciate the reply. TBH I wouldn't know where to start in writing a PHP script for this.

What I was thinking was being able to show if a process is running or not on a webpage by the words "Online" and "Offline".

I'd like some more replies if possible. Any help would be awesome.


Top
   
 Post subject:
PostPosted: Mon Jun 20, 2011 1:12 pm 
Offline
Senior Member

Joined: Sun Mar 07, 2010 7:47 pm
Posts: 1970
Website: http://www.rwky.net
Location: Earth
What programming languages do you know?

_________________
Paid support
How to ask for help
1. Give details of your problem
2. Post any errors
3. Post relevant logs.
4. Don't hide details i.e. your domain, it just makes things harder
5. Be polite or you'll be eaten by a grue


Top
   
 Post subject:
PostPosted: Mon Jun 20, 2011 1:42 pm 
Offline
Senior Member

Joined: Fri May 02, 2008 8:44 pm
Posts: 1121
Here's a PHP script that I just whipped up.

PHP is probably the easiest language to set up with nginx, because nginx doesn't support plain old CGI, Python/Ruby frameworks are overkill for your purpose, and there are tons of tutorials for setting up Debian+nginx with PHP/FastCGI. (Don't bother with compiling FPM, just use php5-cgi and spawn-fcgi packages from the repository.)

Code:
<?php

if (isset($_GET['process'])) {
    $cmd = escapeshellarg($_GET['process']);
    $count = shell_exec("ps -C $cmd | wc -l") - 1;
    echo "$count processes";
} else {
    echo "Error";
}

Save it as "ps.php" someplace where nginx can serve it. Set up nginx to use PHP if you already haven't done so.

Now, visit http://your-domain-or-ip-address/ps.php?process=process_name. If everything is set up properly, the page will display the number of running processes. (Replace process_name with the name of the server process that you'd like to monitor. If you're unsure, use the "top" command to see the names of running processes.)

Caution: You probably don't want this script to be accessible to everyone in the world. Although I think I've built in adequate protections from injection attacks, it would be a good idea to hide it where other people won't know.


Top
   
Display posts from previous:  Sort by  
Post new topic  Reply to topic


Who is online

Users browsing this forum: No registered users and 0 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  
RSS

Powered by phpBB® Forum Software © phpBB Group