bestlong 怕失憶筆記

當健忘由隨機逐漸趨向常態時,作筆記是非常必要的

docker: invalid restart policy unless-stopped.

在執行 docker run 啟動容器有使用到 –restart=unless-stopped 參數,結果得到 docker: invalid restart policy unless-stopped. 的錯誤訊息。

請先用 docker version 確認版本,因為 unless stopped restart policy 是到 1.9.0 版才新加入。舊版 docker 環境可以改回用 always policy 繞過問題。

Leave a Comment

在 mac 環境安裝 JDK 6

雖然 JDK 已經演進到 8 的版本,還是會有有需要用到舊版的狀況。

而 Java SE Development Kit 6 在 Oracle 官方沒有直接提供給 mac 用的版本,需要到 Apple 網站下載

請開啟瀏覽器開啟連結到 https://developer.apple.com/download/more/

需要用到 Applie ID 帳號登入

mac-install-jdk6_1

進入畫面後在左側搜尋框查詢 Java

mac-install-jdk6_2

然後展開最新的 Developer Package 就可以看到 dmg 得下載連結

mac-install-jdk6_3

下載後直接安裝就完成 JDK 6 的安裝。

Leave a Comment

ECShop 解決在新版 PHP 環境會有 Deprecated: preg_replace(): The /e modifier is deprecated 問題

ECShop 改版的速度算是滿落後的,PHP 的都推進到第 7 版本了。所以很多函式基於安全性或其他問題都要被改換掉,只要將 PHP 錯誤報告開到 DEBUG 等級就可以看到一堆警示。不過看起來 ECShop 到 PHP 5.6 版環境都還可以運行。所以有能力的話可以自行解決,至少可以讓開發環境在做修改時能減少這些雜訊與寫入 SSD 的次數。

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in cls_template.php XXX line

以下列出我有修改的部分:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
<?php //cls_template.php
//-- 原本
return preg_replace("/{([^\}\{\n]*)}/e", "\$this->select('\\1');", $source);
//-- 修改成
return preg_replace_callback("/{([^\}\{\n]*)}/", function($r) { return $this->select($r[1]); }, $source);

//-- 原本
$val = preg_replace("/\[([^\[\]]*)\]/eis", "'.'.str_replace('$','\$','\\1')", $val);
//-- 修改成
$val = preg_replace_callback("/\[([^\[\]]*)\]/is", function($r) { return '.'.$r[1]; }, $val);

//-- 原本
$out = "<?php \n" . '$k = ' . preg_replace("/(\'\\$[^,]+)/e" , "stripslashes(trim('\\1','\''));", var_export($t, true)) . ";\n";
//-- 修改成
$out = "<?php \n" . '$k = ' . preg_replace_callback("/(\'\\$[^,]+)/" , function($r) { return stripslashes(trim($r[1],'\'')); }, var_export($t, true)) . ";\n";

//--- 原本
$pattern     = '/<!--\s#BeginLibraryItem\s"\/(.*?)"\s-->.*?<!--\s#EndLibraryItem\s-->/se';
$replacement = "'{include file='.strtolower('\\1'). '}'";
$source      = preg_replace($pattern, $replacement, $source);
//--- 修改成
$pattern     = '/<!--\s#BeginLibraryItem\s"\/(.*?)"\s-->.*?<!--\s#EndLibraryItem\s-->/s';
$replacement = function ($r) { return '{include file='.strtolower($r[1]). '}'; };
$source      = preg_replace_callback($pattern, $replacement, $source);

Leave a Comment

‘vagrant up’ fails to mount linked directory /vagrant

在 vagrant 啟動 CentOS 6 的 VM 時,忽然出現了無法掛載 /vagrant 目錄的錯誤訊息:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
$ vagrant up
Bringing machine 'default' up with 'virtualbox' provider...
==> default: Checking if box 'chef/centos-6.6' is up to date...
==> default: Clearing any previously set forwarded ports...
==> default: Clearing any previously set network interfaces...
==> default: Preparing network interfaces based on configuration...
    default: Adapter 1: nat
==> default: Forwarding ports...
    default: 80 => 8080 (adapter 1)
    default: 22 => 2222 (adapter 1)
