LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (http://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   inittab (http://www.linuxquestions.org/questions/linux-newbie-8/inittab-757173/)

allensim81 09-23-2009 02:13 AM

inittab
 
hi,
Following is my coding in inittab
Code:

########
wa1:345:respawn:/usr/local/bin/htsserver /usr/local/share/httrack/ path /data/websites lang 1 --port 8000 >> /var/log/htsserver8000.log

########
wa2:345:respawn:/usr/local/bin/htsserver /usr/local/share/httrack/ path /data/websites lang 1 --port 8001 >> /var/log/htsserver8001.log

########
wa2:345:respawn:/usr/local/bin/htsserver /usr/local/share/httrack/ path /data/websites lang 1 --port 8002 >> /var/log/htsserver8002.log

How can i restart initab?
can i have 3 post as above... once port 8000 is died, either port 8001 or port 8002 will be invoked. How to do do this?
Do i need to write a simple script.. please help and guide me.
Appreciate your help :-)

acid_kewpie 09-23-2009 03:36 AM

why are you doing this in inittab?? This seems to be a massive misuse of the functionality it provides. I think you need a proper service script instead.

mjsurette 09-23-2009 04:05 AM

Quote:

Originally Posted by allensim81 (Post 3693770)
hi,
Following is my coding in inittab
Code:

########
wa1:345:respawn:/usr/local/bin/htsserver /usr/local/share/httrack/ path /data/websites lang 1 --port 8000 >> /var/log/htsserver8000.log

########
wa2:345:respawn:/usr/local/bin/htsserver /usr/local/share/httrack/ path /data/websites lang 1 --port 8001 >> /var/log/htsserver8001.log

########
wa2:345:respawn:/usr/local/bin/htsserver /usr/local/share/httrack/ path /data/websites lang 1 --port 8002 >> /var/log/htsserver8002.log

How can i restart initab?
can i have 3 post as above... once port 8000 is died, either port 8001 or port 8002 will be invoked. How to do do this?
Do i need to write a simple script.. please help and guide me.
Appreciate your help :-)

The command to reread inittab is 'kill -HUP 1'. It must be done as root. That part's easy, but it's not the solution to your problem.

respawn is just what it sounds like. It starts a process and waits for it to return. When it does, it immediately restarts it.

A quick look at the code for htsserver shows that it forks into the background and returns immediately. This is normal for servers, but will not mesh well with respawn. If you want to hack the code and remove the call to daemonize() in main, that will stop it from returning immediately, but even then you shouldn't put it in inittab. Init processes run as root, which is one reason why you won't find servers in inittab. Too big of a security risk. Anyone hacking your server totally owns your system. This is one reason why you will not find servers started in inittab.

A more secure way would be to hack it so that it doesn't return immediately and write a script calling it in an endless loop. Run this script as a normal user which has been set up specifically for this purpose.

I assume that the reason you have to do this is the server keeps crashing. If so then all this will become unnecessary once the code stabilizes.

Good luck

Mike

allensim81 09-23-2009 04:28 AM

