user1285928
user1285928

Reputation: 1476

Install init script after RPM install

I have this spec file which is used to extract files into directory:

Version:        1.0
Release:        1%{?dist}
Summary:        Linux Agent installation script
Group:          Utilities
License:        license
Source0:        agent-1.0.tar.gz
BuildArch:      x86_64
BuildRoot:      %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n)
%description

%prep
%setup -q -n agent

%build

%install
install -m 0755 -d %{buildroot}/agent
cp -a * %{buildroot}/agent

%clean
rm -rf $RPM_BUILD_ROOT

%files
/agent
%defattr(-,root,root,-)

%doc
%changelog

I want to modify the RPM package also to install init scripts into Linux.

I want to run these commands after RPM install:

ln -s /agent/apache-karaf-4.0.0/bin/karaf-service /etc/init.d/

/etc/init.d/karaf-service start

Which approach is better: - Copy the files after they are extracted - Copy the files from the RPM

I'm not very familiar, can you give advice and how I can implement the commands into spec file?

Upvotes: 1

Views: 4739

Answers (2)

msuchy
msuchy

Reputation: 5437

See:

https://fedoraproject.org/wiki/Packaging:ScriptletSnippets#Systemd

https://fedoraproject.org/wiki/Packaging:Systemd?#Filesystem_locations

Note that automatically enable service is not generally good approach as installations can be in changeroots, in an installer context, or in other situations where you don't want the services autostarted.

Upvotes: 1

Etan Reisner
Etan Reisner

Reputation: 80992

Don't install files to anywhere directly under / it is bad practice. If you need an entire hierarchy of your own use /opt/agent. If you want to integrate with the system cleanly then just use /usr like system packages.

If the service file in question is in this RPM then you can install it to %{buildroot}/opt/agent/apache-karaf-4.0.0/bin/karaf-service (or wherever) and create the ${buildroot}/etc/init.d/karaf-service link during %install and then include both of those files in the %files section.

Upvotes: 0

Related Questions