Create a Java Daemon
Avi Greenbury
lists at avi.co
Wed Feb 27 15:46:14 UTC 2013
Adam Tong wrote:
> Hi,
>
> I added a script in /etc/init.d for my new service.
>
> Now I want to have a way to determine if the service is running or not
> for the status.
>
> I checked the script of apache2 for example, I found that it relies on
> this command to determine that: "pidof apache2 ..."
>
> This does not work for my new service that I can start using "java
> myprogram" in the start function of the service.
>
> I guess that I am missing some step. Can you give me a hint?
The common way of writing init scripts such as this is to use
start-stop-daemon (if you grep the files in /etc/init.d/ for that
you'll find some examples) which provides switches to do things like
reading and writing pidfiles for you.
In general, though, the principle is that on starting the script a
file is written containing the PID of the started process (usually in
/var/run somewhere), and on stopping or getting the status this file
is read in order to determine the pid of the process that we're
interested in.
--
Avi
More information about the ubuntu-users
mailing list