LinuxQuestions.org
Visit the LQ Articles and Editorials section
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices

Reply
 
LinkBack Search this Thread
Old 08-13-2010, 08:03 AM   #1
umaparvahty
LQ Newbie
 
Registered: Nov 2009
Posts: 4

Rep: Reputation: 0
install sysvscript with rpm


Hi All,

i would like to create a rpm . But it should have sysV init script to start and stop service which has to be installed into /etc/init.d....

I'm using a tarball as a source which has one excutable file,conf file.. that conf file should go to /etc/, executable file should go to /usr/sbin

so in the spec file i've given like (spec file for daemonsas)
---------------------------------------
%prep
%setup -q
%build
%configure
make
%install
install -s -m 755 daemonsas /usr/sbin/
install -m 644 daemonsas.conf /etc
install -s -m daemonsasservice.sh /etc/init.d
%files
%defattr(-,root,root)
/usr/sbin/daemonsas
/etc/daemonsas.conf
/etc/init.d/daemonsasservice
---------------------------------------
the error i'm getting in both build and install section... Don't know y?

The error is: ./configure no such file or directory


so i removed the build section then executed the rpmbuild to create rpm but in install section also throws some error like

daemonsasservice.sh --- file format not found..

Y such errors are coming?.. Please help me out in the spec file...

Let me know how to create a service in linux
should i give sh for the sevice...
just creating the script file in /etc/init.d/ ll make the script as a service?

Thanks,
uma
 
Old 08-14-2010, 04:28 AM   #2
unSpawn
Moderator
 
Registered: May 2001
Posts: 26,534
Blog Entries: 51

Rep: Reputation: 2601Reputation: 2601Reputation: 2601Reputation: 2601Reputation: 2601Reputation: 2601Reputation: 2601Reputation: 2601Reputation: 2601Reputation: 2601Reputation: 2601
Quote:
Originally Posted by umaparvahty View Post
i would like to create a rpm .
Creating packages using prefab binaries results in packages that should not be publicly distributed because nobody will be able to determine source origin, changes et cetera. Commonly RPM packages are created by using the original source archive, maybe patch the source or inject files, and the './configure, make, make install' mantra.


Quote:
Originally Posted by umaparvahty View Post
daemonsasservice.sh --- file format not found..

Y such errors are coming?..
Because in "-m filename" you forgot to put in the permission like "-m 0640 filename". You should read at least the http://www.rpm.org/max-rpm/ and http://docs.fedoraproject.org/en-US/...ide/index.html because your .spec file (if you posted the complete one) does not conform to any standards. If you build this as root account user, which you should not need to do ever, then you compromise system integrity because you overwrite system files instead of using a $RPM_BUILD_ROOT.


Quote:
Originally Posted by umaparvahty View Post
Let me know how to create a service in linux
should i give sh for the sevice...
just creating the script file in /etc/init.d/ ll make the script as a service?
Copy one of the SysV init scripts in /etc/rc.d/init.d/ to your package building area and use it as template to create the init script for your service. Test the script works then %install the script and in the %post section (add a user account if required and) use the available tools like 'chkconfig' to add the service:
Code:
%post
if [ "$1" = "1" ]; then
 #This package is being installed for the first time
 #SysV init script /etc/rc.d/init.d/daemonsas
 chkconfig --add daemonsas
fi
* Finally please mind how you write things as writing "Y such errors" makes no sense if you are going to write out the rest of the words and the whole IM / texting style isn't appreciated here anyway.
 
1 members found this post helpful.
Old 08-15-2010, 12:01 PM   #3
umaparvahty
LQ Newbie
 
Registered: Nov 2009
Posts: 4

Original Poster
Rep: Reputation: 0
RPM build errors: file not found

Hi,

here is my complete spec file
----------------------------------
# This is the spec file for daemonsas
%define _topdir /usr/local/up/rpm
%define name daemonsas
%define release 1
%define version 1.2
%define buildroot %{_topdir}/%{name}-%{version}-root
BuildRoot:%{_topdir}
Summary:GNU daemonsas
License:GPL
Name:%{name}
Version:%{version}
Release:%{release}
Source:%{name}-%{version}.tgz
Group: Development tools
%description
Listen the tcp port and prints the received messages from the port to syslog
%prep
%setup -q
%install
rm -rf $RPM_BUILD_ROOT
mkdir -p $RPM_BUILD_ROOT/usr/sbin/daemonsas-1.2
mkdir -p $RPM_BUILD_ROOT/etc/daemonsas-1.2
mkdir -p $RPM_BUILD_ROOT/etc/init.d/daemonsas-1.2
# install -m 755 -d %{buildroot}/usr/sbin/daemonsas-1.2
# install -m 755 -d %{buildroot}/etc/daemonsas-1.2
install -m 755 daemonsas $RPM_BUILD_ROOT/usr/sbin/daemonsas-1.2
install -m 644 daemonsas.conf $RPM_BUILD_ROOT/etc/daemonsas-1.2
install -m 755 daemond $RPM_BUILD_ROOT/etc/init.d/daemonsas-1.2
%clean
[ "$RPM_BUILD_ROOT" != "/" ] && rm -rf $RPM_BUILD_ROOT
%post
# cp daemond /etc/init.d
# chmod +x /etc/init.d/daemond
if [ -x /sbin/chkconfig ]; then
/sbin/chkconfig -add daemond
else
for i in 2 3 5 ; do
ln -sf /etc/init.d/daemond /etc/rc.d/rc${i}.d/S91daemond
done
for i 1 4 6 ; do
ln -sf /etc/init.d/daemond /etc/rc.d/rc${i}.d/K30daemond
done
fi
%preun
if [ $1 = 0 ] ; then
/sbin/chkconfig --del daemond
/sbin/service daemond stop &>/dev/null
fi
exit 0
%files
%defattr(-, root, root)
/usr/sbin/daemonsas-1.2/daemonsas
/etc/daemonsas-1.2/daemonsas.conf
/etc/init.d/daemond
-------------------

The error is

+ install -m 755 daemonsas $'/usr/local/up/rpm/daemonsas-1.2-root/usr/sbin/daemonsas-1.2\r'
+ install -m 644 daemonsas.conf $'/usr/local/up/rpm/daemonsas-1.2-root/etc/daemonsas-1.2\r'
+ install -m 755 daemond $'/usr/local/up/rpm/daemonsas-1.2-root/etc/init.d/daemonsas-1.2\r'
+ /usr/lib/rpm/brp-compress
+ /usr/lib/rpm/brp-strip
+ /usr/lib/rpm/brp-strip-static-archive
+ /usr/lib/rpm/brp-strip-comment-note
Processing files: daemonsas-1.2-1
error: File must begin with "/":
error: File not found: /usr/local/up/rpm/daemonsas-1.2-root/usr/sbin/daemonsas-1.2/daemonsas
error: File not found: /usr/local/up/rpm/daemonsas-1.2-root/etc/daemonsas-1.2/daemonsas.conf
error: File not found: /usr/local/up/rpm/daemonsas-1.2-root/etc/init.d/daemond


RPM build errors:
File must begin with "/":
File not found: /usr/local/up/rpm/daemonsas-1.2-root/usr/sbin/daemonsas-1.2/daemonsas
File not found: /usr/local/up/rpm/daemonsas-1.2-root/etc/daemonsas-1.2/daemonsas.conf
File not found: /usr/local/up/rpm/daemonsas-1.2-root/etc/init.d/daemond


--------------------------

if i look in daemonsas-1.2-root dir, i've etc,sbin dir
but in etc, sbin directories have a sub dir as "daemonsas-1.2?"
why such character(?) is added with the dir???....

if i add the '?' character in the files section such as

%files
%defattr(-,root,root)
/usr/sbin/daemonsas-1.2?/daemonsas
/etc/daemonsas-1.2?/daemonsas
/etc/init.d/daemonsas-1.2?/daemond

the error as

"RPM build errors:
File must begin with "/":


Please help me out ..



Thanks in advance,

regards,
umaparvathy
 
Old 08-15-2010, 06:33 PM   #4
unSpawn
Moderator
 
Registered: May 2001
Posts: 26,534
Blog Entries: 51

Rep: Reputation: 2601Reputation: 2601Reputation: 2601Reputation: 2601Reputation: 2601Reputation: 2601Reputation: 2601Reputation: 2601Reputation: 2601Reputation: 2601Reputation: 2601
The "\r" may be due to transferring files between systems with different line endings, you propose to use paths that do not conform to the FSSTND or FHS, you use application versions in path names other than /usr/share/doc/%{name}, there is no "GNU daemonsas", you haven't used the right Group: tag, you have a malformed %files section, and there is no documentation and manual. What's more you haven't acknowledged you're building packages the bad way so you probably do not understand any of the dangers. This is also shown by you building somewhere in the root-owned "/usr/local" path so I wouldn't be surprised if you actually do run your build process as root user and have read none of the docs linked to.

Here is a .spec file that should build OK as unprivileged user and having a tarball with contents that mimic a tree populated the way 'make install' would (%{name}-%{ver}/{etc,usr}/path/item):
Code:
%define debug_packages	%{nil}
%define debug_package %{nil}
%define name daemonsas
%define ver 1.2
%define rel 1

Name: %{name}
Summary: %{name}, listens and prints messages sent over TCP to syslog
Version: %{ver}
Release: %{rel}
License: GPL
# (See /usr/share/doc/rpm-.*/GROUPS)
Group: Utilities/System
Source: %{name}-%{ver}.tar.gz
Provides: %{name}
BuildRoot: %{_tmppath}/%{name}-%{ver}
%description 
%{name} listens and prints messages sent over TCP to syslog.

%prep
%setup -n %{name}-%{ver}
DUMB=`id -g`
[ $DUMB -eq 0 ] && exit 127
DUMB=`rpm --eval '%{_sourcedir}'`
[ "${DUMB:1:4}" = "root" ] && exit 127
[ "${DUMB:1:3}" = "usr" ] && exit 127

