Linux - SoftwareThis forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Distribution: Redhat 9.0 was but now like Fedora Core 2
Posts: 57
Rep:
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.
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.
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/
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.