==> default: Booting VM...
==> default: Waiting for machine to boot. This may take a few minutes...
    default: SSH address: 127.0.0.1:2222
    default: SSH username: vagrant
    default: SSH auth method: private key
    default: Warning: Connection timeout. Retrying...
    default: Warning: Remote connection disconnect. Retrying...
    default: Warning: Remote connection disconnect. Retrying...
==> default: Machine booted and ready!
==> default: Checking for guest additions in VM...
==> default: Mounting shared folders...
    default: /vagrant => /Users/bestlong/projects/vagrant_vms/chef-centos-66
Failed to mount folders in Linux guest. This is usually because
the "vboxsf" file system is not available. Please verify that
the guest additions are properly installed in the guest and
can work properly. The command attempted was:

mount -t vboxsf -o uid=<code>id -u vagrant

,gid=

1
getent group vagrant | cut -d: -f3

vagrant /vagrant
mount -t vboxsf -o uid=

1
id -u vagrant

,gid=

1
id -g vagrant

vagrant /vagrant

The error output from the last command was:

/sbin/mount.vboxsf: mounting failed with the error: No such device

這是因為在 Guest os 環境內有執行系統更新,因為更新的範圍有包含到 kernal 的部分,所以造成 VirtualBox 的系統工具程式就出問題了。

這時只需要重新安裝一次 VirtualBox Guest Additions kernel modules 應該就可以解決,首先要確認相關的套件都有安裝免得編譯失敗,請執行下列指令:

1
2
[root@localhost ~]# yum update -y
[root@localhost ~]# yum install kernel-devel-$(uname -r) kernel-headers-$(uname -r) dkms -y

再來就是安裝 VirtualBox Guest Additions kernel modules

1
2
3
4
5
6
7
[root@localhost ~]# /etc/init.d/vboxadd setup
Removing existing VirtualBox DKMS kernel modules           [  OK  ]
Removing existing VirtualBox non-DKMS kernel modules       [  OK  ]
Building the VirtualBox Guest Additions kernel modules     [  OK  ]
Doing non-kernel setup of the Guest Additions              [  OK  ]
Starting the VirtualBox Guest Additions                    [  OK  ]
[root@localhost ~]#

再來就可以重新啟動 Guest OS 確認啟動過程,應該就可以正常掛載 /vagrant 目錄了。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
$ vagrant reload
==> default: Attempting graceful shutdown of VM...
==> default: Checking if box 'chef/centos-6.6' is up to date...
==> default: Clearing any previously set forwarded ports...
==> default: Clearing any previously set network interfaces...
==> default: Preparing network interfaces based on configuration...
    default: Adapter 1: nat
==> default: Forwarding ports...
    default: 80 => 8080 (adapter 1)
    default: 22 => 2222 (adapter 1)
==> default: Booting VM...
==> default: Waiting for machine to boot. This may take a few minutes...
    default: SSH address: 127.0.0.1:2222
    default: SSH username: vagrant
    default: SSH auth method: private key
    default: Warning: Connection timeout. Retrying...
    default: Warning: Remote connection disconnect. Retrying...
==> default: Machine booted and ready!
==> default: Checking for guest additions in VM...
==> default: Mounting shared folders...
    default: /vagrant => /Users/bestlong/projects/vagrant_vms/chef-centos-66
==> default: Machine already provisioned. Run <code>vagrant provision

or use the

1
--provision

==> default: to force provisioning. Provisioners marked to run always will still run.

參考資料

https://github.com/mitchellh/vagrant/issues/1657

Leave a Comment

error closing pipe: Bad file descriptor at /usr/lib/git-core/git-svn line 0.

在 ubuntu 14.04 x86_64 環境下將早期使用 subversion 作版本管理的程式專案移轉到 git 時碰到的錯誤訊息

查了網路上有很多資訊,有提到很多可能因素,例如:記憶體不足,或者是 ulimit 的限制…等,但怎麼調整都沒有排除掉錯誤。直到看到有人提到 git version, svn version, 32 bit or 64 bit, Perl version 都是可能原因時,就直接找另一台 CentOS 6.6 x86_64 環境的主機跑看看,還真的就順利過關。

因為是一次性的作業,在更換環境後可以達成目的就不深入研究錯誤原因了。

Leave a Comment

  • 工商服務

    廣告讀取中...
  • 近期迴響

  • 標籤

  • 彙整