%install
if [ "$RPM_BUILD_ROOT" = "%{_tmppath}/%{name}-%{version}" ]; then
	rm -rf $RPM_BUILD_ROOT
	mkdir -p $RPM_BUILD_ROOT/usr/local/sbin
	mkdir -p $RPM_BUILD_ROOT/etc
	mkdir -p $RPM_BUILD_ROOT/etc/rc.d/init.d
	install -m 755 usr/local/sbin/%{name} $RPM_BUILD_ROOT/usr/local/sbin
	install -m 644 etc/%{name}.conf $RPM_BUILD_ROOT/etc
	install -m 755 etc/rc.d/init.d/%{name}d $RPM_BUILD_ROOT/etc/rc.d/init.d
fi

%clean
if [ "$RPM_BUILD_ROOT" = "%{_tmppath}/%{name}-%{version}" ]; then
	rm -rf $RPM_BUILD_ROOT
else
	echo "Invalid Build root "${RPM_BUILD_ROOT}"."
	exit 1
fi

%post
if [ "$1" = "1" ]; then
 chkconfig --add %{name}d
fi

%preun
if [ "$1" = "0" ]; then
	service %{name}d stop >/dev/null 2>&1
	chkconfig --del %{name}d
fi

%files
%defattr(-,root,root)
%attr(644,root,root) %config(noreplace) %{_sysconfdir}/%{name}.conf
%attr(755,root,root) /etc/rc.d/init.d/%{name}d
%attr(755,root,root) /usr/local/sbin/%{name}

%changelog
* Mon Aug 16 2010 %{packager} - init 
- Initialize %{name}-%{ver}.%{rel}.
YMMV(VM)
 
1 members found this post helpful.
Old 08-16-2010, 10:56 AM   #5
umaparvahty
LQ Newbie
 
Registered: Nov 2009
Posts: 4

Original Poster
Rep: Reputation: 0
Hi,

i set the fileformat as unix by using
Code:
:set fileformat=unix
then it's creating rpm....

But while installing rpm i'm getting the following error

Code:
[root@localhost i686]# rpm -ivh daemonsas-1.2-1.i686.rpm
Preparing...                ########################################### [100%]
   1:daemonsas              ########################################### [100%]
error reading information on service daemond: No such file or directory
error: %post(daemonsas-1.2-1.i686) scriptlet failed, exit status 1
the content of the daemond is
Code:
#!/bin/sh
# chkconfig: 235 91 30
# processname:daemond
# pidfile: /var/run/daemond.pid
# config /etc/daemonsas-1.2/daemonsas.conf
#source function library
. /etc/rc.d/init.d/functions

RET=0
daemonsas="/usr/sbin/daemonsas-1.2/daemonsas"
lockfile="/var/run/subsys/daemonsas"

case "$1" in 
	start)
		echo "***starting the service***"
		if [ -f $daemonsas ] ; then
			daemon $daemonsas 
			RET=$?
			echo 
			[ $RET = 0 ] && touch ${lockfile}
		fi	
		;;
	stop)
			echo "***stoping the service***"
			killproc -d 10 $daemonsas
			RET=$?
			echo
			[ $RET -eq 0 ] && rm -f ${lockfile}
			;;
	status)
			echo "***status the service***"
			status daemond
			RET=$?
			;;
	restart)
			echo "***restarting the service***"
			$0 stop
			sleep 3
			$0 start
			;;
	reload)
			echo "***Reloading the service***"
			killproc $daemonsas -HUP
			;;
	*)
			echo "usage: $0 {start|stop|restart|reload|status}"
			exit 1
esac
exit $RET
Please help me out...
Thanks in advance....

Regards,
Umaparvathy
 
Old 08-16-2010, 06:49 PM   #6
unSpawn
Moderator
 
Registered: May 2001
Posts: 26,534
Blog Entries: 51

Rep: Reputation: 2601Reputation: 2601Reputation: 2601Reputation: 2601Reputation: 2601Reputation: 2601Reputation: 2601Reputation: 2601Reputation: 2601Reputation: 2601Reputation: 2601
In the /spec I set '%define name daemonsas' and the SysV init scripts name to '/etc/rc.d/init.d/%{name}d'. "daemond" is way too generic.
 
  


Reply

Tags
file, rpm, spec


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
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Which path to use to query rpm to determine which RPM to install? elitt2 Red Hat 4 10-08-2007 01:18 PM
How to install remotely RPM if you dont have RPM!! reymoskito Fedora 1 05-05-2006 03:13 PM
How do I force an older rpm to install over a newer rpm of wine onyx Linux - Software 4 02-20-2004 12:44 AM
RPM 'failed dependencies': Why can I not install any rpm packages? leontini Linux - Newbie 7 09-16-2003 12:44 AM
Help : rpm dependency error when install video driver rpm ymdwxm Linux - Software 1 04-04-2003 04:55 PM


All times are GMT -5. The time now is 09:30 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