andres-montanez / Magallanes

The PHP Deployment Tool
https://magephp.com
MIT License
691 stars 169 forks source link

Fix owner from symlink release #397

Closed tislars closed 6 years ago

tislars commented 7 years ago

Our server is accessed as root, but the site folders are owned by a different user (e.g. foo.com has owner:group foo:client).

I have written the following custom task and all the content is set to the correct group and owner:

<?php
namespace Task;

use Mage\Task\AbstractTask;

class FixPermissions extends AbstractTask
{

    public function getName()
    {
        return 'custom/fix-permissions';
    }

    public function getDescription()
    {
        return 'Fixing file ownership and permissions';
    }

    public function execute()
    {
        $owner = $this->options['owner'];
        $group = $this->options['group'];

        $cmd = "chown ".$owner.":".$group." -R .";

        $process = $this->runtime->runCommand($cmd);

        return $process->isSuccessful();
    }
}

But the symlink created after deployment is root:root and I can't seem to change this to foo:client. How could this be done?

andres-montanez commented 6 years ago

Hi, the premise is that the user connecting is not root :) I understand that you may need that, in this case to change the symlink you need to pass -h to the chown command. Hope this helps!