DaemonForums  

Go Back   DaemonForums > Miscellaneous > Guides

Guides All Guides and HOWTO's.

Reply
 
Thread Tools Display Modes
  #1   (View Single Post)  
Old 13th November 2009
J65nko J65nko is offline
Administrator
 
Join Date: May 2008
Location: Budel - the Netherlands
Posts: 3,154
Thanked 182 Times in 149 Posts
Default DJB daemontools: compile and install scripts (OpenBSD)

Introduction

The standard installation of the Daniel J. Bernstein's daemontools software creates some directories in "/".
For many years I just ignored the complaints from others that this is not according the OpenBSD standard file layout as described in hier(7).

However for an installation on a Compact Flash card I needed to be able to specify where the files end up.
The following two scripts try to achieve this:
  • new_daemontools_compile
  • new_daemontools_install

new_daemontools_compile

Code:
#!/bin/sh +e
# $Id: new_daemontools_compile,v 1.4 2009/11/13 02:37:48 root Exp $

DAEMONTOOLS="daemontools-0.76"
DAEMONTOOLS_ARCHIVE="${DAEMONTOOLS}.tar.gz"

NEEDED="${DAEMONTOOLS_ARCHIVE} \
       new_daemontools_install \
       dt-makefile.patch"

for file in ${NEEDED} ; do
   if [ ! -f $file ] ; then
      echo $0 : Sorry cannot find file $file
      exit 1
   fi
   echo "$0: OK found file $file"
done

echo
echo -Unpacking ${DAEMONTOOLS_ARCHIVE}
echo

tar -xpvzf ${DAEMONTOOLS_ARCHIVE}

CURDIR=$(pwd)

cd admin/${DAEMONTOOLS}/src/

echo
echo $0: -------- Patching Makefile
echo

patch -p0 -l Makefile ${CURDIR}/dt-makefile.patch

echo
echo $0: ------- compiling daemontools --------
echo
make ||  exit 100 

echo
echo $0: ----- Compile finished --------
echo You now can run the 'new_daemontools_install' script
echo
After checking if all necessary files are in the current directory, it first unpacks the daemontools tarball. This results in a lot of files under the directory ./admin.

Before running Bernsteins makefile, it is patched with the dt-makefile-patch file, shamelessly stolen from the FreeBSD daemontools port.
Code:
--- Makefile    Thu Jul 12 18:49:49 2001
+++ /tmp/Makefile       Sat Nov  5 02:56:33 2005
@@ -82,10 +82,9 @@
 chkshsgr.o: chkshsgr.c compile
       ./compile chkshsgr.c

-choose: choose.sh home warn-auto.sh
+choose: choose.sh  warn-auto.sh
       rm -f choose
       cat warn-auto.sh choose.sh \
-       | sed s}HOME}"`head -1 home`"}g \
       > choose
       chmod 555 choose

@@ -387,10 +386,9 @@
 pathexec.h str.h strerr.h svscan.c wait.h
       ./compile svscan.c

-svscanboot: home svscanboot.sh warn-auto.sh
+svscanboot:  svscanboot.sh warn-auto.sh
       rm -f svscanboot
       cat warn-auto.sh svscanboot.sh \
-       | sed s}HOME}"`head -1 home`"}g \
       > svscanboot
       chmod 555 svscanboot
Executing the script
Code:
# ./new_daemontools_compile

./new_daemontools_compile: OK found file daemontools-0.76.tar.gz
./new_daemontools_compile: OK found file new_daemontools_install
./new_daemontools_compile: OK found file dt-makefile.patch

-Unpacking daemontools-0.76.tar.gz

admin
admin/daemontools-0.76
admin/daemontools-0.76/package
admin/daemontools-0.76/package/README
admin/daemontools-0.76/package/files
admin/daemontools-0.76/package/sharing
admin/daemontools-0.76/package/commands
admin/daemontools-0.76/package/install
[snip]
admin/daemontools-0.76/src/readclose.c
admin/daemontools-0.76/src/openreadclose.h
admin/daemontools-0.76/src/openreadclose.c

