Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
How to debug a user-defined service using init scripts
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Portage & Programming
View previous topic :: View next topic  
Author Message
yagamiram
n00b
n00b


Joined: 17 Feb 2015
Posts: 13

PostPosted: Wed Mar 04, 2015 8:34 pm    Post subject: How to debug a user-defined service using init scripts Reply with quote

There is a user-defined service script which is started whenever the gentoo machine boots and if I shutdown or reboot the gentoo mahine, the service will be stopped.

But it takes longer time to stop the service compared all other services stop time.

I have looked into the code didn't know which part of the code takes longer time to terminate the proccess.

Now I heard that there is way to debug the service using init scripts. By this debug, current line of execution of the service script will be shown in the terminal I think.

But I do not have any clue to debug the service.

If I statement is wrong on debugging the service, pls provide what is the best way to debug the service line by line ? And what is procedure to stop a service ?

I'm completely newbie to this, and I request to explain in detail about this.

Thanks and Regards,
Yagamiram.
Back to top
View user's profile Send private message
steveL
Watchman
Watchman


Joined: 13 Sep 2006
Posts: 5153
Location: The Peanut Gallery

PostPosted: Thu Mar 05, 2015 7:53 am    Post subject: Reply with quote

Initscripts are simply shell, so you can insert set -x and: set +x around the part you want to debug, and every shell line will be echoed to stderr, in expanded form, before being executed.

You may need to redirect stderr to a file:
Code:
exec 2>/etc/log/some.log
depending on what it is, and when it executes. (You'd need to run: mkdir /etc/log as root, once, first; I needed that path for lvm which runs before /var is up on my machine, since it supplies the partition, although in that case I was simply running lsof and redirecting the output to log, at shutdown, again with no /var.)

The biggest difficulty I found with initscripts was tracking the dependencies, ie what needs what in the tree, and what some script does in whichever function, starting with depend as that tells us the deps. So I wrote some shell functions to tell me that; I recommend you try them if you're getting lost in the tree.

If you want to learn shell, I recommend #bash on IRC: chat.freenode.net; they will teach you sh if you tell them upfront that's what you're doing, and not bash. (Just be sure to tell them upfront, as bash is a different language when extensions are used.)

Oh, and read man runscript
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Portage & Programming All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum