Skip to content

Instantly share code, notes, and snippets.

@ksn135
Created December 13, 2014 13:25
Show Gist options
  • Save ksn135/ea1271339e393911a533 to your computer and use it in GitHub Desktop.
Save ksn135/ea1271339e393911a533 to your computer and use it in GitHub Desktop.
Task SetFaclRightsTask class implementation for Magallanes
<?php
/*
* This file is part of the informational system package.
*
* (c) Serg N. Kalachev <serg@kalachev.ru>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* Usage in your mage enviroment.yml:
*
* on-deploy:
* ...
* - setFaclRightsTask: { user: 'ksn135', www: 'www-data', dir: 'app/cache app/logs' }
* - setFaclRightsTask: { user: 'ksn135', www: 'www-data', dir: 'app/cache app/logs', default: true }
* ...
*/
namespace Task;
use Mage\Task\AbstractTask;
/**
* SetFaclRightsTask class implementation.
*
* @author Serg N. Kalachev <serg@kalachev.ru>
*/
class SetFaclRightsTask extends AbstractTask
{
public function getName()
{
$dir = $this->getParameter('dir', './app/cache ./app/logs');
return "Setting ACL to directory $dir";
}
public function run()
{
$dir = $this->getParameter('dir', './app/cache ./app/logs');
$user = $this->getParameter('user', "`whoami`");
$www = $this->getParameter('www', "`ps aux | grep -E '[a]pache|[h]ttpd|[_]www|[w]ww-data|[n]ginx' | grep -v root | head -1 | cut -d\ -f1`");
$default = $this->getParameter('default', false);
$nomask = $this->getParameter('nomask', false);
$command = "sudo setfacl -";
if ($nomask) $command .= 'n';
if ($default) $command .= 'd';
$command .= "R -m u:$www:rwX -m u:$user:rwX $dir";
$result = $this->runCommandRemote($command);
return $result;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment