Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I want to create a service, which receives input from a shell script and returns outputs.

where should I start, and what to do ? Please give me step by step instruction or reference to one.

Thanks.

share|improve this question
add comment

2 Answers 2

I'm not sure what you mean by "a service". Do you mean something that can be invoked and run in the background? If so, your needs might be satisfied by a Bash script that polls a file for input, takes input when it is found in the file (presumably it would be piped in by the shell script that generates the input), and then outputs via whatever mechanism you choose. You could wrap the polling in an infinite loop with a sleep statement, and background the script to run continuously via nohup (manpage). That said, I'm not sure that's robust enough for your purposes, mostly because I'm not truly sure what you're asking. So let's take a few steps back:

There are many ways to write daemons/services in Unix, and your question should be a little more specific if you want step-by-step instructions. Some good places to start might be: what language do you want to write this in? What kinds of inputs will this service be taking? What will it be outputting, in what form, and to where/for whom/what recipient? At a higher level: do you really need a service for this, or is what you're after some sort of persistently-caching data processor, which could run as a standalone executable? The latter is often the better choice, especially when starting from scratch, as you can outsource a lot of rapid-sequential/simultaneous invocation problems to the back-end persistence provider (in my imagining, something like sqlite).

If you'd like to write it in Bash (which might not be the best option), I'd suggest starting here. Be sure you fully understand the basics of UNIX process forking and monitoring, otherwise writing daemons that perform arbitrary functions can be a significantly-sized "foot gun".

Bash, as I said before, isn't necessarily the best choice here. Perl contains a pretty robust built-in facility for doing this, in the form of Proc::Daemon. This SO question should get you pointed in the right direction if you choose Perl.

Python, also, has this ability. The canonical example of a Python daemon, complete with the double-fork magic, and a brief explanation, can be found here.

C/C++ is also a common language for daemon-writing, and there are plenty of guides. I like this one, but my experience in that area is more limited than the other languages above.

All of the above aside, this question probably belongs on Stackoverflow.

share|improve this answer
    
I didn't migrate the question, because as your answer shows, its not really well defined what the OP is really trying. So either he goes to SO with a (new) more specific or the solution is some scripted solution which would be fine for SU. If you still disagree, feel free to flag again –  Ivo Flipse Jun 11 '12 at 22:05
    
Agreed! Thanks for the prompt reply. –  Zac B Jun 11 '12 at 22:09
add comment

If you want to write a daemon and you are a C programmer, grab yourself a copy of The Linux Programming Interface: A Linux and UNIX System Programming Handbook; it has a whole chapter on it and is so valuable.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.