Build a package for Solaris from sorts

Foreword


So, you have the source code of the program you really need and some number of servers for Solaris on which you need to deploy it. Moreover, for a successful compilation you need a bunch of Perl modules.

Not so long ago, I faced such a problem, and, after lengthy attempts, I can not help but share the solution found.

Task: Collect the source code of the munin-node client under SPARC Solaris and distribute it to several servers.

The whole process will be described using the Solaris 10 SPARC operating system as an example (update, it seems to me that it does not play a special role, I had both U6 and U9) and the free munin application (http://munin-monitoring.org/).

Training


To build the package you will need the following:

I fully admit that there may be problems with the last paragraph. Although usually the developer explicitly indicates which modules are needed. The whole problem is that the developer is unlikely to indicate the dependencies of the necessary modules.

Assembly


First of all, you need to install Perl modules. In part, it was for the successful assembly of a package that included Perl modules that it was indicated above that a test server with a clean axis was needed. The fact is that all modules are stored in one place. This is usually / usr / perl5 / site_perl / <version> /. It is advisable that at the time of installing the modules for your program this folder, like / usr / local / perl5 / <version> /, should be empty. This will facilitate the process of integrating modules into the package.

Note: by <version > - this means the working version of Perl on the server.

The easiest way is to install using CPAN.
# perl -MCPAN -e shell 

cpan> install Module::Name


The desired module is installed, pulling up all the dependencies. The network has enough information on CPAN, so I will skip the time with installing modules. I only note that it’s much more efficient to deploy a CPAN mirror somewhere in your home than to download them separately. Moreover, the mirror is configured very quickly, and the total volume at the moment does not exceed 2GB! Manual installation is fraught with extremely long and unpleasant searches for dependent modules.

When all the modules are installed, run:
# find /usr/perl5/site_perl/5.8.8/ > /tmp/perl_files


I will return to the file / tmp / perl_files later.

Now about the source code.
Most sources allow you to specify the path to build when compiling. In other words, it is possible to indicate explicitly in which directory all compiled files are placed.

Compile the source code in the desired directory (/ pkg):
# make DESTDIR=/pkg
# make install-common-prime DESTDIR=/pkg
# make install-node DESTDIR=/pkg
# make install-plugins-prime DESTDIR=/pkg


The source code of the munin-node program has been compiled and installed.
Let me explain a little why this is done. During normal compilation, without specifying DESTDIR, the program will be installed in those directories that are registered in Makefile.config. In this case, it will be difficult to put together all the information about which directories which files were installed.
Now you need to make a list of all the files in our program:
# find /pkg -print > /tmp/files


In this case, the find command will list the contents of / pkg, then the output of the command will be sent to the / tmp / files file.
After that, you need to edit the file / tmp / files, removing the / pkg directory from all paths.
Now you can install the program, as expected, without specifying DESTDIR.
Earlier, I used the find command to create the file / tmp / perl_files. The contents of this file must be placed in / tmp / files, and you must view the file and delete duplicate lines. Lines must not be repeated!
You can start creating the package. First of all, we create the “content” of the package:
# cat /tmp/files | pkgproto > /tmp/Prototype


This command will create a file / tmp / Prototype similar to this:
d none /opt 0755 root root
d none /opt/munin 0755 root root
d none /opt/munin/man 0755 root root
d none /opt/munin/man/man3 0755 root root
f none /opt/munin/man/man3/Munin::Common::TLSClient.3 0555 root root
f none /opt/munin/man/man3/Munin::Common::TLS.3 0555 root root
f none /opt/munin/man/man3/Munin::Common::Config.3 0555 root root
f none /opt/munin/man/man3/Munin::Common::Timeout.3 0555 root root
f none /opt/munin/man/man3/Munin::Common::Defaults.3 0555 root root
f none /opt/munin/man/man3/Munin::Common::TLSServer.3 0555 root root
f none /opt/munin/man/man3/Munin::Node::Config.3 0555 root root
f none /opt/munin/man/man3/Munin::Node::Server.3 0555 root root
f none /opt/munin/man/man3/Munin::Node::Service.3 0555 root root
f none /opt/munin/man/man3/Munin::Node::OS.3 0555 root root
f none /opt/munin/man/man3/Munin::Node::Configure::HostEnumeration.3 0555 root root
f none /opt/munin/man/man3/Munin::Node::Configure::PluginList.3 0555 root root
f none /opt/munin/man/man3/Munin::Node::SNMPConfig.3 0555 root root
f none /opt/munin/man/man3/Munin::Node::Session.3 0555 root root
f none /opt/munin/man/man3/Munin::Node::Logger.3 0555 root root
f none /opt/munin/man/man3/Munin::Node::Configure::Debug.3 0555 root root
f none /opt/munin/man/man3/Munin::Node::Utils.3 0555 root root
f none /opt/munin/man/man3/Munin::Node::Configure::Plugin.3 0555 root root
f none /opt/munin/man/man3/Munin::Node::Configure::History.3 0555 root root
f none /opt/munin/man/man3/Munin::Plugin::Pgsql.3 0555 root root
f none /opt/munin/man/man3/Munin::Plugin::SNMP.3 0555 root root
f none /opt/munin/man/man3/Munin::Plugin.3 0555 root root
d none /opt/munin/man/man1 0755 root rootf none /opt/munin/man/man1/munin-node.1 0555 root root
f none /opt/munin/man/man1/munin-run.1 0555 root rootf none /opt/munin/man/man1/munindoc.1 0555 root root
f none /opt/munin/man/man1/munin-node-configure.1 0555 root rootd none /opt/munin/bin 0755 root root
f none /opt/munin/bin/munindoc 0555 root rootd none /opt/munin/sbin 0755 root rootf none /opt/munin/sbin/munin-run 0555 root root
f none /opt/munin/sbin/munin-node-configure 0555 root rootf none /opt/munin/sbin/munin-node 0555 root root


If desired, you can edit the access level for each file.
Now, at the beginning of this file, you need to add a pointer to the pkginfo file, which will store information about the package. You can also add pointers to checkinstall, preinstall, and postinstall, if necessary. Short description:
  • checkinstall is used to verify before installation. Runs on behalf of nobody. This script can check dependencies or permissions on directories. If the conditions are unsatisfactory, the script will terminate the pkgadd utility.
  • preinstall is launched from root during the installation of the package. With this script, for example, you can create a user for the package to be installed. If you interrupt its execution, you will need to run pkgrm to remove the failed package installation.
  • postinstall is launched after the bulk of the package is installed. This script, for example, can create an SMF service, or display some information for the end user. A lot of options.

All of these files in our case should be in / tmp.
Pkginfo, in turn, looks like this:
PKG="Munin-node"
NAME="Munin-node 1.44"
VERSION="1.44"
ARCH="sparc"
CLASSES="none"
CATEGORY="application"
VENDOR="GNU"
PSTAMP="Creator Name"
EMAIL="Creator.Name@mail"
BASEDIR="/"


The syntax for adding pkginfo, checkinstall, preinstall and postinstall is as follows:
i pkginfo
i checkinstall
i preinstall
i postinstall


So. Configuration files are ready. You can start creating the package:
# pkgmk -o -r / -d /tmp -f Prototype


We create the package, overwriting all previous attempts (-o), using / as the root directory (-r), compile the package in / tmp using the list from the Prototype (-f) file.
Now in / tmp you can find the directory with the compiled package, not yet packaged. The directory will be named as the PKG line in the pkginfo file. All scripts, if added to Prototype, are located in the install directory. Program files are in the root directory. In the process of debugging the installation of the package, you can safely edit the contents of the files. However, it must be borne in mind that the checksum and file size may change and these changes must be reflected in the pkgmap file, otherwise the installation will fail. It’s nice that when pkgadd -d starts, the installer will indicate a mismatch in size and amount, and will certainly write the correct value.
Remained a real trifle:
# cd /tmp
# tar -cf - Munin-node | gzip -9 -c > Munin-node.1.44.SPARC.pkg.tar.gz


The resulting archive can be transferred to other servers and run the installation:
# gunzip -c Munin-node.1.44.SPARC.pkg.tar.gz | tar -xvf -
# pkgadd -d $PWD


The main part is finished.

application


Below we will give an example of a postinstall script in which the munin-node client is initially configured and a service (daemon?) Is created for munin-node.

#!/bin/sh
#
/opt/munin/sbin/munin-node-configure --shell --families=contrib,auto | sh -x
svccfg -v validate /etc/opt/munin/munin-node.xml
svccfg -v import /etc/opt/munin/munin-node.xml
svcadm disable application/munin-node
echo "Before start munin-node service DO:"
echo "1. edit munin-node.conf"
echo "2. configure dns client"
echo "3. passwd munin user"


The munin-node.xml file was created separately.
Its contents:

Тут стоит лишь обратить внимание на путь до исполнительного файла munin-node.

Файл preinstall:
#!/bin/shgroupadd munin
useradd -d /var/munin -m -s /usr/bin/bash -g munin munin
cp /.profile /var/munin/
chown munin:munin /var/munin/.profile

Also popular now: