juli3nk / csf-post-docker

CSF with support for Docker
56 stars 34 forks source link

Adds path to binaries to fix error in script on upgrade/reboot. #3

Closed ddrager closed 8 years ago

ddrager commented 8 years ago

csf does not apparently include $PATH when running it's pre and post scripts natively. According to the readme.txt, Note: You MUST use the full path to any binaries that you execute within these scripts. Therefore, this script for docker works great when installing or restarting csf from command line, but it is broken again when csf upgrades automatically or system is rebooted. This pull request adds the full path to binaries.

Possibly this can be improved by using 'which' to find the path, but I wasn't sure if it always resides at /bin/which or if this differs on distributions.

ghost commented 8 years ago

Thank you for your PR

How about setting PATH variable instead of specifying the 3 variables?

DOCKER_DIR="/bin" IPTABLES_DIR="/sbin" SYS_DIR="/usr/bin"

instead

PATH="/bin:/sbin:/usr/bin:/usr/sbin/usr/local/bin"

ddrager commented 8 years ago

This might be a good solution, but I am not really sure how csf handles the path dirs internally. It's possible it runs the commands outside of bash which is why there is no path. The readme.txt implicitly states that you should have absolute paths on the binaries in the pre and post scripts, which is why I went that way instead of defining a path.

ghost commented 8 years ago

it's run from the perl script csf.pl

if (-e "/usr/local/csf/bin/csfpost.sh") {
        print "Running /usr/local/csf/bin/csfpost.sh\n";
        &syscommand(__LINE__,"/bin/sh /usr/local/csf/bin/csfpost.sh");
}
elsif (-e "/etc/csf/csfpost.sh") {
        print "Running /etc/csf/csfpost.sh\n";
        &syscommand(__LINE__,"/bin/sh /etc/csf/csfpost.sh");
}

It would be like this

ghost commented 8 years ago

4 is merged.