我在服务器中使用capistrano进行node.js部署 . 我有一个在端口8080上运行的node.js项目 . 当我转到项目目录并运行npm start时,它将开始监听http://localhost:8080,这很好 . 但是在capistrano脚本中我先写了npm install然后npm start .

deploy.rb

set :stages, ["testing", "staging", "prod_api01", "prod_api02"]
lock '3.8.0'

set :application, 'coconut'
set :repo_url, 'git@bitbucket.org:app/myapp.git'

set :tmp_url, '/tmp/temp_cap'
set :git_https_username, 'myapp-dev'

set :deployment_root_directory, '/var/www/myapp'
set :deployment_current_directory, "#{fetch(:deployment_root_directory)}/current"
set :deployment_shared_directory, "#{fetch(:deployment_root_directory)}/shared"

set :permission_method, :chmod
set :file_permissions_users, ["ubuntu"]
set :file_permission_paths, ["storage"]

set :use_composer, false
set :composer_install_flags, '--no-dev'

set :nvm_type, :user # or :system, depends on your nvm setup
set :nvm_node, 'v8.11.1'
set :nvm_map_bins, %w{node npm yarn}

# Slack
set :slack_webhook, "https://hooks.slack.com/services/T04SF0S9P/B1NPYCM0X/2"
set :slack_channel, '#myapp-dt-deployment'

set :git

# Default branch is :master
# ask :branch, `git rev-parse --abbrev-ref HEAD`.chomp

# Default deploy_to directory is /var/www/my_app_name
# set :deploy_to, '/var/www/my_app_name'

# Default value for :scm is :git
# set :scm, :git

# Default value for :format is :airbrussh.
# set :format, :airbrussh

# You can configure the Airbrussh format using :format_options.
# These are the defaults.
# set :format_options, command_output: true, log_file: 'log/capistrano.log', color: :auto, truncate: :auto

# Default value for :pty is false
# set :pty, true

# Default value for :linked_files is []
# append :linked_files, 'config/database.yml', 'config/secrets.yml'

# Default value for linked_dirs is []
# append :linked_dirs, 'log', 'tmp/pids', 'tmp/cache', 'tmp/sockets', 'public/system'

# Default value for default_env is {}
# set :default_env, { path: "/opt/ruby/bin:$PATH" }

# Default value for keep_releases is 5
set :keep_releases, 5

namespace :deploy do

    desc "***************************** Running npm install ***************************************"
    task :npm_install do
        on roles(:all) do
            within release_path do
                execute :npm, 'install'
            end
        end
    end

    desc "************************* Run the build *******************************************"
    task :build do
        on roles(:all) do
            within release_path do
                execute :npm, "run start:#{fetch(:env_built)}"
            end
        end
    end

    after :updated, :npm_install
    after :npm_install, :build

    after :restart, :clear_cache do
        on roles(:web), in: :groups, limit: 3, wait: 10 do
        end
    end

end

当我部署到测试服务器时,它将成功部署并向我显示服务器在http://localhost:8080启动的日志,但它在仍在运行的控制台中显示它,所以当我单击ctrl c它停止部署过程并显示** DEPLOY FAILED . 所以我如何开始使用capistrano部署node.js . 我的脚本有问题 .