Skip to content

Deployer 7 on Laravel Forge ttyname failed: Inappropriate ioctl for device #2857

@jasperf

Description

@jasperf

Seems the latest deploy failed on ttyname failed: Inappropriate ioctl for device:

[staging] warning Avoid reloading php-fpm [ï.at/avoid-php-fpm-reloading]
[staging]  error  in php-fpm.php on line 49:
[staging] run sudo systemctl reload php8.0-fpm
[staging] err mesg: ttyname failed: Inappropriate ioctl for device
[staging] err sudo: no tty present and no askpass program specified
[staging] exit code 1 (General error)
task deploy:failed
task deploy:unlock

Any ideas how it could fail?

Here our yaml file

import:
  - recipe/laravel.php
  - contrib/php-fpm.php
  - contrib/npm.php

config:
  application: 'site-app'
  remote_user: forge
  deploy_path: '~/{{hostname}}'
  repository: 'git@github.com:app/site-app.git'
  php_fpm_version: '8.0'
  keep_releases: '10'
  shared_files: 
    - '.env'
    - '.transip_private_key'
    - 'storage/app/exact.api.json'
  shared_dirs:
    - 'bootstrap/cache'
    - 'public/uploads'
    - 'public/published'
    - 'storage/framework/cache'
    - 'storage/framework/sessions'
    - 'storage/framework/views'
    - 'storage/logs'
    - 'storage/tls'
    - 'storage/app/public'
    - 'storage/app/modules'
  writable_dirs:
    - 'public/uploads'
    - 'public/published'
    - 'storage/framework/cache/data'
    - 'storage/logs'
    - 'storage/tls'
    - 'storage/app/public'
    - 'storage/app/modules'

hosts:
  prod:
    hostname: 'app.com'
  staging:
    hostname: 'staging.app.com'

tasks:
  deploy:
    - deploy:prepare
    - deploy:vendors
    - artisan:storage:link
    - artisan:view:cache
    - artisan:config:cache
    - artisan:optimize
    - artisan:migrate
    - artisan:queue:restart    
    - artisan:horizon:terminate
    - deploy:publish

after:
  deploy:symlink: php-fpm:reload
  deploy:failed: deploy:unlock

Did see we had

# Allow members of group sudo to execute any command
%sudo   ALL=(ALL:ALL) ALL

forge ALL = NOPASSWD: /etc/init.d/nginx
forge ALL = NOPASSWD: /etc/init.d/php7.4-fpm restart
# See sudoers(5) for more information on "#include" directives:

#includedir /etc/sudoers.d

So updated to 8.0 and reran the script but no success as of yet. sudo systemctl reload php8.0-fpm on the server did work as said.

Command failure

Command ran from this PHP FPM file in Deployer:

....
## Configuration
- `php_fpm_version` – The PHP-fpm version. For example: `8.0`.
- `php_fpm_service` – The full name of the PHP-fpm service. Defaults to `php{{php_fpm_version}}-fpm`.
- `php_fpm_command` – The command to run to reload PHP-fpm. Defaults to `sudo systemctl reload {{php_fpm_service}}`.
## Usage
Start by explicitely providing the current version of PHP-version using the `php_fpm_version`.
Alternatively, you may use any of the options above to configure how PHP-fpm should reload.
Then, add the `php-fpm:reload` task at the end of your deployments by using the `after` method like so.
php
set('php_fpm_version', '8.0');
after('deploy', 'php-fpm:reload');

 */
namespace Deployer;

set('php_fpm_version', function () {
    return run('php -r "printf(\'%d.%d\', PHP_MAJOR_VERSION, PHP_MINOR_VERSION)"');
});
set('php_fpm_service', 'php{{php_fpm_version}}-fpm');
set('php_fpm_command', 'sudo systemctl reload {{php_fpm_service}}');

desc('Reloads the php-fpm service');
task('php-fpm:reload', function () {
    warning('Avoid reloading php-fpm [ï.at/avoid-php-fpm-reloading]');
    run('{{php_fpm_command}}');
});
...

It failed at php_fpm_command so it ran sudo systemctl reload {{php_fpm_service}} or sudo systemctl reload php8.0-fpm and on server I also ran sudo systemctl reload php8.0-fpm so... what is the issue?

New Custom Command?

I had

run('sudo /etc/init.d/php8.0-fpm restart'); // Using SysV Init scripts

for PHP command before. Perhaps we need this yaml style somehow.However, reading https://askubuntu.com/questions/911525/difference-between-systemctl-init-d-and-service (systemctl vs init.d) it seems like what I have should work?!

Forge recommends using echo "" | sudo -S service php8.0-fpm reload https://forge.laravel.com/docs/1.0/servers/cookbook.html#restarting-php-fpm to do sudoless reloading. But this does not solve the ioctl issue. Sudoless reloading has been added to visudo already..

Did echo "" | sudo -S service php8.0-fpm reload do even avoid needing the visudo change, but this also did not help.

Added

forge ALL = NOPASSWD: /bin/systemctl reload php-fpm-8.0

to visudo and tested as well. Did not help either

Git TTY and Github check

Using git_tty: true did not work and

forge@app-staging:~$ ssh -T git@github.com
Hi jasperf! You've successfully authenticated, but GitHub does not provide shell access.

so Github connection works. Also root profile seems to be fine on the server as well:

cat /root/.profile 
# ~/.profile: executed by Bourne-compatible login shells.

if [ "$BASH" ]; then
  if [ -f ~/.bashrc ]; then
    . ~/.bashrc
  fi
fi

mesg n || true

and an update with code suggested at https://programmerah.com/linux-error-ttyname-failed-inappropriate-ioctl-for-device-solution-2134/ to deal with tty issues like this does not seem to help.

So still no clue what I am missing and how to deal with

task php-fpm:reload
[staging] warning Avoid reloading php-fpm [ï.at/avoid-php-fpm-reloading]
[staging]  error  in php-fpm.php on line 49:
[staging] run sudo systemctl reload php8.0-fpm
[staging] err mesg: ttyname failed: Inappropriate ioctl for device
[staging] err sudo: no tty present and no askpass program specified
[staging] exit code 1 (General error)
task deploy:failed

Originally posted by @jasperf in #2856

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions