RPM: building proctitle for PHP

Sometimes it’s convenient to change PHP script name, it allows to check if it’s running by typing just pstree. You can perform that with use of proctitle. Unfortunately there is no rpm for this package for Fedora 15. So to use it you need to build it. Firstly you need to download source package to your rpmbuild/SOURCES directory.  Put this spec file to SPECS:

%define modname proctitle
%global php_apiver %((echo 0; php -i 2>/dev/null | sed -n 's/^PHP API => //p') | tail -1)
%global php_extdir %(php-config --extension-dir 2>/dev/null || echo "undefined")
%global php_version %(php-config --version 2>/dev/null || echo 0)
Name: php-pecl-proctitle
Version: 0.1.1
Release: 1%{?dist}
Summary: Allows setting the current process name on Linux and BSD
Group: Development/Languages
License: PHP
URL: http://pecl.php.net/package/proctitle
Source0: http://pecl.php.net/get/proctitle-0.1.1.tgz
Source1: %{modname}.ini
BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-buildroot
BuildRequires: php-devel
Requires: php(zend-abi) = %{php_zend_api}
Requires: php(api) = %{php_apiver}
%description
This extension allows changing the current process' name on Linux and *BSD systems. This is useful when using pcntl_fork() to identify running processes in process list.
%prep
%setup -n -q %{modname}-%{version}
[ "../package.xml" != "/" ] && mv ../package.xml .
cp %{SOURCE1} %{}
find . -type d -exec chmod 755 {} ;
find . -type f -exec chmod 644 {} ;
%build
%{_bindir}/phpize
%configure
make %{?_smp_mflags}
%install
rm -rf $RPM_BUILD_ROOT
make install INSTALL_ROOT=$RPM_BUILD_ROOT
# install configuration
%{__mkdir} -p $RPM_BUILD_ROOT%{_sysconfdir}/php.d
%{__cp} %{SOURCE1} $RPM_BUILD_ROOT%{_sysconfdir}/php.d/
%clean
rm -rf $RPM_BUILD_ROOT
%files
%defattr(-,root,root,-)
%doc LICENSE README package*.xml
%config(noreplace) %{_sysconfdir}/php.d/%{modname}.ini
%{php_extdir}/proctitle.so

Run rpmbuild:

[builder@playground BUILD]$ rpmbuild -ba ../SPECS/php-pecl-proctitle.spec

After it finishes you will get built rpm:

[builder@playground rpmbuild]$ rpm -qpl RPMS/x86_64/php-pecl-proctitle-0.1.1-1.fc15.x86_64.rpm
/etc/php.d/proctitle.ini
/usr/lib64/php/modules/proctitle.so
/usr/share/doc/php-pecl-proctitle-0.1.1
/usr/share/doc/php-pecl-proctitle-0.1.1/LICENSE
/usr/share/doc/php-pecl-proctitle-0.1.1/README
/usr/share/doc/php-pecl-proctitle-0.1.1/package.xml
[builder@playground rpmbuild]$

Create test file:

<?php setproctitle("myscript"); sleep(60); ?>

And check:

[web@playground ~]$ ps axu | grep m[y]
builder 28272 1.3 1.1 387524 11720 pts/2 S+ 07:39 0:00 myscript
[web@playground ~]$

Didn’t find the answer to your question? Ask it our administrators to reply we will publish on website.

Leave a Reply

Your email address will not be published. Required fields are marked *