How to set config=value in php.ini with Puppet? - configuration

I'm doing my first steps in Puppet and ran into a problem. I've installed PHP on a Linux server and I want to do some slightly changes to php.ini file. I don't want to overwrite the whole ini file with one from repository, just change/create one simple config value.
I want to ensure, that the property upload_max_filesize in php.ini has the value of 10M.
How can I achieve this?

My preferred option would be to leave php.ini alone, and have puppet create a file in php's conf.d directory to override the values you want to change.
The less changes you make to php.ini, the easier it is to see what's going on when you need to merge your changes with the package providers changes when you upgrade php.ini in future.
file {'/etc/php5/conf.d/upload_limits.conf':
ensure => present,
owner => root, group => root, mode => 444,
content => "post_max_size = 10M \nupload_max_filesize = 10M \n",
}

There's basically 3 options:
Use augeas support in puppet (you'll need the ruby augeas libraries installed) like:
augeas { "php.ini":
notify => Service[httpd],
require => Package[php],
context => "/files/etc/php.ini/PHP",
changes => [
"set post_max_size 10M",
"set upload_max_filesize 10M",
];
}
You can use "augtool ls /files/etc/php.ini" to see the sections to understand how augeas is parsing the file and use that to work out the paths you need.
You can use an exec. Something like:
define set_php_var($value) {
exec { "sed -i 's/^;*[[:space:]]*$name[[:space:]]*=.*$/$name = $value/g' /etc/php.ini":
unless => "grep -xqe '$name[[:space:]]*=[[:space:]]*$value' -- /etc/php.ini",
path => "/bin:/usr/bin",
require => Package[php],
notify => Service[httpd];
}
}
set_php_var {
"post_max_size": value => '10M';
"upload_max_filesize": value => '10M';
}
Unfortunately, this solution doesn't understand the sections in php.ini, so adding a variable that's not already there would require extra effort. This will do the wrong thing if a variable appears in more than one section (but examples I'm looking at appear to have all unique variable names). This should work for a variable that's present but commented-out with a semi-colon.
Copy the original php.ini file into your puppet repository and use file with source => 'puppet:///...' or content => template(...) to replace the file entirely, as you indicated you would prefer not to do.

You could also use the file_line resource found in the stdlib module.
file_line{ 'php_upload_max_filesize':
path => '/path/to/php.ini',
line => "upload_max_filesize = 10M",
}
Since this will append the line to the file if one exactly matching it does not exist, and since the last instance of a config value takes precedence over those earlier in the file it will work. This is how I do it when i only have a couple things to change.

An alternative approach, if you're using Apache as your web server, is to set the php variable in your Apache virtualhost file (which will probably be somewhere in your Puppet manifests directory).
For example:
<VirtualHost *:80>
ServerName app.dev
DocumentRoot /srv/app/public
## etc...
php_value upload_max_filesize 10M
</VirtualHost>
This doesn't actually change php.ini, but - depending on your set-up - may be a simple way of achieving the same effect.

Related

Mysql header not found even if is in a nonstandard location

I follow the basically solutions to solve it, but I already had the problem.
In my configure.ac file I have a check for mysql:
AC_CHECK_HEADER([mysql/mysql.h], ,AC_MSG_ERROR([Could not find mysql headers !]))
and of course it complain because, as explain here:
If the header files are installed in a nonstandard location, such as
/opt/include, and CPPFLAGS doesn't refer to that directory-for
example, as -I/opt/include-the AC_CHECK_HEADER macro will fail, even
though the files do exist on the system. However, this is an issue for
the system's administrator. Part of the convenience of autoconf is
that you, as the developer, don't need to worry about these details.
So, as developer, what's the way to go to solve it properly ?
I also put the path of real location in Makefile with -I/usr/include/mysql, but it continues to complain.
EDIT: as suggestd I post the configure.ac (the main parts):
useMysql=no
AC_MSG_CHECKING([whether to use mysql])
AC_ARG_ENABLE(mysql,
[ --enable-mysql Enable mysql support],
[MYSQL="$enableval"]
useMysql=yes,
[MYSQL="no"]
)
AC_MSG_RESULT([$MYSQL])
AC_SUBST([MYSQL])
[...]
if test "$MYSQL" = "yes"; then
AC_CHECKING([for MYSQL Library and Header files])
AC_CHECK_HEADER([mysql/mysql.h], ,AC_MSG_ERROR([Could not find mysql headers !]))
AC_CHECK_LIB(mysqlclient, mysql_init, [ MYSQL_LIBS="-lmysqlclient" ], [AC_MSG_ERROR([$PACKAGE_NAME requires but cannot find mysqlclient])])
AC_DEFINE(USE_MYSQL, 1, [Use MYSQL library])
AC_SUBST(MYSQL_LIBS)
fi
then I use the MYSQL_LIBS in the Makefile:
AM_CFLAGS = -g -fPIC -rdynamic -I$(top_srcdir)/include -I/usr/include/mysql

mysql - set ~/.my.cnf location?

Is it possible to specify which .my.cnf file mysql client should use? I have 2 mysql instances running on different ports and want to only need to specify a filename with credentials.
As documented under Command-Line Options that Affect Option-File Handling:
When specifying file names, you should avoid the use of the “~” shell metacharacter because it might not be interpreted as you expect.
--defaults-extra-file=file_name
Read this option file after the global option file but (on Unix) before the user option file. If the file does not exist or is otherwise inaccessible, the program exits with an error. file_name is interpreted relative to the current directory if given as a relative path name rather than a full path name.
--defaults-file=file_name
Use only the given option file. If the file does not exist or is otherwise inaccessible, the program exits with an error. file_name is interpreted relative to the current directory if given as a relative path name rather than a full path name.
--defaults-group-suffix=str
If this option is given, the program reads not only its usual option groups, but also groups with the usual names and a suffix of str. For example, the mysql client normally reads the [client] and [mysql] groups. If the --defaults-group-suffix=_other option is given, mysql also reads the [client_other] and [mysql_other] groups.
Note that "to work properly, each of these options must be given before other options".

Changing directory with perl's TokeParser

How can I change the directory TokeParser looks when opening a file for parsing (e.g. adding a directory before $htmlFileName)?
my $p = HTML::TokeParser->new($htmlFileName);
To change the directory in Perl :
chdir($dir);
perldoc said :
chdir EXPR
chdir FILEHANDLE
chdir DIRHANDLE
chdir Changes the working directory to EXPR, if possible. If EXPR is omitted, changes to the directory specified by $ENV{HOME}, if set; if not, changes to the directory specified by
$ENV{LOGDIR}. (Under VMS, the variable $ENV{SYS$LOGIN} is also checked, and used if it is set.) If neither is set, "chdir" does nothing. It returns true on success, false
otherwise. See the example under "die".
On systems that support fchdir(2), you may pass a filehandle or directory handle as the argument. On systems that don't support fchdir(2), passing handles raises an exception.
NOTE
another solution is to put the full path in $htmlFileName
my $p = HTML::TokeParser->new("/foo/bar/$htmlFileName")
or die $!;

dpkg-shlibdeps: error: no dependency information found for

I'm compiling a deb package and when I run dpkg-buildpackage I get:
dpkg-shlibdeps: error: no dependency information found for /usr/local/lib/libopencv_highgui.so.2.3
...
make: *** [binary-arch] Error 2
This happens because I installed the dependency manually. I know that the problem will be fixed if I install the dependency (or use checkinstall), and I want to generate the package anyway because I'm not interested on dependency checking. I know that I can give to dpkg-shlibdeps the option --ignore-missing-info which prevents a fail if dependency information can't be found. But I don't know how to pass this option to dpkg-shlibdeps since I'm using dpkg-buildpackage and dpkg-buildpackage calls dpkg-shlibdeps...
I have already tried:
sudo dpkg-buildpackage -rfakeroot -d -B
And with:
export DEB_DH_MAKESHLIBS_ARG=--ignore-missing-info
as root.
Any ideas?
use:
override_dh_shlibdeps:
dh_shlibdeps --dpkg-shlibdeps-params=--ignore-missing-info
if your rule file hasn't the dh_shlibdeps call in it. That's usually the case if you've
%:
dh $#
as only rule in it ... in above you must use a tab and not spaces in front of the dh_shlibdeps
If you want it to just ignore that flag, change the debian/rules line from:
dh_shlibdeps
to:
dh_shlibdeps --dpkg-shlibdeps-params=--ignore-missing-info
Yet another way, without modifying build scripts, just creating one file.
You can specify local shlib overrides by creating debian/shlibs.local with the following format: library-name soname-version dependencies
For example, given the following (trimmed) ldd /path/to/binary output
libevent-2.0.so.5 => /usr/lib/libevent-2.0.so.5 (0x00007fc9e47aa000)
libgcrypt.so.20 => /usr/lib/libgcrypt.so.20 (0x00007fc9e4161000)
libpthread.so.0 => /usr/lib/libpthread.so.0 (0x00007fc9e3b1a000)
The contents of debian/shlibs.local would be:
libevent-2.0 5 libevent-2.0
libgcrypt 20 libgcrypt
libpthread 0 libpthread
The "dependencies" list (third column) doesn't need to be 100% accurate - I just use the library name itself again.
Of course this isn't needed in a sane debian system which has this stuff defined in /var/lib/dpkg/info (which can be used as inspiration for these overrides). Mine isn't a sane debian system.
Instead of merely ignoring the error, you might also want to fix the source of the error, which is usually either a missing or an incorrect package.shlibs or package.symbols file in package which contains the shared library triggering the error.
[1] documents how dpkg-shlibdeps uses the package.shlibs resp. package.symbols, files, [2] documents the format of the package.shlibs and package.symbols files.
[1] https://manpages.debian.org/jessie/dpkg-dev/dpkg-shlibdeps.1.en.html
[2] https://www.debian.org/doc/debian-policy/ch-sharedlibs.html
You've just misspelled your export. It should be like this:
export DEB_DH_SHLIBDEPS_ARGS_ALL=--dpkg-shlibdeps-params=--ignore-missing-info
dpkg-buildpackage uses make to process debian/rules. in this process, dpkg-buildpackage it might call dpkg-shlibdeps.
thus, the proper way to pass modify a part of the package building process is to edit debian/rules.
it's hard to give you any more hints, without seeing the actual debian/rules.
Finally I did it in the brute way:
I edited the script /usr/bin/dpkg-shlibdeps, changing this :
my $ignore_missing_info = 0;
to
my $ignore_missing_info = 1;
You can use this:
dh_makeshlibs -a -n
exactly after dh_install

Templating MySQL's my.cnf for setup in Puppet

I have been tasked with templating MySQL's my.cnf in an attempt standardize the configuration amongst the slave databases using Puppet. Right now, I'm targeting the innodb settings.
Are there configuration options that can safely be calculated against hardware specifications such as memory, disk and procs?
You need facter.
puppet:/etc/puppet/modules/master/lib/facter$ cat disks.rb
#!/usr/bin/ruby
#require 'facter'
mount = `/bin/mount`
disks=Array.new
mount.split("\n").each_with_index { | disk,i |
unless disk.scan(/ext3|simfs|reiserfs|xfs/).empty?
d=disk.split[2]
disks.push d
disks.push ','
end
}
Facter.add('disks') do
setcode do
disks
end
end
`
and in puppet.pp i use facts $disks
#add disk check to zabbix
exec { "create_host":
command => "/bin/echo $fqdn $ipaddress $disks | do_work",
require => File["/root/ticket"],
subscribe => File["/root/ticket"],
refreshonly => true,
}
see "Adding Custom Facts to Facter" on puppet labs.
I'd be tempted to move the calculations into the erb file, for example the key_buffer_size is recommended to be set to 1/4 of the Systems RAM:
set-variable = key_buffer_size=<%= (memorysize.split(' ')[0].to_i * 1024) / 4 -%>M
there is no reason why you couldn't work on other variables available from Facter (number of processors etc) and come up with your own calculations to set other variables as above.
Remember ERB effectively provides a subset of Ruby so almost anything you can do in Ruby can be done in ERB.
puppet have the erb template, erb template can use the facter value ,like hostname or memor. and you can write you self facter shell script.