Hi,
in fact, daemon is not so complex. I will give some examples - the "normal" program, I want to daemonize, is a ping on localhost:
To run it as daemon, I write:
Code:
daemon -- ping localhost
To check that my ping does really run, I look at the output of ps:
Code:
clemens@hammerhai : ~ : 03:25
>ps faux | grep ping
clemens 11508 0.0 0.0 3400 472 ? Ss 03:23 0:00 daemon -- ping localhost
clemens 11509 0.0 0.0 1916 668 ? S 03:23 0:00 \_ ping localhost
It runs - and will keep on running, if I log of. Only way to stop it - at least the only way, I know - is:
.
To get more control, I can name my daemon:
Code:
daemon --name="mydaemon" -- ping localhost
Using this name, I can stop and restart it as follows:
Code:
daemon --name="mydaemon" --stop -- ping localhost
daemon --name="mydaemon" --restart -- ping localhost
To get any output from my daemon, I can set an output file:
Code:
daemon --name="mydaemon" --output=/tmp/mydaemon.output -- ping localhost
To check what happens, I do look into my output file:
Code:
clemens@hammerhai : ~ : 03:32
>cat /tmp/mydaemon.output
PING localhost (127.0.0.1) 56(84) bytes of data.
64 bytes from localhost (127.0.0.1): icmp_seq=1 ttl=64 time=0.025 ms
64 bytes from localhost (127.0.0.1): icmp_seq=2 ttl=64 time=0.028 ms
64 bytes from localhost (127.0.0.1): icmp_seq=3 ttl=64 time=0.028 ms
64 bytes from localhost (127.0.0.1): icmp_seq=4 ttl=64 time=0.027 ms
64 bytes from localhost (127.0.0.1): icmp_seq=5 ttl=64 time=0.027 ms
64 bytes from localhost (127.0.0.1): icmp_seq=6 ttl=64 time=0.028 ms
64 bytes from localhost (127.0.0.1): icmp_seq=7 ttl=64 time=0.028 ms
64 bytes from localhost (127.0.0.1): icmp_seq=8 ttl=64 time=0.033 ms
And I don't forget to stop my daemon as shown above.
To run your java program, you can change the "ping localhost" to the comand, you use to start your application.
I hope, this one helps a little bit,
Greet-o-mente