./new_daemontools_compile: -------- Patching Makefile

Hmm...  Looks like a unified diff to me...
The text leading up to this was:
--------------------------
|--- Makefile    Thu Jul 12 18:49:49 2001
|+++ /tmp/Makefile       Sat Nov  5 02:56:33 2005
--------------------------
Patching file Makefile using Plan A...
Hunk #1 succeeded at 82.
Hunk #2 succeeded at 386.
done

./new_daemontools_compile: ------- compiling daemontools --------

sh find-systype.sh > systype
rm -f compile
sh print-cc.sh > compile
chmod 555 compile
./compile byte_chr.c
./compile byte_copy.c
./compile byte_cr.c
[snip]
./compile tai64nlocal.c
./load tai64nlocal unix.a byte.a
env - /bin/sh rts.tests 2>&1 | cat -v > rts
[snip]
grep sysdep iopause.h >> sysdeps
grep sysdep hasmkffo.h >> sysdeps
grep sysdep hasflock.h >> sysdeps
grep sysdep hasshsgr.h >> sysdeps

./new_daemontools_compile: ----- Compile finished --------
You now can run the new_daemontools_install script
__________________
You don't need to be a genius to debug a pf.conf firewall ruleset, you just need the guts to run tcpdump
Reply With Quote
  #2   (View Single Post)  
Old 13th November 2009
J65nko J65nko is offline
Administrator
 
Join Date: May 2008
Location: Budel - the Netherlands
Posts: 3,154
Thanked 182 Times in 149 Posts
Default new_daemontools_install

The main tasks of this script:
  • Allow choice of another 'service' directory than the default hardcoded '/service' by modifying the SERVICEDIR variable.
  • Patching of 'svscanboot' script to allow this choice
  • Installation of the daemontools executables
  • Adding start-up code to '/etc/rc.local'

Code:
#!/bin/sh +e
# $Id: new_daemontools_install,v 1.4 2009/11/13 03:52:31 root Exp $

# --- adjust these if needed

# Destination directory for the daemontools programs 
DESTDIR='/usr/local/bin'        

# The directory montored by svscan
SERVICEDIR=/var/service

DAEMONTOOLS='daemontools-0.76'  
# -----------------------------

CURDIR=$(pwd)

cd admin/${DAEMONTOOLS}/src/

FILE=svscanboot
echo $0: ------ Modifying ${FILE} to remove '/command' from PATH

cp -p  ${FILE} ${FILE}.orig

# --- inline patch !!!

cat <<'END' | patch  -l ${FILE}
--- svscanboot.orig     Sun Jan 22 05:40:17 2006
+++ svscanboot  Sun Jan 22 06:04:07 2006
@@ -1,13 +1,16 @@
 #!/bin/sh
 # WARNING: This file was auto-generated. Do not edit!
 
-PATH=/command:/usr/local/bin:/usr/local/sbin:/bin:/sbin:/usr/bin:/usr/sbin:/usr/X11R6/bin
+PATH=/usr/local/bin:/usr/local/sbin:/bin:/sbin:/usr/bin:/usr/sbin:/usr/X11R6/bin
 
+SERVICEDIR=$1
+[ "X$1" = "X" ] && SERVICEDIR=/service
+
 exec </dev/null
 exec >/dev/null
 exec 2>/dev/null
 
-/command/svc -dx /service/* /service/*/log
+/usr/local/bin/svc -dx $SERVICEDIR/* $SERVICEDIR/*/log
 
-env - PATH=$PATH svscan /service 2>&1 | \
+env - PATH=$PATH svscan $SERVICEDIR 2>&1 | \
 env - PATH=$PATH readproctitle service errors: ...........................................................
...........................................................................................................
...........................................................................................................
...........................................................................................................
....................
END

echo
echo  Modified/patched svscanboot file :
echo ----------------------------------------------------------
cat $FILE
echo ----------------------------------------------------------

echo "About to install. Press Cntrl-C to not install " ; read a

for prog in $(cat $CURDIR/admin/${DAEMONTOOLS}/package/commands) ; do
   echo Installing $prog
   cp -p $CURDIR/admin/${DAEMONTOOLS}/src/$prog $DESTDIR
done

echo
echo $0: Creating "$SERVICEDIR" directory

mkdir -p $SERVICEDIR 

# ---- add svscanboot startup to /etc/rc.local

echo
echo $0: Modifying "/etc/rc.local" to start up $DESTDIR/svscanboot at boot time
echo $0: $DESTDIR/svscanboot will monitor the service directory $SERVICEDIR

cat <<END >>/etc/rc.local
# -------- svscanboot of daemontools

SERVICEDIR=${SERVICEDIR}

if [ -x $DESTDIR/svscanboot ] ; then
   echo -n "Starting svscanboot to monitor \$SERVICEDIR"
   csh -cf "$DESTDIR/svscanboot \$SERVICEDIR &"
fi

END

echo
echo Contents of '/etc/rc.local':
cat /etc/rc.local
echo =========================v
echo $0: finished!
echo
Please note that I modified the script to use "/var/service".

Produced output:
Code:
# ./new_daemontools_install

./new_daemontools_install: ------ Modifying svscanboot to remove /command from PATH
Hmm...  Looks like a unified diff to me...
The text leading up to this was:
--------------------------
|--- svscanboot.orig    Sun Jan 22 05:40:17 2006
|+++ svscanboot Sun Jan 22 06:04:07 2006
--------------------------
Patching file svscanboot using Plan A...
Hunk #1 succeeded at 1.
done

Modified/patched svscanboot file :
----------------------------------------------------------
#!/bin/sh
# WARNING: This file was auto-generated. Do not edit!

PATH=/usr/local/bin:/usr/local/sbin:/bin:/sbin:/usr/bin:/usr/sbin:/usr/X11R6/bin

SERVICEDIR=$1
[ "X$1" = "X" ] && SERVICEDIR=/service

exec </dev/null
exec >/dev/null
exec 2>/dev/null

/usr/local/bin/svc -dx $SERVICEDIR/* $SERVICEDIR/*/log

env - PATH=$PATH svscan $SERVICEDIR 2>&1 | \
env - PATH=$PATH readproctitle service errors: ............................................................
...........................................................................................................
...........................................................................................................
...........................................................................................................
...................
----------------------------------------------------------
About to install. Press Cntrl-C to not install 

Installing svscan
Installing svscanboot
Installing supervise
Installing svc
Installing svok
Installing svstat
Installing fghack
Installing pgrphack
Installing readproctitle
Installing multilog
Installing tai64n
Installing tai64nlocal
Installing softlimit
Installing setuidgid
Installing envuidgid
Installing envdir
Installing setlock

./new_daemontools_install: Creating /var/service directory

./new_daemontools_install: Modifying /etc/rc.local to start up /usr/local/bin/svscanboot at boot time
./new_daemontools_install: /usr/local/bin/svscanboot will monitor the service directory /var/service

Contents of /etc/rc.local:
#       $OpenBSD: rc.local,v 1.39 2006/07/28 20:19:46 sturm Exp $

# Site-specific startup actions, daemons, and other things which
# can be done AFTER your system goes into securemode.  For actions
# which should be done BEFORE your system has gone into securemode
# please see /etc/rc.securelevel.

echo -n 'starting local daemons:'

# Add your local startup actions here.

echo '.'

# -------- svscanboot of daemontools

SERVICEDIR=/var/service

if [ -x /usr/local/bin/svscanboot ] ; then
   echo -n "Starting svscanboot to monitor $SERVICEDIR"
   csh -cf "/usr/local/bin/svscanboot $SERVICEDIR &"
fi

=========================v
./new_daemontools_install: finished!
The installed daemontools programs:
Code:
# ls -l /usr/local/bin
total 436
-rwxr-xr-x  1 root  wheel  13844 Nov 13 10:53 envdir
-rwxr-xr-x  1 root  wheel  13812 Nov 13 10:53 envuidgid
-rwxr-xr-x  1 root  wheel  13812 Nov 13 10:53 fghack
-rwxr-xr-x  1 root  wheel  22196 Nov 13 10:53 multilog
-rwxr-xr-x  1 root  wheel  13812 Nov 13 10:53 pgrphack
-rwxr-xr-x  1 root  wheel   5588 Nov 13 10:53 readproctitle
-rwxr-xr-x  1 root  wheel  13844 Nov 13 10:53 setlock
-rwxr-xr-x  1 root  wheel  13812 Nov 13 10:53 setuidgid
-rwxr-xr-x  1 root  wheel  13844 Nov 13 10:53 softlimit
-rwxr-xr-x  1 root  wheel  16436 Nov 13 10:53 supervise
-rwxr-xr-x  1 root  wheel  11956 Nov 13 10:53 svc
-rwxr-xr-x  1 root  wheel  11572 Nov 13 10:53 svok
-rwxr-xr-x  1 root  wheel  17940 Nov 13 10:53 svscan
-r-xr-xr-x  1 root  wheel    800 Nov 13 10:56 svscanboot
-rwxr-xr-x  1 root  wheel  13844 Nov 13 10:53 svstat
-rwxr-xr-x  1 root  wheel   5652 Nov 13 10:53 tai64n
-rwxr-xr-x  1 root  wheel   9716 Nov 13 10:53 tai64nlocal
To start daemontools you either reboot or execute the startup code in "/etc/rc.local'.
The following processes will now be running:
Code:
 8594 C0- I       0:00.00 /bin/sh /usr/local/bin/svscanboot /var/service
21025 C0- S       0:00.01 svscan /var/service
17921 C0- I       0:00.00 readproctitle service errors: .........................
__________________
You don't need to be a genius to debug a pf.conf firewall ruleset, you just need the guts to run tcpdump

Last edited by J65nko; 13th November 2009 at 10:27 AM. Reason: Upgrading placeholder to the 'Real Thing (tm)'
Reply With Quote
  #3   (View Single Post)  
Old 13th November 2009
J65nko J65nko is offline
Administrator
 
Join Date: May 2008
Location: Budel - the Netherlands
Posts: 3,154
Thanked 182 Times in 149 Posts
Default Dowload

The two scripts and patch file
Code:
$ tar -tvzf OBSDdaemontools_utils.tgz 

-rw-r--r--  1 root     wheel          711 Nov 25  2005 dt-makefile.patch
-rwxr-xr-x  1 root     wheel          825 Nov 13 03:37 new_daemontools_compile
-rwxr-xr-x  1 root     wheel         2676 Nov 13 10:55 new_daemontools_install
Attached Files
File Type: tgz OBSDdaemontools_utils.tgz (1.6 KB, 48 views)
__________________
You don't need to be a genius to debug a pf.conf firewall ruleset, you just need the guts to run tcpdump
Reply With Quote
Reply

Thread Tools
Display Modes

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 On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Can't load any scripts in ircII guitarscn General software and network 4 22nd November 2010 12:06 AM
Executing web scripts : can't! erehwon OpenBSD General 3 3rd November 2009 10:02 PM
Howto Compile in OpenBSD 4.5 shep OpenBSD Packages and Ports 2 7th May 2009 11:25 PM
Windows scripts can't print drhowarddrfine Other OS 15 31st March 2009 08:53 AM
Periodic scripts for mail scripts stukov FreeBSD General 2 8th March 2009 07:51 PM


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


Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Content copyright © 2007-2010, the authors
Daemon image copyright ©1988, Marshall Kirk McKusick