Solved

Linux daemon

Posted on 2011-09-22
22
616 Views
Last Modified: 2012-05-12
Hi Experts,

I need to create a linux daemon that start stop a service ( basically launch a shell script)).
I need to be able to communicate with it remotely.

I don't really need where to start ?

Also don't know in which langage to implement it (C/C++ or java) I can program in both ?

Any help and advice ?

Thanks,
0
Comment
Question by:bachra04
[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
  • 10
  • 7
  • 4
  • +1
22 Comments
 
LVL 47

Expert Comment

by:for_yan
ID: 36581603
What do you mean by daemon?
Dio you need to strat a sellscript at some time?

Maybe cron job will be an option?
0
 
LVL 2

Author Comment

by:bachra04
ID: 36581922
To be honest I don't really care as long as it does the job i.e I can communicate with it remotely and tell it to start/stop the job
0
 
LVL 47

Expert Comment

by:for_yan
ID: 36582001
Do you need that it runs at specific times?
What you mean by accessing remotely - you can probably telnet and do whatever you need
0
Three Reasons Why Backup is Strategic

Backup is strategic to your business because your data is strategic to your business. Without backup, your business will fail. This white paper explains why it is vital for you to design and immediately execute a backup strategy to protect 100 percent of your data.

 
LVL 47

Expert Comment

by:for_yan
ID: 36582111


If you type

man crontab

it will give you information about how to set up crontab file
In this filwe you specifiy the timimng and periodicity when your job has to be executed and the
shelscript which needs to be executed

then you just say

crontab crontab.file

and cron daemon will see to it that your
jobs are running at specified times

I use it all the time - it is very useful option

Let me know if you have questions
0
 
LVL 2

Author Comment

by:bachra04
ID: 36582117
I want to access it from java client remote application and call start / stop
0
 
LVL 47

Expert Comment

by:for_yan
ID: 36582131
what you mean by remote application - can you elaborate?

adn do you want to start/stop it yourself by uyour command?
Then you probably don't need the daemon, as you'll be your own daemon :)
0
 
LVL 2

Author Comment

by:bachra04
ID: 36582156
Sorry may be the daemon is not the right word
but What I need is a process running on linux machine and I can communicate with it remotely
The process exposes : start /stop methods that I can call from another client application running on another machine
0
 
LVL 47

Expert Comment

by:for_yan
ID: 36582207
I would recommedn to use RMI (Remote Method Invocation) for that purpose.

http://download.oracle.com/javase/tutorial/rmi/index.html

So you can run the RMI server on your host and run RMI cilient on you local machine and clien will call method on the server
and this method wwould initiate your java program on the sevrver

RMI server is very light weight and easy in setup



0
 
LVL 86

Expert Comment

by:CEHJ
ID: 36582267
Why don't you just ssh into the box and start/stop it whenever you want?
0
 
LVL 47

Expert Comment

by:for_yan
ID: 36582283
That is waht I was suggestiing in the very beginning:

>What you mean by accessing remotely - you can probably telnet and do whatever you need
0
 
LVL 2

Author Comment

by:bachra04
ID: 36582340
For Two reasons:
-  don't like to give to the user full access rights.
- The client code is gine be executed from an eclipse plugin
0
 
LVL 47

Expert Comment

by:for_yan
ID: 36582346
Well, then RMI should serve your purpose
0
 
LVL 2

Author Comment

by:bachra04
ID: 36582499
yes RMI can be good I just want to run it automatically on linux ( the equivalent of windows service)
0
 
LVL 47

Expert Comment

by:for_yan
ID: 36582518
You can start your server together with the startup sequence - it will be waiting for requests - if that waht you mnean by running it automatically

As I guess you are going to run your client manually

0
 
LVL 2

Author Comment

by:bachra04
ID: 36582589
>> You can start your server together with the startup sequence
I need to do it from the installer that I give to a user to install it ,
Is there any reference or documentation on how to do that ?

Thanks
0
 
LVL 47

Expert Comment

by:for_yan
ID: 36582822
The RMI server start is just two commands:

rmiregistry &

and

java startServer &

you can do it from any place

Read the tutorial above - it is reaklly very simple
- you juts write interface which methons the methods
and the server class

adn then run "rmic" - program comes with java - which
makes stub and skeleton and you
keep skeleton with the server class and stub
with the clien class.

Then youn start rmiregistry (also tools comes with java distribuition)
and start registry and server on the server side.

Then on the client side you lookup your object on the registrty - and get a handle on it
and then invole remote method on thta object - very simple serevr
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 36586277
>>
For Two reasons:
-  don't like to give to the user full access rights.
- The client code is gine be executed from an eclipse plugin
>>

That's fair enough.

If i were doing this, i would integrate it with the normal daemon management of whatever Linux distro you're using. This would often be /etc/init.d See

man inittab

to determine that's the daemon management being used in your case

As far as the remoting is concerned, rmi is a possibility, although maybe overkill for this purpose. I might be inclined to use a simple TCP/IP approach
0
 
LVL 2

Author Comment

by:bachra04
ID: 36588020
Hi CEJH,

You mean I create a TCP/IP connection and send commands using some proprietary protocol ?

I prefer this idea over RMI (because of all the Overhead included when using RMI).

Is there any sample code or reference for creating a TCP IP connection under linux and sending back and forth
messages ?

Also security is a concern, should use TLS or ?? ( the client application should enter some kind of password to connect to the daemon)
0
 
LVL 9

Expert Comment

by:parparov
ID: 36588329
0
 
LVL 86

Accepted Solution

by:
CEHJ earned 350 total points
ID: 36588584
>>You mean I create a TCP/IP connection and send commands using some proprietary protocol ?

Yes. I would think the protocol could be very simple. Create an SSLServerSocket and you should be fine
0
 
LVL 47

Assisted Solution

by:for_yan
for_yan earned 150 total points
ID: 36588688

>because of all the Overhead included when using RMI

There is minimum overhead associated with RMI - and you don't need to deal with sockets
and all this stuff

Unfortunately, RMI is very much overlooked  -  it works nicely, much simpler to use that all this
web services hype, and is much more effective, and does not need any thirfd-party server to depend upon.

Once you use it - you'll love it and start using all the time you need remotte access.
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 36600533
:)
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Linux users are sometimes dumbfounded by the severe lack of documentation on a topic. Sometimes, the documentation is copious, but other times, you end up with some obscure "it varies depending on your distribution" over and over when searching for …
In this post we will learn different types of Android Layout and some basics of an Android App.
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

695 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