LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (https://www.linuxquestions.org/questions/linux-software-2/)
-   -   coding linux services (https://www.linuxquestions.org/questions/linux-software-2/coding-linux-services-278692/)

bytebrowser 01-16-2005 10:48 PM

coding linux services
 
Hi

I am new to the coding side of linux. I am building a system that will require me to write a service (like httpd or vsftpd). I would just like to know where to start, what language(s) I need to learn and how to install the service.

I suppose I should also explain what I am trying to do! I am planning to build a system the can recieve an email (like postfix) and then extract information from that email and update a website using the attachment. I also need to build one that will listen for a request from the web, receive a file list and then move those files in the list from one folder to another.

Thanks heaps for your help!!

--pete

Prabhat Sharda 01-16-2005 11:23 PM

hello dear,

Linux has a different way to run a program as service. No registry concept needed here. You have to make a script file, and put it in /etc/init.d/ directory, in which you have to run your program as a daemon.
As you may know, that daemon forks a new process and allows the parent to exit. Your parent here is the script file which you are running by service command, located at /etc/init.d/ directory.

Your script may use the functions of the 'function' file in /etc/init.d/ itself, in which you get daemon function, status function. Give the path of this file in your script.

If you see other files in /etc/init.d/ you will definitely get the basic idea behind that.
Kernel echos the message of the completion of your script, either [ OK ] or [FAILED]. You can easily judge from this, that whether your are on the right path or not. You can echo your own message too.

When the process successfully execute, it makes a pid file in /var/run/ directory, in which you have the process id of your process. When you see the status, kernel(may be your program too) checks for this file, extract the pid from the file, check for the process status and returns it. Similarly, if you call the service for stop, it checks for the pid in the respective .pid file, and kill that pid, and delete this file.

I think you can make your own shell scripts , follow all the processing by yourself. Always make a file (i think so)in /var/lock/sysconf/ directory whenever you start your service (if you are doing by your own script.) , and delete it whenever you are stopping your service.

Hope this will help you....
Good luck

bytebrowser 01-16-2005 11:30 PM

Thanks for your response. It seems that it will be fairly difficult and different to do, seen as thou I am normally a Java and PL/SQL programmer!!

Prabhat Sharda 01-16-2005 11:50 PM

no dear, its not too tough,
I think my way of explaining makes it so tough..

go to the /etc/init.d dir and see some files say smb, you will get the working behind that.

run ur program as daemon, you can save its pid by echo $! in respective .pid file in /var/run/ folder by yourself, and use touch command to make a file in /var/lock/sysconf dir.

for status you can use the status function in 'function' file.

for stop, you can use the function file here too. Remove the file in /var/lock/sysconf .

that's it..
yeah, you have to code some shell scripts for that or you can cheat this from other files defined in /etc/init.d/

bytebrowser 01-16-2005 11:56 PM

Thanks again for you help :)


All times are GMT -5. The time now is 05:07 AM.