Foreman hooks not working for me

Hello!

I'm struggling with hooks and the don't work for me.
CentOS7
selinux is in permissive

RELEASE: CentOS Linux release 7.1.1503 (Core)
FOREMAN: 1.8.3
RUBY: ruby 2.0.0p598 (2014-11-13) [x86_64-linux]
PUPPET:
DENIALS: 46

foreman is running through passenger

I've installed ruby193-rubygem-foreman_hooks
I've created simple sh script
find /usr/share/foreman/config/hooks/
/usr/share/foreman/config/hooks/host
/usr/share/foreman/config/hooks/host/managed
/usr/share/foreman/config/hooks/host/managed/create
/usr/share/foreman/config/hooks/host/managed/create/30_test
/usr/share/foreman/config/hooks/host/managed/destroy
/usr/share/foreman/config/hooks/host/managed/destroy/30_test
/usr/share/foreman/config/hooks/host/managed/after_commit
/usr/share/foreman/config/hooks/host/managed/after_commit/30_test
/usr/share/foreman/config/hooks/host/managed/after_build
/usr/share/foreman/config/hooks/host/managed/after_build/30_test

it's executable

ll /usr/share/foreman/config/hooks/host/managed/after_commit/30_test

-rwxr-xr-x. 1 root root 100 Aug 23 19:12
/usr/share/foreman/config/hooks/host/managed/after_commit/30_test

cat /usr/share/foreman/config/hooks/host/managed/destroy/30_test
#!/bin/sh

echo >> /tmp/hooklog
date >> /tmp/hooklog
echo 'Yay it ran!' ${1} Host: ${2} >> /tmp/hooklog
cat >> /tmp/hooklog

I've restarted apache

foreman says that it sees those hooks
tail -f /var/log/foreman/production.log | grep hook
2015-08-23 19:40:29 [I] Finished registering 1 hooks for
Host::Managed#create
2015-08-23 19:40:29 [I] Finished registering 1 hooks for
Host::Managed#destroy
2015-08-23 19:40:29 [I] Finished registering 1 hooks for
Host::Managed#after_commit
2015-08-23 19:40:29 [I] Finished registering 1 hooks for
Host::Managed#after_build

but nothing appears in /tmp/hooklog on creating or deleting hosts.

> but nothing appears in /tmp/hooklog on creating or deleting hosts.

Is 'foreman' user allowed to write into the dir/file? Haven't you
created the log file as root by chance?

··· -- Later, Lukas #lzap Zapletal

For the record, I answered this on IRC. Using /tmp in a hook on EL7
won't work as expected, since httpd has its own /tmp namespace
(PrivateTmp=true in the systemd unit). Writing logs elsewhere ought to
be visible to both httpd and your shell.

··· On 23/08/15 17:43, Александр Костырев wrote: > Hello! > > I'm struggling with hooks and the don't work for me. > CentOS7 > selinux is in permissive > > [...] > it's executable > # ll /usr/share/foreman/config/hooks/host/managed/after_commit/30_test > -rwxr-xr-x. 1 root root 100 Aug 23 19:12 > /usr/share/foreman/config/hooks/host/managed/after_commit/30_test > > cat /usr/share/foreman/config/hooks/host/managed/destroy/30_test > #!/bin/sh > > echo >> /tmp/hooklog > date >> /tmp/hooklog > echo 'Yay it ran!' ${1} Host: ${2} >> /tmp/hooklog > cat >> /tmp/hooklog


Dominic Cleal
Red Hat Engineering

Nope. I've already ruled it out.

Should I have changed shell of foreman user to /bin/bash or something?

> Should I have changed shell of foreman user to /bin/bash or something?

Nope, that's not needed. Note it's foreman-proxy user, not foreman!

Give us ls -laZ /tmp just for the record.

··· -- Later, Lukas #lzap Zapletal

> For the record, I answered this on IRC. Using /tmp in a hook on EL7
> won't work as expected, since httpd has its own /tmp namespace
> (PrivateTmp=true in the systemd unit). Writing logs elsewhere ought to
> be visible to both httpd and your shell.

Right, it happened to me as well…

··· -- Later, Lukas #lzap Zapletal