Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
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.
Introduction to Linux - A Hands on Guide
This guide was created as an overview of the Linux Operating System, geared toward new users as an exploration tour and getting started guide, with exercises at the end of each chapter.
For more advanced trainees it can be a desktop reference, and a collection of the base knowledge needed to proceed with system and network administration. This book contains many real life examples derived from the author's experience as a Linux system and network administrator, trainer and consultant. They hope these examples will help you to get a better understanding of the Linux system and that you feel encouraged to try out things on your own.
Click Here to receive this Complete Guide absolutely free.
To start your program at boot, like for instance any ftp daemons or http daemons, then you'll need to
create a script in /etc/init.d
Have a look at the scripts that are already there. They are not very hard to understand.
They simply provide a way to:
-start the daemon
-restart it (==stop + start)
Basically, your program then becomes a "service" and you can start it by:
/sbin/service <name_of_script_in_/etc/init.d> start
likewise for stop/restart/status.
See also "man service".
In such scripts, it's also typical to define a "pid-file". This file stores the Process ID (unique number that identifies a running program) in a file, usually somewhere in /var/run/...
If you do so, you can question your service's status too. Checking the status will simply check if the PID file is there or not. If it is, then that indicates that the program is still running, so it'll get the status "running" or "ok". If not, then you get status "stopped".
Another issue is the so-called runlevel. When you boot, run in single user mode, run in normal multi-user mode, graphical multi user mode, shutdown the machine, etc, the machine is in fact in different runlevels (states). See "man init" for details on your system's runlevels.
Services, like the ones in /etc/init.d, are typically only started when your computer goes into one or more runlevels. For instance, you probably don't want to start your program whenever the computer goes to the shutdown runlevel (because it's then shutting everything down). Likewise for the boot runlevels (0 and 1 typically).
In fact, most daemons should only run in multi-user runlevels, typically levels 3, 4 and 5 and in some cases also in single user mode (runlevel 2 typically).
To make your script run in certain runlevels, you need to use "chkconfig".
See "man chkconfig" for details.
In short, your /etc/init.d/something script should have a line at the beginning telling chkconfig the default runlevels and giving it a certain number in the starting order (for instance the script that starts httpd will run after the network configuration because it has a higher number). You should thus probably give your program a pretty high number. For shutting down, the order of the scripts is reversed automatically (so high numbered scripts are shut down first).
After you've added your script to chkconfig's control, you can use commands like:
/sbin/chkconfig --level 345 <your_service>
to run it in levels 3, 4 and 5.
<your_service> is the name of your script in /etc/init.d.
Perhaps my explanation wasn't very clear. If you want to run the daemon, a few "rules of thumb":
-use chkconfig --levels 345. Starting up the daemon when your system (briefly) is in runlevel 0 or 1 probably won't do what you want.
-Second of all, for the chkconfig changes to be used, you need to actually change the runlevel to one of the levels for which the daemon is supposed to run. So, you'll need to reboot your machine or use the "telinit" program or something.
-Thirdly, you're not supposed to take the scripts in /etc/init.d literally. I said that you consider them as examples.
that you mentioned actually configure a kernel module for apm (battery power monitoring), if /proc/apm (a pseudo-file, representing a part of the kernel) doesn't exist (in other words, if the module isn't already loaded). Your daemon probably doesn't need to set up this module (the apmd daemon's script, /etc/init.d/apmd, already sets it up for you), so you shouldn't use those lines in your script.
-To create a file in /var/run, you must be the "root" user. The daemon script in /etc/init.d should in any case be run as root (most daemons need to be started as root, because they allocate ports with portnumbers < 1024, the so-called "privileged ports"). If your daemon doesn't do that, it's possible that you shouldn't be using a daemon at all. For process id files (PID files in short), you can simply create them via "touch" or by "echo" of your pid into the file.
You should also have a look at the /etc/init.d/functions script, which provides some useful functions, like killproc() (for killing a certain process, even if you don't know it's PID).
So, please describe what exactly your daemon program is supposed to do.
No problem. I'm relatively new to Linux myself.
But after a while, you'll get the hang of it, just like me.
Unfortunately, your explanations of the program are still somewhat unclear to me.
For instance, what do you mean with "free spaces"?
Why does the daemon need to run at startup (boot)?
Isn't it enough to start it just before you login? Or even when one particular user logs in?
What does the Java program do and why does it require the other program to run first?
I don't know much about SANs, but they're just a bunch of network hard disks, no?
To use them, you'll need to mount them, possibly by some disk volume management software.
So, your "daemon" will need to run after that software.
If you find the /etc/init.d/ script that launches this management software, find it's place in the order
of launch at boot (chkconfig number) and you should launch your program afterwards (higher number).
If you don't have such a disk management program, you should consider getting one. It would make system configuration and maintenance a lot easier, probably.
You shouldn't launch your daemon if the disk management soft isn't loaded. So only run your program in the same runlevels (most likely 3, 4 and 5 - maybe 2 as well).
I do have some questions for you:
-Can't you use a command line tool like "df" to get the disk free space, once the disks have been mounted?
Using Java to calculate disk space seems a bit much (Linux, just like most OSs, keep track of disk space for
you, so you don't need to write a program that does the math).
-How do you want to report the available disk space to the users?
When they login? In plain text? Via a web interface? Send them a mail whenever free disk space is lower than
a certain number of bytes/megabytes/gigabytes?
-Doesn't the disk management software provide some kind of interface (for instance a graphical user interface
or web interface) that allows you to monitor the disk's space? And can't you allow the users to use that
interface? Or does this give the users also the possibility to mess up the disk configuration?
Therefore i also don't know how he going to show it.
my task is to create a daemon to run that program.
I tried it many ways included in forums.
but could not catch it.
Evean it is better to write a script to run on the background from booting process.
So can u explain a simple daemon program script and how can i make it to run.
It is better evean to execute a C program.
I am now in deep trouble.