简体   繁体   English

Capistrano重新启动Apache服务器

[英]Capistrano to restart Apache server

I'm having an issue with Capistrano and my rails application. 我在Capistrano和Rails应用程序方面遇到问题。 I have a simple rake task for my deployment: 对于部署,我有一个简单的rake任务:

 task :restart do
    on roles(:app), in: :sequence, wait: 5 do
      execute "cd #{current_path}; rake assets:precompile"
      execute "sudo service httpd restart"
    end
  end

As you can see, after all the code is uploaded I precompile my assets and attempt to restart my server. 如您所见,在上传所有代码之后,我将对资产进行预编译并尝试重新启动服务器。 For some reason this used to work fine, but now gives me as error: 出于某种原因,它过去可以正常工作,但现在却给了我错误:

DEBUG [e2f1f3dc] Command: sudo service httpd restart
DEBUG [e2f1f3dc]    sudo
DEBUG [e2f1f3dc]    : 
DEBUG [e2f1f3dc]    sorry, you must have a tty to run sudo

Any ideas how I could resolve this? 有什么想法可以解决这个问题吗?

EDIT: Just in case you were wondering, the user that capistrano is logged in as is "ec2-user" with all the defaults that amazon assigns it with. 编辑:以防万一您想知道,capistrano的用户以“ ec2-user”身份登录,亚马逊为其分配了所有默认值。

ssh to the server and then issue this command: ssh到服务器,然后发出以下命令:

visudo

Then comment out the following line: 然后注释掉以下行:

#Default requiretty

A better solution in case multiple users login to the system (bad idea, deployment systems should be managed by programs) is to disable TTY for a particular user like this: 如果多个用户登录系统(一个坏主意,部署系统应由程序管理),一个更好的解决方案是为特定用户禁用TTY,如下所示:

Defaults requiretty
Defaults:%build !requiretty
Defaults:build !requiretty

The first line makes TTY mandatory for everyone. 第一行使TTY对每个人都是强制性的。 The second and third line exclude the build group and user from this requirement respectively. 第二行和第三行分别将构建组和用户排除在此要求之外。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM