Building Your Contrib

From SME Server
Jump to navigationJump to search

This how-to intend to give you a tour of what you need with some usefull tmeplates to build you own contrib on SME10 with last php-fpm, httpd 2.4, core backup integration and systemd usage

Warning.png Work in Progress:
Unnilennium has marked this page as a Work in Progress. The contents off this page may be in flux, please have a look at this page history the to see list of changes.


Architecture

SPEC file

%define name foo
%define version 3.6.431
%define release 1
Summary: foo is a helpdesk system
Name: %{name}
Version: %{version}
Release: %{release}%{?dist}
Distribution: SME Server
License: GNU GPL version 2
URL: http://www.fooweb.com
Group: SMEserver/addon
#wget http://www.fooweb.com/downloads/foo-3.6.431.tar.gz
Source: foo-3.6.431.tar.gz
Packager: Stephen Foo <support@foo.net>
BuildArchitectures: noarch
BuildRoot: /var/tmp/%{name}-%{version}
BuildRequires: e-smith-devtools
Requires: e-smith-release >= 7.0
AutoReqProv: no

%description
http://foo.org/
foo is a helpdesk system 

%changelog
* Thu Sep 13 2007 Stephen Foo <support@foo.net> 3.6.431-1
- initial release
- builds from unchanged .tar.gz 

%prep
%setup  -c -n %{name}

%build
perl createlink

%install
rm -rf $RPM_BUILD_ROOT
(cd root   ; find . -depth -print | cpio -dump $RPM_BUILD_ROOT)
rm -f %{name}-%{version}-filelist
/sbin/e-smith/genfilelist $RPM_BUILD_ROOT \
   --dir '/opt/foo/tempdir/' 'attr(775,www,www)' \
   --file '/opt/foo/logo.gif' 'attr(660,www,www)' \
   --ignoredir '/opt/foo' \
 --dir /var/log/foo  'attr(0755,root,root)' \
 --dir /var/log/php/foo  'attr(0755,www,www)' \
 --dir /var/lib/php/foo  'attr(0755,www,www)' \
 --dir /var/lib/php/foo/tmp 'attr(0755,www,www)' \
 --dir /var/lib/php/foo/opcache 'attr(0755,www,www)' \
 --dir /var/lib/php/foo/session 'attr(0755,www,www)' \

    > %{name}-%{version}-filelist

%clean
cd ..
rm -rf %{name}

%files -f %{name}-%{version}-filelist
%defattr(-,root,root)

Createlinks

#!/usr/bin/perl
use strict;
use esmith::Build::CreateLinks qw(:all);

my $pkg= "smeserver-foo";
my $event = "${pkg}-update";

event_actions($event, qw(
   myfoo 05
   systemd-default 88
   systemd-reload  89
));

event_templates($event, qw(
/etc/httpd/conf/httpd.conf
/etc/opt/remi/php80/php-fpm.d/www.conf
/opt/foo/foo.conf
));

event_services($event, qw(
    php80-php-fpm restart
    httpd-e-smith restart
    foo restart
));

use esmith::Build::Backup qw(:all);
backup_includes($pkg, qw(
/opt/foo/
));

Configuration DB

Mariadb myslq init

Systemd

all you need to have your service to start is

  1. a configuration db key foo of type service with status enabled
  2. a dropin file as this one

/usr/lib/systemd/system/foo.service.d/50koozali.conf

[Service]
#first we reset the ExecStartPre
ExecStartPre=
#our needs
ExecStartPre=-/sbin/e-smith/service-status foo
ExecStartPre=-/sbin/e-smith/expand-template /opt/foo/foo.conf

Restart=always
[Install]
#so it start on boot
WantedBy=sme-server.target

PHP-FPM

all you need is to add and improve this fragment .

What version of php it will be used against depends on the value you set on the line "if ($PHP_VERSION eq '80'){". This template is called for every version of php using the magic of template.metadata.

smeserver-foo-1.0/root/etc/e-smith/templates/etc/php-fpm.d/www.conf/15foo

{

if ($PHP_VERSION eq '80'){
  if (($foo{'status'} || 'disabled') eq 'enabled'){
    my $max_upload_size = ($foo{MaxUploadSize} || '4096');
    $max_upload_size .= 'M' if ($max_upload_size =~ m/^\d+$/);
    my $memory_limit = ($foo{MemoryLimit} || '500M');
    $memory_limit .= 'M' if ($memory_limit =~ m/^\d+$/);
    my $open_basedir= $foo{PHPBaseDir} || '';
    $open_basedir = "/opt/foo/html/:/var/log/foo/:/var/lib/php/foo:$open_basedir";
    my $id = 'cacti';
    my $max_children = $foo{'PHPmaxChildren'} || 20;
    my $min_spare_servers = $foo{'PHPminServers'} || 4;
    my $start_servers = $foo{'PHPstartServers'} || 6;
    my $max_spare_servers = $foo{'PHPmaxServers'} || 8;
    my $max_requests = $foo{'PHPmaxRequests'} || 1000;
    $min_spare_servers = ( $min_spare_servers > $max_spare_servers ) ? printf("%.0f",$max_spare_servers/2) : $min_spare_servers;
    $start_servers = ( $start_servers > $max_spare_servers ) ? printf("%.0f", $max_spare_servers /2 +  $min_spare_servers/2  ) : $start_servers;

    $OUT .=<<_EOF;

[php$PHP_VERSION-$id]
user = www
group = www
listen.owner = root
listen.group = www
listen.mode = 0660
listen = /var/run/php-fpm/php$PHP_VERSION-$id.sock
pm = dynamic
pm.max_children = $max_children
pm.start_servers = $start_servers
pm.min_spare_servers = $min_spare_servers
pm.max_spare_servers = $max_spare_servers
pm.max_requests = $max_requests
php_admin_value[session.save_path] = /var/lib/php/$id/session
php_admin_value[session.gc_maxlifetime] = 86400
php_admin_value[opcache.file_cache]  = /var/lib/php/$id/opcache
php_admin_value[upload_tmp_dir] = /var/lib/php/$id/tmp
php_admin_value[error_log] = /var/log/php/$id/error.log
slowlog = /var/log/php/foo/slow.log
php_admin_value[sendmail_path] = /usr/sbin/sendmail -t -i -f php@{ $DomainName }
php_admin_flag[display_errors] = off
php_admin_flag[log_errors] = on
php_admin_value[error_log] = syslog
php_admin_value[memory_limit] = $memory_limit
php_admin_value[max_execution_time] = 3600
php_admin_value[post_max_size] = $max_upload_size
php_admin_value[upload_max_filesize] = $max_upload_size
php_admin_value[disable_functions] = system, show_source, symlink, dl, passthru, phpinfo, escapeshellarg, escapeshellcmd
php_admin_value[open_basedir] = $open_basedir
php_admin_flag[allow_url_fopen] = on
php_admin_flag[file_uploads] = on
php_admin_flag[session.cookie_httponly] = on
php_admin_flag[allow_url_include] = off
php_admin_value[session.save_handler] = files
php_admin_flag[output_buffering] = off

_EOF

  }
  else{
    $OUT .= '; foo is disabled';
  }
}
}

you will also need the specific files created and accessible by www, that is done in the spec file for the permission and you need also to create them

mkdir -p smeserver-foo-1.0/root/var/lib/php/foo/{session,tmp,opcache)
mkdir -p smeserver-foo-1.0/root/var/log/php/foo
mkdir -p smeserver-foo-1.0/root/var/log/foo

Apache httpd