LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Slackware
User Name
Password
Slackware This Forum is for the discussion of Slackware Linux.

Notices

Reply
 
Search this Thread
Old 11-27-2007, 04:11 PM   #1
agentc0re
Member
 
Registered: Apr 2007
Location: SLC, UTAH
Distribution: Slackware
Posts: 200

Rep: Reputation: 32
Question src2pkg for nagios


Hey gnashley, I am running into a problem when trying to make nagios 2.10 into a package using src2pkg.
here's how i'm trying to accomplish it.
src2pkg build script
Code:
#!/bin/bash
## src2pkg script for: 	nagios
## Auto-generated by src2pkg-1.6
## src2pkg Copyright 2005-2007 Gilbert Ashley <amigo@ibilio.org>
## Full package name: nagios-2.10-i486-1.tgz

SOURCE_NAME='nagios-2.10.tar.gz'
NAME='nagios'
VERSION='2.10'
ARCH='i486'
BUILD='1'
PRE_FIX='/opt/nagios'
# Any extra options go here
# EXTRA_CONFIGS=''
# STD_FLAGS='-O2 -march=i486 -mtune=i686'
#MAKE_COMMAND='make all'
INSTALL_LINE='make all'
INSTALL_LINE='make install'
INSTALL_LINE='make install-config'
INSTALL_LINE='make install-init'
#Create User and Group Nagios
groupadd nagios
useradd nagios -g nagios
mkdir $PKG_DIR/opt/nagios
chown -R nagios.nagios $PKG_DIR/opt/nagios
# Get the functions and configs
. /usr/libexec/src2pkg/FUNCTIONS ;

# do_all_processes can substitute these 16 steps:

pre_process
find_source
make_dirs
unpack_source
fix_source_perms
configure_source
compile_source
fake_install

#chown -R nagios.nagios $PKG_DIR/opt/nagios
mv $PKG_DIR/etc/rc.d/nagios $PKG_DIR/etc/rc.d/rc.nagios
fix_pkg_perms
strip_bins
create_docs
compress_man_pages
make_description
make_doinst
make_package
post_process

# src2pkg - Copyright 2005-2007  Gilbert Ashley <amigo@ibiblio.org>
## See the documentation for more help and examples. Below are some of
# the most common Extras and Options for easy cut-and-paste use.
# EXTRA_CONFIGS='' PRE_FIX='' DOCLIST=''
# MAKE_COMMAND='' INSTALL_LINE='' 
# SHELL_INSTALL='YES' CORRECT_PERMS='NO'
I executed this by running
Code:
src2pkg -C -X
What happens is that, and please correct me where i am wrong, where it's supposed to do the "fake install" (im guessing this is watching where the files really need to go and then places them in the PKG_DIR) seems like it's not seeing anything and the files are actually being installed to my /opt/nagios DIR. i guess i could change the prefix to $PKG_DIR/opt/nagios, maybe? or in the script, mv the /opt/nagios dir to $PKG_DIR/opt/nagios.

also, do you think that is the correct way to do add the users needed?

P.S. Thank you for the webmin help. i did get that one made. it was very much appreciated. **insert brown nose smiley here
 
Old 11-27-2007, 11:24 PM   #2
gnashley
Amigo developer
 
Registered: Dec 2003
Location: Germany
Distribution: Slackware
Posts: 4,755

Rep: Reputation: 466Reputation: 466Reputation: 466Reputation: 466Reputation: 466
Code:
SOURCE_NAME='nagios-2.10.tar.gz'
NAME='nagios'
VERSION='2.10'
ARCH='i486'
BUILD='1'
PRE_FIX='/opt/nagios'
# Any extra options go here
EXTRA_CONFIGS='--sysconfdir=/etc --with-initdir=/etc/rc.d --with-lockfile=/var/run/nagios.pid'

# STD_FLAGS='-O2 -march=i486 -mtune=i686'
MAKE_COMMAND='make all'
INSTALL_LINE='make install install-config install-init'

# Get the functions and configs
. /usr/libexec/src2pkg/FUNCTIONS ;

# do_all_processes can substitute these 16 steps:

pre_process
find_source
make_dirs
unpack_source
fix_source_perms
configure_source
compile_source

# see notes
fake_install


# see notes 
fix_pkg_perms
chown -R nagios:nagios $PKG_DIR/opt/nagios

strip_bins
create_docs
compress_man_pages
make_description
make_doinst
make_package
post_process

When you need to run multiple make rules put them all together as shown for INTALL_LINE. For EXTRA_CONFIGS you might consider adding the options for --with-htmlurl and perhaps for nagios-user/nagios-group and command-user/command-group depending on who you want to allow to run the program. Usually, if the program is a sort of daemon, you'd make the user 'nobody' in Slackware with group users.
Do the chowning after the fix_pkg_perms to 'undo' the regular way, although I think that the normal root:root may be correct in this case.

This should be done after fake_install:
mv $PKG_DIR/etc/rc.d/nagios $PKG_DIR/etc/rc.d/rc.nagios
Usually, these init files need to be hand edited in order to work properly with Slackware, though in this case it looks like it might just work, if you have given enough of the needed extra options to configure and if you have the latest slack init-scripts which include the /etc/rc./init.d/finctions file. For better compatibility with Slack-11 and just for better control, you should consider hand-editing the init file and then copy it into the $PKG_DIR/etc/rc.d directory after fake_install runs, something like:

rm -f $PKG_DIR/etc/rc.d/nagios
cp $CWD/rc.nagios $PKG_DIR/etc/rc.d/
chown root:root $PKG_DIR/etc/rc.d/rc.nagios
chmod 644 $PKG_DIR/etc/rc.d/rc.nagios


#Create User and Group Nagios
groupadd nagios
useradd nagios -g nagios
The commands to create a new user and group should, most properly go in a doinst.sh file which gets run when the package is installed. Use grep to make sure that the user and group don't already exist, so that you don't get multiple entries if you install the package several times.

if [ $(grep nagios /etc/group) != "" ] ; then
groupadd nagios
fi

if [ $(grep nagios /etc/passwd) != "" ] ; then
useradd nagios -g nagios
fi

Build the package first without any doinst.sh file to see whether src2pkg produces one. If the 'make install' rules create any links then src2pkg will create a doinst.sh for you with the code for creating the links when the package is installed. You can then add the above code for group/useradd to that doinst.sh. You may also want to add code which echos a couple of lines into /etc/rc.d/rc.local which check to see if /etc/rc.d/rc.nagios is executable and which start the service if it is. Use the example from webmin for code sample.

A little trick: if the package indeed creates links, you can preserve the ability to have src2pkg add them automatically by placing any other code you want added to the doinst.sh in a file named doinst.prepend or doinst.append, depending on whether you want the code before or after the link-creation lines. This is most handy for packages whose link-creation lines change when you build a new version -usually for libs, so that may not be the case here. Once you place a file named doinst.sh in the $CWD it will be added to the package *without changes*.

I won't 'steal your thunder' by doing the whole thing for you this time-you seem to want to learn more and besides, I'm in the middle of adding serious new code to src2pkg so my running version is only semi-functional at the moment. the webmin package should give you some good examples.
One other thing, nagios appears to support using DESTDIR, so if you have any problems getting it to install correctly as shown above, you could always comment out the fake_install line and put this in its' place:

mkdir -p $PKG_DIR/$PRE_FIX
cd $SRC_DIR && make DESTDIR=$PKG_DIR install install-config install-init

Cheers!
 
Old 11-28-2007, 12:45 PM   #3
agentc0re
Member
 
Registered: Apr 2007
Location: SLC, UTAH
Distribution: Slackware
Posts: 200

Original Poster
Rep: Reputation: 32
Quote:
Originally Posted by gnashley View Post
[CODE]
One other thing, nagios appears to support using DESTDIR, so if you have any problems getting it to install correctly as shown above, you could always comment out the fake_install line and put this in its' place:

mkdir -p $PKG_DIR/$PRE_FIX
cd $SRC_DIR && make DESTDIR=$PKG_DIR install install-config install-init

Cheers!
AH HA! thats what i was needing to know. I didn't look into it much but when i did a search for any slack builds for nagios i found one and it had a similar command in there for DESTDIR. So i tried to impliment it into the INSTALL_LINE but it didn't work for me. Probably because i put the DESTDIR after install. just used the wrong syntax. and since you suggested to comment out fake_install, it probably wouldn't have worked even if i did put it in correctly. Thank you for showing me that.

so i got the package built fine. even made my own (first one too) doinst.sh. I don't have a ftp server or anything to upload this stuff too so i'll just post it again. I know there are a TON of "free" places i could chose from, any you or anyone else for that matter, recommends?

My doinst.sh
Code:
root@yoda:/tmp/nagios# cat doinst.sh
#~/bin/sh

if [ "$(grep nagios /etc/group)" = "" ] ; then
        groupadd nagios
        echo -e '\E[34mUser nagios has been added.'
else
        echo -e '\E[34mUser Nagios already exists.'
fi

if [ "$(grep nagios /etc/passwd)" = "" ] ; then
        useradd nagios -g nagios
        echo "Group nagios has been added"
else
        echo "Group nagios already exists"
fi

if [ "$(grep  nagioscmd /etc/group)" = "" ] ; then
        groupadd nagioscmd
        usermod -G nagioscmd apache
        usermod -G nagioscmd nagios
        echo "Group nagioscmd with users apache and nagios apart of it."
else
        echo "Group nagioscmd already exists"
fi

if [[ "$(grep 'rc.nagios' /etc/rc.d/rc.local)" = "" ]] ; then

        echo "" >> /etc/rc.d/rc.local
        echo "# Start Nagios:" >> /etc/rc.d/rc.local
        echo "if [ -x /etc/rc.d/rc.nagios ]; then" >> /etc/rc.d/rc.local
        echo "   /etc/rc.d/rc.nagios start" >> /etc/rc.d/rc.local
        echo "fi" >> /etc/rc.d/rc.local
        echo "/etc/rc.d/rc.local has been modified to start nagios on start up."
else
        echo "An entry to start rc.nagios at start-up already exists"
fi

if [[ "$(grep 'nagios.conf' /etc/httpd/httpd.conf)" = "" ]] ; then
        echo "" >> /etc/httpd/httpd.conf
        echo "#Enable nagios for browsing" >> /etc/httpd/httpd.conf
        echo "Include /etc/httpd/nagios.conf" >> /etc/httpd/httpd.conf
        echo "/etc/httpd/httpd.conf has been modified to include nagios.conf."
        echo "Restarting Apache."
        apachectl restart
else
        echo "An entry to include nagios.conf already exists in your"
        echo "/etc/httpd/httpd.conf."
fi
echo -e '\E[34m' ; tput sgr0
sleep 3
My src2pkg script (not much changed really, posting in case someone else needs it)
Code:
#!/bin/bash
## src2pkg script for:  nagios
## Auto-generated by src2pkg-1.6
## src2pkg Copyright 2005-2007 Gilbert Ashley <amigo@ibilio.org>
## Full package name: nagios-2.10-i486-1.tgz

SOURCE_NAME='nagios-2.10.tar.gz'
NAME='nagios'
VERSION='2.10'
ARCH='i486'
BUILD='1'
PRE_FIX='/opt/nagios'
# Any extra options go here
# EXTRA_CONFIGS=''
# STD_FLAGS='-O2 -march=i486 -mtune=i686'
#MAKE_COMMAND='make all'
EXTRA_CONFIGS='--sysconfdir=/etc --with-initdir=/etc/rc.d --with-lockfile=/var/run/nagios.pid --with-nagios-user=nagios --with-nagios-group=nagios --with-command-group=nagioscmd'
MAKE_COMMAND='make all'
INSTALL_LINE='make install install-config install-init'
FORCE_ZERO_LENGTH="YES"
# Get the functions and configs
. /usr/libexec/src2pkg/FUNCTIONS ;

