Reloading php-fpm after deploy via php-deployer without password
Asked Answered
U

2

6

What I'm trying to achieve is, to reload php7.2-fpm service via php-deployer.
According to php-deployer's documentation, it can be done like the code below:

task('reload:php-fpm', function () {
    run('sudo /usr/sbin/service php7-fpm reload');
});

after('deploy', 'reload:php-fpm');

However, I face the error below while deploying:

➤ Executing task deploy:reload_php_fpm

↳ on [prod]

sudo service php7.2-fpm reload

In PhpSecLib.php line 124:
[RuntimeException]
sudo: no tty present and no askpass program specified

System info:

PHP Version 7.2
Ubuntu 18.04 LTS
PHP-Deployer Version 6.3.0

Do you have any idea how can I solve this issue?

Unexceptional answered 22/10, 2018 at 12:45 Comment(1)
does this help? appuals.com/…Corelli
U
7

After digging around, I finally found the proper answer to handle the situation. I edited /etc/sudoers file by following command:

sudo visudo

At the end of the file, I added this line:

siamak ALL=(ALL) NOPASSWD:/etc/init.d/php7.2-fpm reload

It means that, the user siamak has permission to just reload php7.2-fpm without entering password. For any other administrative tasks, siamak must enter password.

Unexceptional answered 23/10, 2018 at 8:44 Comment(0)
Q
0

Task 'cachetool:clear:opcache'

Nowadays Deployer.org has special taks for this issue:

YAML syntax:

...
after:
  deploy:failed: deploy:unlock
  deploy:cleanup: cachetool:clear:opcache

Just to add to your script after making symlink. How to use the task you can see in recipe/magento2.php script.

It's better and safer, than add deploy user to sudoers.

If you don't utilize Deployer.org - you can use lib cachetool directly: CacheTool - Manage cache in the CLI (Github)

Quechua answered 27/4 at 11:17 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.