Solved

making a application a service in linux

Posted on 2004-09-12
5
258 Views
Last Modified: 2013-12-06
I need to find the BEST way to run a app as a service in linux.

Im going to run a php script that will call that app and start or stop it. We currently do this in windows using the net stop service_name and we need a similar way in linux. Something like firedaemon but for linux.

The solution should meet the following requirements:

1.) be able to start,stop,restart the service from a php script via the internet.

2.) be a stable solution.

3.) run any type of app i choose to run this way.


Thanks for any help you can provide!
0
Comment
Question by:Brad_nelson1
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 40

Accepted Solution

by:
jlevie earned 500 total points
ID: 12038873
You'll want to look at the init scripts, usually in /etc/rc.d/init.d, that are used to manage Linux services.  Each of the scripts will have at a minimum a start & stop function, and may include functions to restart, reload, or return status as desired. You can see how these work in the section on "Init" in http://www.redhat.com/docs/manuals/linux/RHL-7.1-Manual/ref-guide/s1-boot-init-shutdown-booting.html

For Linux systems that use the SysV chkconfig the man page for chkconfig will also be helpful.
0
 

Author Comment

by:Brad_nelson1
ID: 12038970
Well I have learned about the utility called screen, this will create a virtual session that runs the app.  I have it working so now all i have to do is kill the pid that the username is running.

Does anyone know how i would go about matching the PID with the username so that i can kill that pid?


0
 
LVL 2

Expert Comment

by:Sunjith
ID: 12039124
ps aux | grep username | awk '{ print $2; }'

The above command will give you the pid's of all the processes run by the user: 'username'
To eliminate the last 4 lines from the above output:

ps aux | grep username | awk '{ print $2; }' | head -n-4

If you want to kill all the processes listed by the above command:

ps aux | grep username | awk '{ print $2; }' | head -n-4 | xargs kill -9

You can get the list of pid's of the processes you are running by replacing "username" in the above command with program name.
0
 

Author Comment

by:Brad_nelson1
ID: 12039175
im running Red Hat Linux, it appears some of those commands are invalid, because they the bottom line doest run correctly. Is that code be compatible for RH?
0
 
LVL 2

Expert Comment

by:Sunjith
ID: 12039619
Those commands should work fine in RH. I'm personally using RH. But if the last line [ps aux | grep username | awk '{ print $2; }' | head -n-4 | xargs kill -9] does not work for you, maybe xargs is not available in your system. Try this instead:
===========
for processid in `ps aux | grep username | awk '{ print $2; }' | head -n-3`; do  kill -9 $processid; done
============
NB: note the apostrophe's in the first line. The one just before 'ps' is usually the key just below ESC. The one inside is the other one. You may copy the code exactly to your shell.

If head don't work for you, omit it. That shouldn't be much problem:
===========
for processid in `ps aux | grep username | awk '{ print $2; }' `; do  kill -9 $processid; done
============

If awk is a problem, try:
===========
for processid in `ps aux | grep username | tr -s ' ' | cut -d ' ' -f 2`; do  kill -9 $processid; done
============
NB: There's a space between the internal apostrophe's. You may copy the code exactly to your shell.
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
php56-php-mcrypt for rhel7 php56 1 176
Can't "Unset" Proxy in Apache headers for PCI compliance... 4 94
phpmyadmin memory error 55 96
Bitcoin mining - Is it possible? 6 107
The purpose of this article is to demonstrate how we can upgrade Python from version 2.7.6 to Python 2.7.10 on the Linux Mint operating system. I am using an Oracle Virtual Box where I have installed Linux Mint operating system version 17.2. Once yo…
I. Introduction There's an interesting discussion going on now in an Experts Exchange Group — Attachments with no extension (http://www.experts-exchange.com/discussions/210281/Attachments-with-no-extension.html). This reminded me of questions tha…
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial
Suggested Courses

710 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question