2
5
I know there is a program called upstart that can make it easy to make small daemons. I can't get this program to configure on CentOS. I get all sort of errors concerning pkg-congfig, libnih, and dbus.
I am working on a node.ja application and this is a pain to start and stop all the time, so I want to create a deamon for this which makes it easy to start and stop.
Update 1
I will give a small example of what i need for this project, I hope someone can help with this.
To start the node.js application I have to type in SSH:
# node /path-to-file/filename.js
Now when I execute this the terminal freezez, i have to press CTRL + Z (pc) to get input back.
Now when i changed something in the file I have to reload it again
I need to:
# killall -9 node
This kills all the node applications that are running
Next i have to start the script again
# node /path-to-file/filename.js
I want to just type
# myapp restart
And everything is done. This type of setup would save me lots of time
Update 2
I found a program called monit. This works nice, and automatically starts the application in case of a crash, which is good. It also has a nice web interface which is also handy.
I can type
# monit myapp start(start/stop/restart)
This works fine. There is only one downside, and this is a major downside. When i start the myapp application, it does not display the compile errors node.js throws. So when it fails to start I will not know what the reason is. I have to type the whole '# node /path-to-file/filename.js' again to check the error.
Ok i am new to linux, so I don't know what all those tings are. Can you maybe give me a little example on how to achieve this. I will edit the question a little and maybe you can help me with this particular type of setup, because i have no idea what stdin, etc are. – Saif Bechan – 2010-03-30T10:32:01.747
Ok so basically I just create a file(myapp), and just add #!/bin/sh to the top of the line. And when I type the filename it will run as a program? – Saif Bechan – 2010-03-30T11:27:51.660
Thank you this will get me started on the program. Thank you for the help. Accepted answer – Saif Bechan – 2010-03-30T12:27:56.320
Good answer, though I would add that the parent process should ignore SIGCHLD in order for init to immediately inherit the orphan process and not leave a zombie in the process table. This is easily done in scripts using the NOHUP command, but like you said, tie up all 3 standard IO as well. – kmarsh – 2010-03-30T12:46:04.753
This works great. I now have full control over the start and stop of the execution. This will save me a huge amount of time. – Saif Bechan – 2010-03-30T12:58:46.403
You're welcome :) you can use this script as /etc/init.d/yourapp and use your application as a full-fledged service from now. Error messages will go to the log file ( /var/log/whatever). – wazoox – 2010-03-30T13:13:50.730
1Simply closing stdin and backgrounding works as well:
myprog 1<&- &
. Now you have a daemon. – w00t – 2012-03-23T13:36:08.597@woot, chdir to /root is essential to not prevent unmounting something inadvertently. – wazoox – 2012-03-24T22:01:46.513