LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Start a daemon/program at boot (https://www.linuxquestions.org/questions/linux-newbie-8/start-a-daemon-program-at-boot-27170/)

SchwipSchwap 08-04-2002 10:39 AM

Start a daemon/program at boot
 
Im really :newbie:

i wanna start the daemon lircd at boot
and then the program irexec

i tried it at:
/etc/inid.d/boot.local the program started, but
the daemon failed with permission denied

Where can i start the daemon :confused:

THX SchwipSchwap :p

MartBrooks 08-04-2002 11:11 AM

Start again. What /exactly/ did you add to this file? What was the error message? Where did you see this error message?

Regards

Mara 08-04-2002 11:39 AM

Can you start the deamon manually or you get the same error?

SchwipSchwap 08-04-2002 12:47 PM

i can start the daemon manually as root

i added at /etc/init.d/boot.local:

/dev/lircd
/usr/local/bin/irexec /home/user/irexec

at startup i get error /dev/lircd cant start daemon
permission denied

--> irexec failed too: cant find socket

manually i can start both and it works

SchwipSchwap 08-04-2002 02:41 PM

the lircd daemon has to be added at runlevel3

do i have to write the skripts myself to add the daemon?!

or is there an easier way

SchwipSchwap 08-04-2002 05:46 PM

Problem solved

cp /tmp/lirc-0.6.3pre3/contrib/lirc.suse6.2 /etc/init.d/lirc
cd /etc/init.d/rc3.d
ln -s ../lirc S80lirc
ln -s ../lirc K80lirc
cd /etc/init.d/rc5.d
ln -s ../lirc S80lirc
ln -s ../lirc K80lirc

http://www.suse.com/us/support/howto/fb/index.html#t5

bogoda 01-18-2006 08:35 AM

Quote:

Originally Posted by SchwipSchwap
Problem solved

cp /tmp/lirc-0.6.3pre3/contrib/lirc.suse6.2 /etc/init.d/lirc
cd /etc/init.d/rc3.d
ln -s ../lirc S80lirc
ln -s ../lirc K80lirc
cd /etc/init.d/rc5.d
ln -s ../lirc S80lirc
ln -s ../lirc K80lirc

http://www.suse.com/us/support/howto/fb/index.html#t5

Hello SchwipSchwap,

I sow your question posted in 2003.

I am now confuse with daemon program.

I have a daemon program written in c++.

But i donot know how to set that run at system boot up.

Some people say that we can script as Daemon.:scratch: :scratch:

If possiable how it can do.

Please if u can help me.

I konw very few things about daemon and scripts.:mad: :mad:

Thank you.

timmeke 01-18-2006 10:27 AM

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
-stop it
-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.

bogoda 01-19-2006 09:27 PM

Few things to know Daemon
 
First of all thank you very much for your discription about Daemon script.

I done the work as explained.

But I have some problems.

There are some commands that i cannot understand.

[ -e /proc/apm ] || /sbin/modprobe apm &>/dev/null

CONFIG=/etc/sysconfig/apdm


Are those lines nessary.

Also how can i create file in /var/run/... to store my pid.

I can manually run the daemon how can i make it run on the booting time.

I set chkconfig: 0123

But i could not see that is running.

Thank you

timmeke 01-20-2006 02:00 AM

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.
The lines
Quote:

Originally Posted by 03000176
[ -e /proc/apm ] || /sbin/modprobe apm &>/dev/null
CONFIG=/etc/sysconfig/apdm

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.

bogoda 01-20-2006 02:39 AM

Daemon my Program
 
hello timmeke,

Thank you verymuch for your reply.

I am sorry for my low knowledge about linux.

Because i am new for it.

We suppose to run a program (Daemon) at system bootup time to run another java program.

That java program is responsible for calculating free spaces of given program.

:Pengy: :Pengy: So I want run a Daemon program to do above task.

I want to konw how i can write a daemon program as a script.

Writing a java program will done by my friend.

:scratch: :scratch: So can you give any suggetion for daemon.


:) :) :) Thank you very much for your help again.

timmeke 01-20-2006 05:41 AM

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?

bogoda 01-20-2006 11:10 AM

My Daemon Program
 
Thank you for reply,

This is what all about.

We hope to develop strage area network(SAN) as a project.

On system boot time we want to run the daemon program and get the free spases of the local hard disk drives in our net work.

So free space calculating done by java program.

:scratch: I want to create a daemon program to execuate that java program at system boot up.:scratch:

Then after login user can see his free space.

;) I think you can get rough idea about what we are going to do.;)

If you can help me Thank full to u.

:newbie:

timmeke 01-23-2006 02:13 AM

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?

bogoda 01-23-2006 09:23 AM

HI timemeke,

Disk management program don by one of my friend.

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.

Thannk u.


All times are GMT -5. The time now is 11:33 AM.