Create a Java Daemon

Patrick Asselman iceblink at seti.nl
Fri Mar 1 09:21:09 UTC 2013


On 2013-02-26 19:56, Adam Tong wrote:
> On Wed, Feb 20, 2013 at 12:12 PM, Steve Flynn 
> <anothermindbomb at gmail.com> wrote:
>> On 20 February 2013 17:03, Adam Tong <adam.tongu at gmail.com> wrote:
>>
>>> I looked over the net but the information is confusing. Can you 
>>> tell
>>> me how should I do that and maybe a link that explains the steps to
>>> follow?
>>
>> http://www.netzmafia.de/skripten/unix/linux-daemon-howto.html
>>
>>
>> --
>> Steve
>>
> 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?
>
> Here is my service script content /etc/init.d/myservice:
> ---------------------
> #!/bin/sh
>
> start() {
> echo “Starting myservice”
> eval "java -classpath /home/me/Documents/projects/myproject/ 
> JavaDaemonTest"
> }
>
> stop() {
> echo “Stopping myservice”
> }
>
> restart() {
> stop
> start
> }
>
> status() {
> echo "myservice is ... status to implement"
> }
>
> case "$1" in
> start)
>   start
> ;;
> stop)
>   stop
> ;;
> restart)
>   restart
> ;;
> status)
>   status
> ;;
>
> *)
>
> echo $"Usage: $0 {start|stop|restart}"
> exit 1
> esac
>
> exit $RETVAL
>
> ------
>


Steve,

At the bottom of this page there is an elaborate shell script example 
you can use as wrapper for your java service.
The idea is that you create a file in /var/run/ with the pid at 
startup, and at stop time you read that file to see what the pid of the 
running service is.

There are also links to fancier specialised wrapper programs, maybe 
that is an option for you.

Best regards,
Patrick Asselman





More information about the ubuntu-users mailing list