LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This 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!

Notices


Reply
  Search this Thread
Old 07-26-2012, 05:51 AM   #1
w1cx3d
LQ Newbie
 
Registered: Jul 2012
Posts: 2

Rep: Reputation: Disabled
Enabling simple init script to restart compiled dhcpd


Hi! This is my first time posting here!
I recently compiled the isc dhcp server and wrote a simple
init script to enable it to automatically start after booting.
The start and stop parts of the script are working pretty well,
much different to the way the restart part behaves.

Any help for figuring out why this isn't working as it should
would be greatly appreciated:

The script:
Code:
student@ubuntu12:~$ cat /etc/init.d/dhcpd
#!/bin/bash

case $1 in

start) /opt/dhcpd/sbin/dhcpd -cf /opt/dhcpd/etc/dhcpd.conf \
        -lf /opt/dhcpd/etc/dhcpd.leases ;;

stop) pkill dhcpd ;;

restart) echo "turned off"
        $0 stop
        echo "this line got executed"
        sleep 2
        $0 start
        echo "turned on" ;;

*) echo "sintax: $0 {start|stop|restart}"
echo "         service dhcpd {start|stop|restart}"

esac
stud@ubuntu12:~$
Command output:
Code:
student@ubuntu12:~$ pgrep -l dhcpd
student@ubuntu12:~$ sudo service dhcpd start
Internet Systems Consortium DHCP Server 4.2.4-P1
Copyright 2004-2012 Internet Systems Consortium.
All rights reserved.
For info, please visit https://www.isc.org/software/dhcp/
Wrote 0 deleted host decls to leases file.
Wrote 0 new dynamic host decls to leases file.
Wrote 5 leases to leases file.
Listening on LPF/eth0/00:d0:de:31:ac:9f/10.20.30.0/24
Sending on   LPF/eth0/00:d0:de:31:ac:9f/10.20.30.0/24
Sending on   Socket/fallback/fallback-net
student@ubuntu12:~$ pgrep -l dhcpd
2322 dhcpd
student@ubuntu12:~$ sudo service dhcpd restart
turned off
student@ubuntu12:~$ pgrep -l dhcpd
student@ubuntu12:~$
 
Old 07-26-2012, 09:16 PM   #2
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,329

Rep: Reputation: 2745Reputation: 2745Reputation: 2745Reputation: 2745Reputation: 2745Reputation: 2745Reputation: 2745Reputation: 2745Reputation: 2745Reputation: 2745Reputation: 2745
1. try amending top of script
Code:
#!/bin/bash
set -xv    # this line shows what parser is doing
2. why compile dhcpd instead of just getting it from your distro's repos?
Much easier...
 
Old 07-27-2012, 05:18 AM   #3
w1cx3d
LQ Newbie
 
Registered: Jul 2012
Posts: 2

Original Poster
Rep: Reputation: Disabled
Hi! Thanks for your reply. This week we're having a school project in which
we're supposed to compile dhcpd and make it start normally after booting.


Sorry for the long follow-up..

I appended your line to my script and it looked like it was getting
interrupted right after executing the "$0 stop" line of the restart case:

Code:
student@ubuntu12:~$ sudo service dhcpd restart

< .. output of the script in it's entirety .. >

+ case $1 in
+ echo 'turned off'
turned off
+ /etc/init.d/dhcpd stop

< .. output of the script in it's entirety .. >

+ case $1 in
+ pkill dhcpd
student@ubuntu12:~$

I'did a little bit of tweaking to the code by adding "ps -ef | grep dhcpd"
to the restart case:
Code:
restart) echo "turned off"
        ps -ef | grep dhcpd
        $0 stop
        echo "this line got executed"
        sleep 2
        $0 start
        echo "turned on" ;;
Here's the output I got after adding that line:
Code:
student@ubuntu12:~$ sudo service dhcpd restart

< .. output of the script in it's entirety .. >

+ case $1 in
+ echo 'turned off'
turned off
+ ps -ef
+ grep dhcpd
root      2172     1  0 11:27 ?        00:00:00 /opt/dhcpd/sbin/dhcpd -cf 
                      /opt/dhcpd/etc/dhcpd.conf -lf /opt/dhcpd/etc/dhcpd.leases
root      2174  2013  0 11:28 pts/2    00:00:00 sudo service dhcpd restart
root      2175  2174  0 11:28 pts/2    00:00:00 /bin/bash /etc/init.d/dhcpd restart
root      2179  2175  0 11:28 pts/2    00:00:00 grep dhcpd
+ /etc/init.d/dhcpd stop

< .. output of the script in it's entirety .. >

+ case $1 in
+ pkill dhcpd
student@ubuntu12:~$
So it turned out the script was sending itself the kill signal all along.
I changed the script's name to dhcpsrv, and sure enough it is now working
properly.


Again, many thanks for the input,
Mike
 
Old 07-29-2012, 07:10 PM   #4
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,329

Rep: Reputation: 2745Reputation: 2745Reputation: 2745Reputation: 2745Reputation: 2745Reputation: 2745Reputation: 2745Reputation: 2745Reputation: 2745Reputation: 2745Reputation: 2745
No worries.

Here's some useful links:
http://rute.2038bug.com/index.html.gz
http://tldp.org/LDP/Bash-Beginners-G...tml/index.html
http://www.tldp.org/LDP/abs/html/
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Add simple script to "service network restart" Paulius_J Linux - Newbie 4 06-05-2012 08:50 AM
Missing /etc/init.d/dhcpd from ISC DHCPD Quigi Linux - Networking 4 03-27-2008 09:50 PM
simple security question about init script java8964 Linux - Security 2 04-09-2003 08:43 PM
Compiled own kernel and got: Kernel panic: No init found. Try passing init= option to fbl Linux - General 12 01-14-2003 04:38 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 12:25 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration