2

I am using Drush 9 and Drupal 8. When I execute drush site:install I find that it also modifies the permission of the web/site/default directory to r-xr-x--x, which troubles me delete that directory later. I want that directory to be 740 in my case. So two methods came to my mind. One is to run a custom shell script as post drush si or to override the default dush si command. I tried to go through some blogs but I couldn't understand them. Please explain stepwise.

How can I invoke a custom shell script to drush site:install which will be run just after that command is executed.

How can I override the default site:install command?

Note: I am using Drupal composer project. So I have a drush folder outside the webroot but I don't know if I can edit some files in that directory and write my custom commands.

  • 1
    Every time the cache is cleared in Drupal and some other similar events, it will lock those folders down. – Kevin Nov 20 '18 at 21:44
  • So you mean it is not only matter of drush si but any command is executed it will modify the permission. Any way to provide my custom permission ? – SkyRar Nov 20 '18 at 21:47
  • @Kevin I examined with drush cr and cc. But It doesn't modify the permission. Only drush si does – SkyRar Nov 20 '18 at 21:54
1

See the example file PolicyCommands.php in the Druhs examples directory. Create a directory named "Commands" in your site's "drush" directory, and put your command file there. Its name must end with "Commands.php" or "Hooks.php".

Create a hook similar to one of the ones shown in the example file. You'll want @hook post-command site:install.

  • Thanks. Do I also need to define drush.yml here github.com/drupal-composer/drupal-project/tree/8.x/drush ? Is there anything I need to define or edit ? Can you please have a look on this link ? – SkyRar Nov 21 '18 at 1:34
  • For testing purpose, as per the documentation I run drush --include=/var/www/drupal/vendor/drush/drush/examples xkcd , drush cc drush, then drush xkcd, but getting error command is not defined. Am I missing something ? – SkyRar Nov 21 '18 at 3:19
  • If you put your command in /var/www/drupal/drush/Commands, then you do not need --include – greg_1_anderson Nov 22 '18 at 22:43
0

To create a site:install hook I just needed to create a file SiteInstallCommands.php inside drush/Commands dir. then drush cc drush to clear the drush cache and my custom post command is up. Thanks to @greg_1_anderson for guiding. Note you have to add @hook post-command site-install not @hook post site:install.

<?php

namespace Drush\Commands;


class InstallCommands extends DrushCommands
{

    /**
     * Modify files/directory permission as per project's need executing just after `drush site:install`
     *
     * @hook post-command site-install
     *
     */
    public function installChmod() {
        $this->logger()->success(dt('Executing post site:install commands'));
        drush_shell_exec('chmod -R 740 sites/default');

    }
}
  • 1
    Thanks for correcting my typo; I fixed my answer to "post-command" – greg_1_anderson Nov 22 '18 at 22:44

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.