# do_all_processes can substitute these 16 steps:

pre_process
find_source
make_dirs
unpack_source
fix_source_perms
configure_source
compile_source
#fake_install
mkdir -p $PKG_DIR/$PRE_FIX
cd $SRC_DIR && make DESTDIR=$PKG_DIR install install-config install-init
mv $PKG_DIR/etc/rc.d/nagios $PKG_DIR/etc/rc.d/rc.nagios
mkdir $PKG_DIR/etc/httpd
cp $CWD/nagios.conf $PKG_DIR/etc/httpd/

fix_pkg_perms
chown -R nagios:nagios $PKG_DIR/opt/nagios

strip_bins
create_docs
compress_man_pages
make_description
make_doinst
make_package
post_process

# src2pkg - Copyright 2005-2007  Gilbert Ashley <amigo@ibiblio.org>
## See the documentation for more help and examples. Below are some of
# the most common Extras and Options for easy cut-and-paste use.
# EXTRA_CONFIGS='' PRE_FIX='' DOCLIST=''
# MAKE_COMMAND='' INSTALL_LINE=''
# SHELL_INSTALL='YES' CORRECT_PERMS='NO'
 
Old 11-28-2007, 01:54 PM   #4
gnashley
Amigo developer
 
Registered: Dec 2003
Location: Germany
Distribution: Slackware
Posts: 4,755

Rep: Reputation: 466Reputation: 466Reputation: 466Reputation: 466Reputation: 466
FWIW, the INSTALL_LINE is superfluous if you comment out the fake_install function. What I meant was that if the fake_install function would correctly install using the INSTALL_LINE as given, then you could do it the alternate way by using the manual ceration of $PKG_DIR/$PRE_FIX and using DESTDIR in the 'make install' rule. Sometimes this works when fake_install won't, but fake_install works more reliably than DESTDIR -statistically. Some packages seem to need DESTDIR like this: 'make DESTDIR=?? install' and others can take it like:
'make install DESTDIR=??'

DESTDIR should *not* be used in INSTALL_LINE for fake_install. The fake_install routine attempts to do a real installation in the real location and uses installwatch to track the files created. Anything which gets overwritten on your system gets backed up first, then the new files are installed, then copied into the PKG_DIR, then the backed up files are copied back to the real file system. Pretty complicated the way it happens, but works remarkably well -as mentioned more often than DESTDIR. The worst thing about DESTDIR is when sources only support it *partially*. This means that some files get copied into the DESTDIR while others get installed to your real system -and there is virtually no way to know that this has happened.

The 'serious coding' that I mentioned I am working on invloves getting installwatch to do an even better job by simulating a root directory -sort of like installing in a chroot directory, which should make it more dependable and less intrusive at the same time.

Congrats on your progress in learning to use src2pkg -you've started by attempting some fairly difficult packages. But just look at how simple the scripts are compared to a very basic SlackBuild!

As far as where to upload your packages, you could always try putting them on linuxpackages.net, although you'll have to include a 'slack-requires' file in order to get them approved, I think. I only host packages that I have compiled on my site, but perhaps I'll compile and package it using and (crediting) your work on getting it working smoothly with config and doinst.sh tweaks -that's the most important and hardest part, anyway, -src2pkg make the routine parts of packaging easy so you shouldn't mind running the build and installation a few times to make sure everything is right. Bet you are itching to build something else...
 
  


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
src2pkg-1.6 released gnashley Slackware 32 11-17-2007 03:03 PM
src2pkg 1.5 question hitest Slackware 4 08-01-2007 02:58 PM
Nagios Daemon, PID not found but rc.nagios runs agentc0re Slackware 1 07-03-2007 02:47 PM
LXer: Nagios 2.5 and Oreon 1.3 (Nagios web front end) installation with screenshots LXer Syndicated Linux News 0 08-11-2006 05:33 PM
LXer: Nagios and Oreon (Nagios web front end) installation and Configuration LXer Syndicated Linux News 0 07-18-2006 08:33 PM


All times are GMT -5. The time now is 05:16 PM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration