Solved

Linux daemon

Posted on 2011-09-22
22
572 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
  • 10
  • 7
  • 4
  • +1
22 Comments
 
LVL 47

Expert Comment

by:for_yan
Comment Utility
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
Comment Utility
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
Comment Utility
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
 
LVL 47

Expert Comment

by:for_yan
Comment Utility


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
Comment Utility
I want to access it from java client remote application and call start / stop
0
 
LVL 47

Expert Comment

by:for_yan
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
Why don't you just ssh into the box and start/stop it whenever you want?
0
 
LVL 47

Expert Comment

by:for_yan
Comment Utility
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
Comment Utility
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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 47

Expert Comment

by:for_yan
Comment Utility
Well, then RMI should serve your purpose
0
 
LVL 2

Author Comment

by:bachra04
Comment Utility
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
Comment Utility
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
Comment Utility
>> 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
Comment Utility
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
Comment Utility
>>
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
Comment Utility
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
Comment Utility
0
 
LVL 86

Accepted Solution

by:
CEHJ earned 350 total points
Comment Utility
>>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
Comment Utility

>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
Comment Utility
:)
0

Featured Post

Get up to 2TB FREE CLOUD per backup license!

An exclusive Black Friday offer just for Expert Exchange audience! Buy any of our top-rated backup solutions & get up to 2TB free cloud per system! Perform local & cloud backup in the same step, and restore instantly—anytime, anywhere. Grab this deal now before it disappears!

Join & Write a Comment

Little introduction about CP: CP is a command on linux that use to copy files and folder from one location to another location. Example usage of CP as follow: cp /myfoder /pathto/destination/folder/ cp abc.tar.gz /pathto/destination/folder/ab…
Setting up Secure Ubuntu server on VMware 1.      Insert the Ubuntu Server distribution CD or attach the ISO of the CD which is in the “Datastore”. Note that it is important to install the x64 edition on servers, not the X86 editions. 2.      Power on th…
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

728 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now