deployer icon indicating copy to clipboard operation
deployer copied to clipboard

Detect Motd and warn users about it

Open antonmedv opened this issue 3 years ago • 9 comments

  • Deployer version: v7.0.0-beta.23
  • Deployment OS: macOS 11.3

YAML

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

config:
  application: website
  branch: main
  base_deploy_path: /srv/users/serverpilot/apps
  config_file: ~/.ssh/config
  php_fpm_service: php7.4-fpm-sp
  remote_user: serverpilot
  repository: [email protected]:user/website.git
  shared_dirs:
    - users
  ssh_multiplexing: true
  writable_dirs:
    - storage/statamic

hosts:
  production:
    deploy_path: '{{base_deploy_path}}/{{application}}'
    hostname: domain.com
  staging:
    deploy_path: '{{base_deploy_path}}/staging-{{application}}'
    hostname: staging.domain.com

tasks:
  deploy:
    - deploy:prepare
    - deploy:vendors
    - artisan:storage:link
    - artisan:view:cache
    - artisan:config:cache
    - artisan:optimize
    - npm:install
    - npm:run:production
    - please:cache:clear
    - deploy:publish
    - php-fpm:reload
  npm:run:production:
    script:
      - 'cd {{release_or_current_path}} && npm run production'
  please:assets:meta:
    script:
      - 'cd {{release_or_current_path}} && php please assets:meta'
  please:git:commit:
    script:
      - 'cd {{release_or_current_path}} && php please git:commit'
  please:glide:clear:
    script:
      - 'cd {{release_or_current_path}} && php please glide:clear'
  please:cache:clear:
    script:
      - 'cd {{release_or_current_path}} && php please cache:clear'

after:
  deploy:failed: deploy:unlock

Here is the error

[staging] run cd /srv/users/serverpilot/apps/staging-website && ([ -f /srv/users/serverpilot/apps/staging-website/.dep/repo/HEAD ] || **********************************************************************
*  Learn about SSH, SFTP, PHP, MySQL, apps, cron, and more at:       *
*  https://serverpilot.io/community/articles/system-user-guide       *
*                                                                    *
*  To use a specific PHP version for the 'php' command, see:         *
*  https://serverpilot.io/community/articles/how-to-use-the-php-cli  *
**********************************************************************
/usr/bin/git clone --mirror [email protected]:user/website.git /srv/users/serverpilot/apps/staging-website/.dep/repo 2>&1)
[staging] **********************************************************************
[staging] *  Learn about SSH, SFTP, PHP, MySQL, apps, cron, and more at:       *
[staging] *  https://serverpilot.io/community/articles/system-user-guide       *
[staging] *                                                                    *
[staging] *  To use a specific PHP version for the 'php' command, see:         *
[staging] *  https://serverpilot.io/community/articles/how-to-use-the-php-cli  *
[staging] **********************************************************************
[staging] bash: line 1: release: command not found
[staging] bash: line 2: release: command not found
[staging] bash: line 3: release: command not found
[staging] bash: line 4: release: command not found
[staging] bash: line 5: release: command not found
[staging] bash: line 6: release: command not found
[staging] bash: line 7: release: command not found

Here is the fix

  1. Edit the following file: /etc/profile.d/serverpilot-login-message.sh
  2. Delete the following lines to remove the Message of the day:
elif [[ "$HOME" == /srv/users/* ]]; then
    echo "**********************************************************************"
    echo "*  Learn about SSH, SFTP, PHP, MySQL, apps, cron, and more at:       *"
    echo "*  https://serverpilot.io/community/articles/system-user-guide       *"
    echo "*                                                                    *"
    echo "*  To use a specific PHP version for the 'php' command, see:         *"
    echo "*  https://serverpilot.io/community/articles/how-to-use-the-php-cli  *"
    echo "**********************************************************************"

Originally posted by @pryley in https://github.com/deployphp/deployer/discussions/2542

Upvote & Fund

  • We're using Polar.sh so you can upvote and help fund this issue.
  • We receive the funding once the issue is completed & confirmed by you.
  • Thank you in advance for helping prioritize & fund our backlog.
Fund with Polar

antonmedv avatar Feb 19 '22 10:02 antonmedv

I think it's not a complete solution to only warn users about it. If Motd cannot be removed from server, DeployerV7 seems to be not usable. Maybe Deployer can detect Motd and before each remote command, filter result to remove it.

MaximeOh avatar Feb 19 '22 15:02 MaximeOh

Yes, this is also possible. Let’s implement it as well. For example as configurable regexp.

antonmedv avatar Feb 19 '22 15:02 antonmedv

Configurable Regexp seems to be a good idea and the most powerful solution.

The Hostinger Motd contains static and dynamic parts.

   HHHH               HHHH
   HHHHHHHH           HHHHHHHH
   HHHHHHHH           HHHHHHHH
   HHHHHHHH           HHHHHHHH
   HHHHHHHHHHHHHHHHHHHH  HHHHH
   HHHHHHHHHHHHHHHHHHHHHHHHH
     HHHHHHHHHHHHHHHHHHHHHHHHH
   HHHH  HHHHHHHHHHHHHHHHHHHHH
   HHHHHHHH           HHHHHHHH
   HHHHHHHH           HHHHHHHH
   HHHHHHHH           HHHHHHHH
       HHHH               HHHH

Welcome back! The time now is 17:14 UTC
Server load: 15.51, 16.41, 16.67

Link to hPanel: 
https://hpanel.hostinger.com/ 

MaximeOh avatar Feb 19 '22 17:02 MaximeOh

Maybe create a list of predefined motd for popular services?

antonmedv avatar Feb 19 '22 18:02 antonmedv

Do you use ssh multiplexing?

antonmedv avatar Feb 19 '22 18:02 antonmedv

Yes, i use ssh multiplexing because it's the default value of Deployer option. But i try to deactivate it, and there is no difference.

I'm trying to deploy a classical CakePhp4 WebApp, the task tree is a basic case.

The task-tree for deploy:
└── deploy
    ├── deploy:prepare
    │   ├── deploy:info
    │   ├── deploy:setup
    │   ├── deploy:lock
    │   ├── deploy:release
    │   ├── deploy:update_code
    │   ├── deploy:shared
    │   └── deploy:writable
    ├── deploy:vendors
    ├── deploy:init
    ├── deploy:run_migrations
    └── deploy:publish
        ├── deploy:symlink
        ├── deploy:unlock
        ├── deploy:cleanup

I try each task individually until the update_code task and there is no problem with motd.

I discover deployerV7 since couple days, i use it since the V4 and next version, the motd never produce problem.

MaximeOh avatar Feb 20 '22 18:02 MaximeOh

I am running into this issue when using the test() function, it's messing up the results and returning false every time.

lfolco avatar Aug 11 '23 19:08 lfolco

We just upgraded some projects (yeah really delayed) and hit this. Oddly while the spammed MOTD over n over was annoying in older versions - it still worked.

It seems after some investigation that after this commit - https://github.com/deployphp/deployer/commit/da8bb1adffab871c94305c47d34beb10ac2c51da, it broke.

Since it would get stuck an infinite loop. I doubt I'll have any luck, but I requested our client to ask if Hostinger can remove the MOTD as its quite annoying and doesn't look configurable in my research.

   HHHH               HHHH
   HHHHHHHH           HHHHHHHH
   HHHHHHHH           HHHHHHHH
   HHHHHHHH           HHHHHHHH
   HHHHHHHHHHHHHHHHHHHH  HHHHH
   HHHHHHHHHHHHHHHHHHHHHHHHH
     HHHHHHHHHHHHHHHHHHHHHHHHH
   HHHH  HHHHHHHHHHHHHHHHHHHHH
   HHHHHHHH           HHHHHHHH
   HHHHHHHH           HHHHHHHH
   HHHHHHHH           HHHHHHHH
       HHHH               HHHH

Welcome back! The time now is 18:32 UTC
Server load: 19.28, 19.43, 20.37

Link to hPanel: 
https://hpanel.hostinger.com/ 

iBotPeaches avatar Nov 07 '23 19:11 iBotPeaches

Okay, we fixed without code changes. Explained below. In short though - I wish clients didn't use Hostinger and used a solution that is more in-tune with hosting Laravel. So with that rant out of the way.

The name of the game is setting up values ahead of time.

# You must set `git` yourself, otherwise the MOTD will meld with command and lead to crash.
set('bin/git', '/usr/bin/git');

# Hostinger default php version is 8.0, you probably don't want that.
set('bin/php', '/opt/cloudlinux/alt-php82/root/usr/bin/php');

# Hostinger default composer is composer1, wtf seriously. We must invoke composer2 with the php version we want from above
set('bin/composer', '/opt/cloudlinux/alt-php82/root/usr/bin/php /usr/local/bin/composer2');

# We must remove the login shell to hide the MOTD. This is important.
set('shell', 'bash');

# Hostinger won't allow ACL changes, use chmod
set('writable_mode', 'chmod');

# Hardcode user/group that you need because Hostinger won't expose that in ps aux
set('http_user', 'uXXX');
set('http_group', 'oXXX');

iBotPeaches avatar Nov 07 '23 23:11 iBotPeaches