Skip to content

Zeroplex 生活隨筆

軟體開發、伺服器和生活瑣事

小 縮小字型大小。 中 重設字型大小。 大 放大字型大小。

年份: 2019 年

Deploy to AWS EC2 via Rsync

Posted on 2019 年 5 月 27 日2021 年 3 月 12 日 By 日落 在〈Deploy to AWS EC2 via Rsync〉中尚無留言

今天嘗試讓 Bitbucket 的 Pipeline 測試完畢以後,自動部屬到 EC2 上。

遇到幾個有點頭大的問題:

  • EC2 只要 restart 後 IP 都會改變
  • RSync based 在 SSH 上,所以再次連線都會有 hand shake 問題 (known_hosts)
  • 要連上 EC2 需要 ssh -i my.PEM,把這個 PEM 塞進 Pipeline 或是參數都是好方法
這幾點先不考慮的時候,pipeline script 大概會長這樣:

    - step:
        name: Deploy to EC2
        deployment: test
        caches:
        script:
            - apt-get update && apt-get install -y zip unzip rsync openssh-client ssh
            - rm -fr .git vendor
            - curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
            - composer --version
            - composer install --no-interaction --no-progress --prefer-dist --no-dev
            - chmod 600 u18-micro.pem
            - echo '|1|gdwZ6TN1l9.............GOqLzzpGY=' > ${HOME}/.ssh/known_hosts
            - rsync -av --delete --force --progress -e "ssh -i my-ec2.pem" ./ ubuntu@${Host}:/var/www/

注意紅色標記的地方,這幾個都是很重要的 key,把這些資料放在 script、git repository 都是很糟糕的方法。

繼續找方法解決這些鳥問題。

Tags:AWS, EC2

UbuntuMate 18.04 無法鎖定畫面

Posted on 2019 年 5 月 23 日2021 年 3 月 12 日 By 日落 在〈UbuntuMate 18.04 無法鎖定畫面〉中尚無留言

開機後突然沒有辦法使用快速鍵「Ctrl + Alt + L」來鎖定畫面,覺得很不對對勁。

網路上看了幾篇文章以後,發現螢幕鎖定和 gnome 的 screen saver 都有關係,由於 UbuntuMate 的預設不是使用 gnome,所以找到的是 mate-screensaver-command:

$ mate-screensaver-command -h
Usage:
  mate-screensaver-command [OPTION…]

Help Options:
  -h, --help                 Show help options

Application Options:
  --exit                     Causes the screensaver to exit gracefully
  -q, --query                Query the state of the screensaver
  -t, --time                 Query the length of time the screensaver has been active
  -l, --lock                 Tells the running screensaver process to lock the screen immediately
  -c, --cycle                If the screensaver is active then switch to another graphics demo
  -a, --activate             Turn the screensaver on (blank the screen)
  -d, --deactivate           If the screensaver is active then deactivate it (un-blank the screen)
  -p, --poke                 Poke the running screensaver to simulate user activity
  -i, --inhibit              Inhibit the screensaver from activating.  Command blocks while inhibit is active.
  -n, --application-name     The calling application that is inhibiting the screensaver
  -r, --reason               The reason for inhibiting the screensaver
  -V, --version              Version of this application

由於之前腦包把 background daemon 關掉,所以螢幕保護服務沒有啟動,不管怎麼下指令都不會有反應。記得「啟動應用程式」中,把「螢幕保護程式」開啟,以免部份功能失效:

Tags:Linux

GNU grep 的 exit code 會因結果而不同

Posted on 2019 年 5 月 7 日2021 年 3 月 12 日 By 日落 在〈GNU grep 的 exit code 會因結果而不同〉中尚無留言

昨天寫了類似以下這樣一段 script:

#!/usr/bin/env bash

set -e

R=`ls /dev/ | grep sd`

echo "Results found:"
echo $R

照理來說,不管 grep 是有有撈到資料,至少會印出「Results found」字樣,但實際執行時卻什麼資料都沒有輸出。

後來使用「bash -xv」來執行,監視值流程,才發現 script 執行到一半就中斷了:

$ bash -xv qwe.sh 
#!/usr/bin/env bash

set -e
+ set -e

R=`ls /dev/ | grep sd`
++ ls /dev/
++ grep sd
+ R=

追蹤後發現二個結果交互影響導致 script 中斷:

  • set -e 的設定
  • grep 的 exit code

在 bash 中「set -e」代表遇到錯誤立即中斷執行;而 grep 的 exit code 比較令人意外,當 grep 有找到資料時,則 exit code 為 0 (正常結束),若 grep 都沒有找到指定的字串,則會回傳 1 (錯誤)。這二件事情同時發生,所以就導致了上面的 script 在 grep 執行後就中斷執行。

// ——

shell script 好像沒什麼 debug 的工具,不過在執行時可以透過 bash 的參數,來提供執行時的一些狀態,例如: -xv。

Tags:Bash, Linux

在 bash 看指令執行後的 exit status code

Posted on 2019 年 5 月 6 日2021 年 3 月 12 日 By 日落 在〈在 bash 看指令執行後的 exit status code〉中尚無留言

老題目了,做個筆記。

Linux 底下,所有程式、指令結束都會有個 exit code,有點像是執行成功、或失敗的狀態。一般來說,正常執行的 exit code 都會是 0。

如果要看前一個指令執行後的 exit code,可以使用「echo $?」來看:

$ cd .
$ echo $?
0
$ mkdir app
mkdir: cannot create directory ‘app’: File exists
echo $?
1
Tags:Bash, Linux

幾個清空 docker 資料的好用指定

Posted on 2019 年 5 月 3 日2021 年 3 月 12 日 By 日落 在〈幾個清空 docker 資料的好用指定〉中尚無留言

中斷所有正在運作的 container:

docker kill $(docker ps -q)

刪除所有已中止的 container:

docker rm $(docker ps -a -q)

刪除所有的 images:

docker rmi $(docker images -q)

節錄自:Top 10 Docker CLI commands you can’t live without

Tags:Docker, Linux

文章分頁

上一頁 1 ... 5 6 7 8 下一頁

其他

關於我  (About me)

  文章 RSS Feed

  留言 RSS Feed

Apache AWS Bash C/C++ Docker FreeBSD GCP Git Google Java JavaScript Laravel Linux Microsoft MSSQL MySQL Nginx PHP PHPUnit PostgreSQL Python Qt Ubuntu Unix Vim Web Windows WordPress XD 作業系統 分享 好站推薦 專題 攝影 新奇搞笑 新聞 旅遊 生活雜記 程式設計 網路架站 網頁設計 資訊學習 資訊安全 遊戲 音樂


創用 CC 授權條款
本著作係採用創用 CC 姓名標示-相同方式分享 4.0 國際 授權條款授權.