Hi, the reason I doing is this is beacuse:
Iam using Webhttrack and everytime I finish to configure a project in web mode with htsserver, the server stops (with the message "Unable to create the server: No such file or directory).

Is it possible to restart the htsserver server automatically or to reuse the current port 8000 ?

It is imposible to restart the htsserver in the same port during few minutes because it's seems that is not really stopped.

Please guide me on this. I really dont have any ideas to solve this.
Thanks

mjsurette 09-23-2009 05:44 AM

Quote:

Originally Posted by allensim81 (Post 3693876)
Hi, the reason I doing is this is beacuse:
Iam using Webhttrack and everytime I finish to configure a project in web mode with htsserver, the server stops (with the message "Unable to create the server: No such file or directory).

Is it possible to restart the htsserver server automatically or to reuse the current port 8000 ?

It is imposible to restart the htsserver in the same port during few minutes because it's seems that is not really stopped.

Please guide me on this. I really dont have any ideas to solve this.
Thanks

Sorry about that. I was talking about a totally different package.

I loaded the right package, tried it, and got exactly what you got.

A couple of things I noticed:

You can specify the port it listens on at startup.

htsserver --port 8081 /path/to/html/root/dir

The error message only shows up after you click on the Finsh button. At that point all files have been downloaded, so it's a non-issue as far as downloading is concerned. You'll want to notify the authors so they can fix this though.

Hope that helps,

Mike

allensim81 09-24-2009 12:43 AM

Hi Mike,
Thanks for your fast reply! Appreciate it!
Now that i open 2 ports in /etc/initab, port 8000 and port 8001 as following:

########
wa1:345:respawn:/usr/local/bin/htsserver /usr/local/share/httrack/ path /data/websites lang 1 --port 8000 >> /var/log/htsserver8000.log

########
wa2:345:respawn:/usr/local/bin/htsserver /usr/local/share/httrack/ path /data/websites lang 1 --port 8001 >> /var/log/htsserver8001.log

Can it be like when port 8000 is being used and after the user finished download the website and click on the exit button, port 8000 will stop/die, but then immediately port 8001 will be called to replace port 8000, vice versa.

Can this be done? do i need to write a simple script for this? or this can be done by just few lines of command in inittab?
Please guide me on this...

Thanks a lot.

mjsurette 09-24-2009 01:36 AM

Quote:

Originally Posted by allensim81 (Post 3695074)
Hi Mike,
Thanks for your fast reply! Appreciate it!
Now that i open 2 ports in /etc/initab, port 8000 and port 8001 as following:

########
wa1:345:respawn:/usr/local/bin/htsserver /usr/local/share/httrack/ path /data/websites lang 1 --port 8000 >> /var/log/htsserver8000.log

########
wa2:345:respawn:/usr/local/bin/htsserver /usr/local/share/httrack/ path /data/websites lang 1 --port 8001 >> /var/log/htsserver8001.log

Can it be like when port 8000 is being used and after the user finished download the website and click on the exit button, port 8000 will stop/die, but then immediately port 8001 will be called to replace port 8000, vice versa.

Can this be done? do i need to write a simple script for this? or this can be done by just few lines of command in inittab?
Please guide me on this...

Thanks a lot.

No, the way inittab works is each process is independent, so they will both be running. You could still go from one to the other whenever one dies. Is there some particular reason that you don't want them both running at once? If so, you can write a shell script which calls one, then the other in an endless loop. Remember though, the second one won't start up until the first one exits, so you'll have gained nothing timewise.

This is not the proper way to start servers though. It's the wrong way to do this from both an administrative and security point of view. Don't forget this is a wide open server running as root. That sets off so many alarms for me that it makes my head hurt. I hope for your sake that you're at least hidden behind a NAT router.

Mike

allensim81 09-24-2009 02:28 AM

Hi Mike,
U r awsome! u are really fast!
I want both porth running at once.
What i mean in my previous post is that,whenever user finish download the website by using Webhttrack and click exit button, the htsserver seems like dies, and everythg stop. I dont want this to happen, so, i am thinking of how to automatically avoke port 8001 when 8000 is dead. So that user can continue to use Webhttrack to download the website again.. without to wait for longer time.

Can this be done?
can u guide me,
thanks

my logic is :
if port 8000 die, then port 8001 quickly been called & cont to fucntion
if port 8001 die, then port 8000 quickly been called & cont to fucntion

Wim Sturkenboom 09-24-2009 03:01 AM

The port 'dies' because it's not closed properly in the software. So although the application does no longer run, the lower layers (network stack?) are still listening on the used port.

This should basically be fixed at the application level, not by creating a workaround.

zhjim 09-24-2009 03:02 AM

Heres a sample shell script that should suit your needs

Code:

while [ 1 ]; do
 /usr/local/bin/htsserver /usr/local/share/httrack/ path /data/websites lang 1 --port 8000 >> /var/log/htsserver8000.log
 /usr/local/bin/htsserver /usr/local/share/httrack/ path /data/websites lang 1 --port 8001 >> /var/log/htsserver8001.log
done

put this into a shell script and call it from /etc/init.d/rc.local or just put the shell script into /etc/init.d and link to it from the apropriate runlevel init directory.

allensim81 09-24-2009 04:45 AM

dear zhjim,

cool zhjim!
i tired to put the shell script at the /etc/init.d
Once i run it at the terminal to start it, it shows:
Unable to initialaize a temporary server (no remaining port)

can u please guide me on this. thanks in advance

allensim81 09-24-2009 04:57 AM

hi zhjim,1 more querries,
to put he above shell script izzit samething as i add on the following at inittab?
########
wa1:345:respawn:/usr/local/bin/htsserver /usr/local/share/httrack/ path /data/websites lang 1 --port 8000 >> /var/log/htsserver8000.log

########
wa2:345:respawn:/usr/local/bin/htsserver /usr/local/share/httrack/ path /data/websites lang 1 --port 8001 >> /var/log/htsserver8001.log

Can it be automate? if port 8000 die,it will go straight to port 80001,without user key in the port.

Thanks & Appreciate your help.

zhjim 09-24-2009 05:25 AM

Quote:

Originally Posted by allensim81 (Post 3695259)
hi zhjim,1 more querries,
to put he above shell script izzit samething as i add on the following at inittab?

Jup it just resambles what you did inside the inittab. It works like this. Loop for ever (while [ 1 ]) then start the first server on port 8000. When the programm ends the next line is called and the second server is started on port 8001. Then start all over (loop for ever).
Keep in mind that this only works if the start up of the server remains in forgeground. Else the script tries to start a programm that uses a already in use port.

Quote:

Originally Posted by allensim81 (Post 3695259)
Can it be automate? if port 8000 die,it will go straight to port 80001,without user key in the port.

Thanks & Appreciate your help.

The automation is the loop for ever ;)

The error message you get from script points to a port allready in use problem. Please see what happens when you just run this line from the terminal
Code:

/usr/local/bin/htsserver /usr/local/share/httrack/ path /data/websites lang 1 --port 9000 >> /var/log/htsserver9000.log
use 9000 as a port just to make sure the port is not in use.
If it puts you back on the command line imediatly the program acts like a daemon. Meaning it puts itself into background. If this is the case see if there is a option to have the program run in foreground.

May when you read up on this things will get a bit clearer for you
http://www.yolinux.com/TUTORIALS/Lin...itProcess.html

Cheers Zhjim

allensim81 09-24-2009 11:12 PM

Thanks for the fast reply.

now that two ports are working, if one die, another one will still working. But then the user need to key in the port by themself.Let say if http://10.17.32.46:8000/server/index.html die, user need to type the url to http://10.17.32.46:8001/server/index.html.

My question..can it be like when http://10.17.32.46:8000/server/index.html die, it will automatically route to http://10.17.32.46:8001/server/index.html without user key in anything?

How can this be done... issit i need to do it on my html ?

Please advice, appreciate your help! Thanks in advance :-)

allensim81 09-25-2009 03:49 AM

Hi,
I am stil wondering how to solve this:
Now that Once user finished download using ths url: http://10.17.32.46:8000/server/index.html the htsserver will die, so in order to let user continue to use the application, http://10.17.32.46:8001/server/index.html must be avoke.

How can these be done? should i wirte a script to do this or should i write some coding in my html?

pls advice.Appreciate ur guidiance and help. :-)


All times are GMT -5. The time now is 04:53 PM.