Opsworks 自定义厨师食谱上的 Codeigniter ci_sessions
Posted
技术标签:
【中文标题】Opsworks 自定义厨师食谱上的 Codeigniter ci_sessions【英文标题】:Codeigniter ci_sessions on Opsworks Custom Chef Recipies 【发布时间】:2015-11-24 01:35:29 【问题描述】:我是 Codeigniter 开发人员,是 AWS OpsWorks 的新手。我已经成功创建了一个来自AWS-getting started with db recipies 的database.php 文件。
现在我面临在数据库中创建 ci_sessions 表的问题。请参考以下错误日志。
================================================================================
Error executing action `run` on resource 'execute[mysql-create-table]'
================================================================================
Mixlib::ShellOut::ShellCommandFailed
------------------------------------
Expected process to exit with [0], but received '1'
---- Begin output of /usr/bin/mysql -uroot -pbulkhouse vendor_data -e'CREATE TABLE ci_sessions(
session_id INT UNSIGNED NOT NULL AUTO_INCREMENT,
ip_address VARCHAR(63) NOT NULL,
user_agent VARCHAR(63) NOT NULL,
last_activity INT(10) UNSIGNED NOT NULL,
user_agent TEXT NOT NULL,
PRIMARY KEY (session_id),
KEY last_activity_idx (last_activity)
) ----
STDOUT:
STDERR: sh: -c: line 0: unexpected EOF while looking for matching `''
sh: -c: line 9: syntax error: unexpected end of file
---- End output of /usr/bin/mysql -uroot -pbulkhouse vendor_data -e'CREATE TABLE ci_sessions(
session_id INT UNSIGNED NOT NULL AUTO_INCREMENT,
ip_address VARCHAR(63) NOT NULL,
user_agent VARCHAR(63) NOT NULL,
last_activity INT(10) UNSIGNED NOT NULL,
user_agent TEXT NOT NULL,
PRIMARY KEY (session_id),
KEY last_activity_idx (last_activity)
) ----
Ran /usr/bin/mysql -uroot -pbulkhouse vendor_data -e'CREATE TABLE ci_sessions(
session_id INT UNSIGNED NOT NULL AUTO_INCREMENT,
ip_address VARCHAR(63) NOT NULL,
user_agent VARCHAR(63) NOT NULL,
last_activity INT(10) UNSIGNED NOT NULL,
user_agent TEXT NOT NULL,
PRIMARY KEY (session_id),
KEY last_activity_idx (last_activity)
) returned 1
Resource Declaration:
---------------------
# In /var/lib/aws/opsworks/cache.stage2/cookbooks/phpapp/recipes/dbsetup.rb
2: execute "mysql-create-table" do
3: command "/usr/bin/mysql -u#deploy[:database][:username] -p#deploy[:database][:password] #deploy[:database][:database] -e'CREATE TABLE #node[:phpapp][:dbtable](
4: session_id INT UNSIGNED NOT NULL AUTO_INCREMENT,
5: ip_address VARCHAR(63) NOT NULL,
6: user_agent VARCHAR(63) NOT NULL,
7: last_activity INT(10) UNSIGNED NOT NULL,
8: user_agent TEXT NOT NULL,
9: PRIMARY KEY (session_id),
10: KEY last_activity_idx (last_activity)
11: )"
12: not_if "/usr/bin/mysql -u#deploy[:database][:username] -p#deploy[:database][:password] #deploy[:database][:database] -e'SHOW TABLES' | grep #node[:phpapp][:dbtable]"
13: action :run
14: end
15: end
Compiled Resource:
------------------
# Declared in /var/lib/aws/opsworks/cache.stage2/cookbooks/phpapp/recipes/dbsetup.rb:2:in `block in from_file'
execute("mysql-create-table") do
action [:run]
retries 0
retry_delay 2
command "/usr/bin/mysql -uroot -pbulkhouse vendor_data -e'CREATE TABLE ci_sessions(\n session_id INT UNSIGNED NOT NULL AUTO_INCREMENT,\n ip_address VARCHAR(63) NOT NULL,\n user_agent VARCHAR(63) NOT NULL,\n last_activity INT(10) UNSIGNED NOT NULL,\n user_agent TEXT NOT NULL,\n PRIMARY KEY (session_id),\n KEY last_activity_idx (last_activity)\n )"
backup 5
returns 0
cookbook_name "phpapp"
recipe_name "dbsetup"
not_if "/usr/bin/mysql -uroot -pbulkhouse vendor_data -e'SHOW TABLES' | grep ci_sessions"
end
[2015-08-29T13:57:47+00:00] INFO: Running queued delayed notifications before re-raising exception
[2015-08-29T13:57:47+00:00] INFO: template[mysql configuration] sending restart action to service[mysql] (delayed)
[2015-08-29T13:57:47+00:00] INFO: Processing service[mysql] action restart (mysql::server line 44)
[2015-08-29T13:57:51+00:00] INFO: service[mysql] restarted
[2015-08-29T13:57:51+00:00] ERROR: Running exception handlers
[2015-08-29T13:57:51+00:00] ERROR: Exception handlers complete
[2015-08-29T13:57:51+00:00] FATAL: Stacktrace dumped to /var/lib/aws/opsworks/cache.stage2/chef-stacktrace.out
[2015-08-29T13:57:51+00:00] ERROR: execute[mysql-create-table] (phpapp::dbsetup line 2) had an error: Mixlib::ShellOut::ShellCommandFailed: Expected process to exit with [0], but received '1'
---- Begin output of /usr/bin/mysql -uroot -pbulkhouse vendor_data -e'CREATE TABLE ci_sessions(
session_id INT UNSIGNED NOT NULL AUTO_INCREMENT,
ip_address VARCHAR(63) NOT NULL,
user_agent VARCHAR(63) NOT NULL,
last_activity INT(10) UNSIGNED NOT NULL,
user_agent TEXT NOT NULL,
PRIMARY KEY (session_id),
KEY last_activity_idx (last_activity)
) ----
STDOUT:
STDERR: sh: -c: line 0: unexpected EOF while looking for matching `''
sh: -c: line 9: syntax error: unexpected end of file
---- End output of /usr/bin/mysql -uroot -pbulkhouse vendor_data -e'CREATE TABLE ci_sessions(
session_id INT UNSIGNED NOT NULL AUTO_INCREMENT,
ip_address VARCHAR(63) NOT NULL,
user_agent VARCHAR(63) NOT NULL,
last_activity INT(10) UNSIGNED NOT NULL,
user_agent TEXT NOT NULL,
PRIMARY KEY (session_id),
KEY last_activity_idx (last_activity)
) ----
Ran /usr/bin/mysql -uroot -pbulkhouse vendor_data -e'CREATE TABLE ci_sessions(
session_id INT UNSIGNED NOT NULL AUTO_INCREMENT,
ip_address VARCHAR(63) NOT NULL,
user_agent VARCHAR(63) NOT NULL,
last_activity INT(10) UNSIGNED NOT NULL,
user_agent TEXT NOT NULL,
PRIMARY KEY (session_id),
KEY last_activity_idx (last_activity)
) returned 1
[2015-08-29T13:57:51+00:00] FATAL: Chef::Exceptions::ChildConvergeError: Chef run process exited unsuccessfully (exit code 1)
我创建的食谱如下所示
node[:deploy].each do |app_name, deploy|
execute "mysql-create-table" do
command "/usr/bin/mysql -u#deploy[:database][:username] -p#deploy[:database][:password] #deploy[:database][:database] -e'CREATE TABLE #node[:phpapp][:dbtable](
session_id INT UNSIGNED NOT NULL AUTO_INCREMENT,
ip_address VARCHAR(63) NOT NULL,
user_agent VARCHAR(63) NOT NULL,
last_activity INT(10) UNSIGNED NOT NULL,
user_agent TEXT NOT NULL,
PRIMARY KEY (session_id),
KEY last_activity_idx (last_activity)
)"
not_if "/usr/bin/mysql -u#deploy[:database][:username] -p#deploy[:database][:password] #deploy[:database][:database] -e'SHOW TABLES' | grep #node[:phpapp][:dbtable]"
action :run
end
end
提前致谢
【问题讨论】:
【参考方案1】:您的 SQL 查询需要在双引号之前有一个单引号。请看下文。试试
node[:deploy].each do |app_name, deploy|
execute "mysql-create-table" do
command "/usr/bin/mysql -u#deploy[:database][:username] -p#deploy[:database][:password] #deploy[:database][:database] -e'CREATE TABLE #node[:phpapp][:dbtable](
session_id INT UNSIGNED NOT NULL AUTO_INCREMENT,
ip_address VARCHAR(63) NOT NULL,
user_agent VARCHAR(63) NOT NULL,
last_activity INT(10) UNSIGNED NOT NULL,
user_agent TEXT NOT NULL,
PRIMARY KEY (session_id),
KEY last_activity_idx (last_activity)
)'" # <-- ADD A SINGLE QUOTATION BEFORE THIS DOUBLE QUOTATION
not_if "/usr/bin/mysql -u#deploy[:database][:username] -p#deploy[:database][:password] #deploy[:database][:database] -e'SHOW TABLES' | grep #node[:phpapp][:dbtable]"
action :run
end
end
【讨论】:
以上是关于Opsworks 自定义厨师食谱上的 Codeigniter ci_sessions的主要内容,如果未能解决你的问题,请参考以下文章