全方位
      • Sharing URL Link copied
      • /edit
      • View mode
        • Edit mode
        • View mode
        • Book mode
        • Slide mode
        Edit mode View mode Book mode Slide mode
      • Customize slides
      • Note Permission
      • Read
        • Owners
        • Signed-in users
        • Everyone
        Owners Signed-in users Everyone
      • Write
        • Owners
        • Signed-in users
        • Everyone
        Owners Signed-in users Everyone
      • Engagement control Commenting, Suggest edit, Emoji Reply
    • Invite by email
      Invitee

      This note has no invitees

    • Publish Note

      Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note No publishing access yet

      Your note will be visible on your profile and discoverable by anyone.
      Your note is now live.
      This note is visible on your profile and discoverable online.
      Everyone on the web can find and read all notes of this public team.

      Your account was recently created. Publishing will be available soon, allowing you to share notes on your public page and in search results.

      Your team account was recently created. Publishing will be available soon, allowing you to share notes on your public page and in search results.

      Explore these features while you wait
      Complete general settings
      Bookmark and like published notes
      Write a few more notes
      Complete general settings
      Write a few more notes
      See published notes
      Unpublish note
      Please check the box to agree to the Community Guidelines.
      View profile
    • Commenting
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
      • Everyone
    • Suggest edit
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
    • Emoji Reply
    • Enable
    • Versions and GitHub Sync
    • Note settings
    • Note Insights New
    • Engagement control
    • Make a copy
    • Transfer ownership
    • Delete this note
    • Insert from template
    • Import from
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
    • Export to
      • Dropbox
      • Google Drive
      • Gist
    • Download
      • Markdown
      • HTML
      • Raw HTML
Menu Note settings Note Insights Versions and GitHub Sync Sharing URL Help
Menu
Options
Engagement control Make a copy Transfer ownership Delete this note
Import from
Dropbox Google Drive Gist Clipboard
Export to
Dropbox Google Drive Gist
Download
Markdown HTML Raw HTML
Back
Sharing URL Link copied
/edit
View mode
  • Edit mode
  • View mode
  • Book mode
  • Slide mode
Edit mode View mode Book mode Slide mode
Customize slides
Note Permission
Read
Owners
  • Owners
  • Signed-in users
  • Everyone
Owners Signed-in users Everyone
Write
Owners
  • Owners
  • Signed-in users
  • Everyone
Owners Signed-in users Everyone
Engagement control Commenting, Suggest edit, Emoji Reply
  • Invite by email
    Invitee

    This note has no invitees

  • Publish Note

    Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note No publishing access yet

    Your note will be visible on your profile and discoverable by anyone.
    Your note is now live.
    This note is visible on your profile and discoverable online.
    Everyone on the web can find and read all notes of this public team.

    Your account was recently created. Publishing will be available soon, allowing you to share notes on your public page and in search results.

    Your team account was recently created. Publishing will be available soon, allowing you to share notes on your public page and in search results.

    Explore these features while you wait
    Complete general settings
    Bookmark and like published notes
    Write a few more notes
    Complete general settings
    Write a few more notes
    See published notes
    Unpublish note
    Please check the box to agree to the Community Guidelines.
    View profile
    Engagement control
    Commenting
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    • Everyone
    Suggest edit
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    Emoji Reply
    Enable
    Import from Dropbox Google Drive Gist Clipboard
       Owned this note    Owned this note      
    Published Linked with GitHub
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    --- title: '部署本機端檔案到server ' disqus: hackmd --- ###### tags: `system` 部署本機端檔案到server === [TOC] ## linux排程 crontab guru https://crontab.guru/ ## 筆記目的 了解如何部署本機端開發的應用程式到linux主機上 [何謂CICD](https://ithelp.ithome.com.tw/articles/10219083) ## 先備條件 先去下載這兩個工具 [winscp](https://winscp.net/eng/download.php) [cmder](https://cmder.net/)不需要安裝 winscp 的目的在於幫你比較容易地去複製本機端檔案到遠端的server,或是檢視server端的檔案,把他想成一種檔案管理工具 cmder 讓你在windows環境下,可以簡易的去操作linux指令 ## 總結步驟 1. 把必要的jar,token放到主機對應的folder裡面 2. 在主機的folder下 write sh 3. 該 sh 要能記錄 execution time,裡面也要有run jar 檔案的設定 service那些設定 4. 在cmder裡面可以用`crontab -e`來編輯排程方式,何時去run sh檔案 ## 會用到的指令 | 指令 | 功能 | | -------------------- | --------------------- | | `crontab -l` | 查看排程 | | `crontab -e` | 編輯排程 | | clear | clear page | | `ps -ef \| grep jar` | 查看正在運行的jar檔案 | ## 關掉排程 ![](https://i.imgur.com/5hCIKO4.png) > sudo kill -9 45319(替換成第二欄編號) ## 如何馬上runrun看 1. 先 crontab -l 2. 之後複製看看 有sh 的那行指令 ## 重要的步驟和概念 1. 要在Eclipse當中要先push最新專案到遠端的remote當中[如何使用可以看這篇](https://dotblogs.com.tw/CYLcode/2019/01/08/111851) 2. 對專案點右鍵,run as => Maven build... Goal=package ![](https://i.imgur.com/fiqkW66.png) 等它一下,接下來會在最後面出現這些資訊,裡面最重的就是有告訴你build好的jar檔案路徑放在哪裡 ``` java= [INFO] Building jar: C:\Users\TDG_USER\git\allie-google-optimize-performance-observe\target\allie-google-optimize-performance-observe-1.0.0.jar [INFO] [INFO] --- spring-boot-maven-plugin:2.5.3:repackage (repackage) @ allie-google-optimize-performance-observe --- [INFO] Replacing main artifact with repackaged archive [INFO] ------------------------------------------------------------------------ [INFO] BUILD SUCCESS [INFO] ------------------------------------------------------------------------ [INFO] Total time: 24.461 s [INFO] Finished at: 2021-08-30T14:50:39+08:00 [INFO] ------------------------------------------------------------------------ ``` ![](https://i.imgur.com/LAoMHs9.png) 3. 我們要做的事情很簡單,就是把jar檔放入遠端主機的排程當中,為此我們需要cmder的協助 首先先連線,使用ssh的方式連線 他會要你輸入帳號密碼,輸入就對了 ``` ssh mike@192.168.0.228 ``` ![](https://i.imgur.com/xJji2Ar.png) 下面的事情可以在winscp當中做完,就不需要下達linux指令 將allie-google-optimize-performance-observe-1.0.0.jar 複製到對應的資料夾 把**GoogleDriveTokens** && **GoogleSheetsTokens** 此2個資料夾必須於local環境手動產生再copy至server端,原因是google oauth認證階段的callback 路徑因為是指定localhost 因此無法正常完成認證的步驟,因此先在local環境先行認證產生出該資料夾內所需的檔案後再手動上傳至server端即可(一次性設定)。 ![](https://i.imgur.com/1iCGgsE.png) 至此在server端,你已經有了所有需要的東西,一個jar檔案 接著就是想辦法去寫排程 排程的作業大概分成兩塊 4-1. 寫一個sh檔案,可以用記事本編輯,然後儲存成**sh檔案**內容為以下內容,這個檔案會先移動到放入jar檔的資料夾,之後紀錄啟動時間,最後編寫**如何運行**jar檔的參數 ```bash cd /Users/mike/AllieGoogleOptimizePerformanceObserve_Gap date >> /Users/mike/AllieGoogleOptimizePerformanceObserve_Gap/execution.txt echo 'run service' >> /Users/mike/AllieGoogleOptimizePerformanceObserve_Gap/execution.txt java -jar -Dspring.profiles.active=prod -Dservice.properties.source=gap /Users/mike/AllieGoogleOptimizePerformanceObserve_Gap/allie-google-optimize-performance-observe-1.0.0.jar --SERVICE=AI_CAMPAIGN_UPDATE_SPREADSHEET_SERVICE exit 0; ``` 4-2. 在cmder的介面當中,下達如何排程的指令,何時,比如說幾小時,這裡我下達的指令會運行第一個步驟製造的sh檔案,並且告訴你**何時**運行該sh檔案 使用`crontab -e`便可以編輯它,之後要按鍵盤上的**insert按鍵才能真正的編輯**,想要離開或是**存檔**的時候就使用 `esc :wq`這樣就可以離開 write and quite ```bash= #-------Backup crontab---------- 29 * * * * crontab -l > /Users/mike/Crontab_Backup/crontab_setting_228.txt #--------------------------------AI Support System----------------------------------------- 55 0-23/2 * * * sh /Users/mike/AllieGoogleOptimizePerformanceObserve/execute_allie-google-optimize-performance-observe-admin.sh 45 0-23/2 * * * sh /Users/mike/AllieGoogleOptimizePerformanceObserve_Gap/execute_allie-google-optimize-performance-observe-gap.sh ``` ## 部署完成後 請記得一定要run run看,不是部署完了之後,人就跑了!要注意的事情是run的時候,要確保主機沒有剛好在排程的時候run ```shell sh /Users/mike/AllieGoogleOptimizePerformanceObserve/execute_allie-google-optimize-performance-observe-admin.sh ``` > sh +檔案路徑 > 這樣就會直接執行我們編輯好的sh檔案 ## 要注意的地方 兩個資料夾的sh不能一樣,因為一個是給gap看的,一個是給老師看的,sh裡面有不同的設定 ## 一定要進去到最裡面才能去下指令測試 ``` APOCde-Mac-mini:Google-Account-Budget-contract-Annual-Consumption-Statistics mike$ pwd /Users/mike/Google-Account-Budget-contract-Annual-Consumption-Statistics ``` > 善用pwd指令來去看現在的目錄在哪裡,另外善用winscp的重新整理,確認目前資料夾的狀況 ## 可能會有的bug [No compiler is provided in this environment. Perhaps you are running on a JRE rather than a JDK?](https://blog.csdn.net/hjwang1/article/details/50085839) 解法很簡單 把運行環境改成jdk,這個錯誤的原因是因為預設我們在jre環境運行,但是打包的時候需要變成jdk,所以就一勞永逸的把它換成jdk吧 ![](https://i.imgur.com/BANYSG4.png) ## 部署切換log4j的紀錄檔案路徑 ```java= #-----------------YahooGeminiSystem----------------------------- 50 02,08,14,17 * * * java -Dlogging.config=classpath:log4j2_AdvertiserInfo_AccountService.properties -jar /home/mike/YahooAdsAPICenter/YahooAdsApiClientLibraryCenterApplication.jar AdvertiserInfo_AccountService ALLCID 50 03,09,15,18 * * * java -Dlogging.config=classpath:log4j2_AdvertiserInfo_CampaignService.properties -jar /home/mike/YahooAdsAPICenter/YahooAdsApiClientLibraryCenterApplication.jar AdvertiserInfo_CampaignService ALLCID 00 06,15 * * * java -Dlogging.config=classpath:log4j2_Performance_Daily_AccountService.properties -jar /home/mike/YahooAdsAPICenter/YahooAdsApiClientLibraryCenterApplication.jar Performance_Daily_AccountService ALLCID 10 06,15 * * * java -Dlogging.config=classpath:log4j2_Performance_Daily_CampaignService.properties -jar /home/mike/YahooAdsAPICenter/YahooAdsApiClientLibraryCenterApplication.jar Performance_Daily_CampaignService ALLCID 20 06,15 * * * java -Dlogging.config=classpath:log4j2_Performance_Daily_AdGroupService.properties -jar /home/mike/YahooAdsAPICenter/YahooAdsApiClientLibraryCenterApplication.jar Performance_Daily_AdGroupService ALLCID 30 06 * * * java -Dlogging.config=classpath:log4j2_Performance_Daily_AdService.properties -jar /home/mike/YahooAdsAPICenter/YahooAdsApiClientLibraryCenterApplication.jar Performance_Daily_AdService ALLCID 30 07,16 * * * java -Dlogging.config=classpath:log4j2_ConversionRule_Daily_AccountService.properties -jar /home/mike/YahooAdsAPICenter/YahooAdsApiClientLibraryCenterApplication.jar ConversionRule_Daily_AccountService ALLCID 30 04 * * * java -Dlogging.config=classpath:log4j2_AdvertiserInfo_AdgroupService.properties -jar /home/mike/YahooAdsAPICenter/YahooAdsApiClientLibraryCenterApplication.jar AdvertiserInfo_AdgroupService ALLCID 20 03 * * * java -Dlogging.config=classpath:log4j2_AdvertiserInfo_AdService.properties -jar /home/mike/YahooAdsAPICenter/YahooAdsApiClientLibraryCenterApplication.jar AdvertiserInfo_AdService ALLCID 45 07 * * * java -Dlogging.config=classpath:log4j2_ConversionRule_Daily_AdgroupService.properties -jar /home/mike/YahooAdsAPICenter/YahooAdsApiClientLibraryCenterApplication.jar ConversionRule_Daily_AdgroupService ALLCID ``` log4j2.properties ``` name=PropertiesConfig property.filename=logs appenders=console, rolling # rootLogger rootLogger.level=info rootLogger.appenderRef.stdout.ref=Stdout rootLogger.appenderRef.rolling.ref=InfoRollingFile # console appender.console.type=Console appender.console.name=Stdout appender.console.layout.type=PatternLayout appender.console.layout.pattern=%highlight{%d{yyyy-MM-dd HH:mm:ss.SSS} [%5p] [%40.40c{1.}:%3L] - %m%n}{FATAL=white, ERROR=red, WARN=blue, INFO=Green, DEBUG=Yellow, TRACE=blue} # rolling file appender.rolling.type=RollingFile appender.rolling.name=InfoRollingFile # spring.http.log-request-details=false #Local #appender.rolling.fileName=D://Local Develop Systems//GoogleAdsAPICenter//logs//GoogleAdsApiClientLibraryCenterApplication.log #appender.rolling.filePattern=D://Local Develop Systems//GoogleAdsAPICenter//logs//GoogleAdsApiClientLibraryCenterApplication_%d{yyyy-MM-dd}_%i.log #Production appender.rolling.fileName=/home/mike/YahooAdsAPICenter/logs/YahooAdsApiClientLibraryCenterApplication.log appender.rolling.filePattern=/home/mike/YahooAdsAPICenter/logs/YahooAdsApiClientLibraryCenterApplication_%d{yyyy-MM-dd}_%i.log appender.rolling.layout.type=PatternLayout appender.rolling.layout.pattern=%highlight{%d{yyyy-MM-dd HH:mm:ss.SSS} [%5p] [%40.40c{1.}:%3L] - %m%n}{FATAL=white, ERROR=red, WARN=blue, INFO=Green, DEBUG=Yellow, TRACE=blue} appender.rolling.policies.type=Policies appender.rolling.policies.time.type=TimeBasedTriggeringPolicy appender.rolling.policies.time.interval=1 appender.rolling.policies.time.modulate=true appender.rolling.policies.size.type=SizeBasedTriggeringPolicy appender.rolling.policies.size.size=60M appender.rolling.strategy.type=DefaultRolloverStrategy appender.rolling.strategy.max=100 ``` log4j2_ConversionRule_Daily_AdgroupService.properties ```java= name=PropertiesConfig property.filename=logs appenders=console, rolling # rootLogger rootLogger.level=info rootLogger.appenderRef.stdout.ref=Stdout rootLogger.appenderRef.rolling.ref=InfoRollingFile # console appender.console.type=Console appender.console.name=Stdout appender.console.layout.type=PatternLayout appender.console.layout.pattern=%highlight{%d{yyyy-MM-dd HH:mm:ss.SSS} [%5p] [%40.40c{1.}:%3L] - %m%n}{FATAL=white, ERROR=red, WARN=blue, INFO=Green, DEBUG=Yellow, TRACE=blue} # rolling file appender.rolling.type=RollingFile appender.rolling.name=InfoRollingFile # spring.http.log-request-details=false #Production appender.rolling.fileName=/home/mike/YahooAdsAPICenter/logs/ConversionRule_Daily_AdgroupService.log appender.rolling.filePattern=/home/mike/YahooAdsAPICenter/logs/ConversionRule_Daily_AdgroupService_%d{yyyy-MM-dd}_%i.log appender.rolling.layout.type=PatternLayout appender.rolling.layout.pattern=%highlight{%d{yyyy-MM-dd HH:mm:ss.SSS} [%5p] [%40.40c{1.}:%3L] - %m%n}{FATAL=white, ERROR=red, WARN=blue, INFO=Green, DEBUG=Yellow, TRACE=blue} appender.rolling.policies.type=Policies appender.rolling.policies.time.type=TimeBasedTriggeringPolicy appender.rolling.policies.time.interval=1 appender.rolling.policies.time.modulate=true appender.rolling.policies.size.type=SizeBasedTriggeringPolicy appender.rolling.policies.size.size=60M appender.rolling.strategy.type=DefaultRolloverStrategy appender.rolling.strategy.max=100 ```

    Import from clipboard

    Paste your markdown or webpage here...

    Advanced permission required

    Your current role can only read. Ask the system administrator to acquire write and comment permission.

    This team is disabled

    Sorry, this team is disabled. You can't edit this note.

    This note is locked

    Sorry, only owner can edit this note.

    Reach the limit

    Sorry, you've reached the max length this note can be.
    Please reduce the content or divide it to more notes, thank you!

    Import from Gist

    Import from Snippet

    or

    Export to Snippet

    Are you sure?

    Do you really want to delete this note?
    All users will lose their connection.

    Create a note from template

    Create a note from template

    Oops...
    This template has been removed or transferred.
    Upgrade
    All
    • All
    • Team
    No template.

    Create a template

    Upgrade

    Delete template

    Do you really want to delete this template?
    Turn this template into a regular note and keep its content, versions, and comments.

    This page need refresh

    You have an incompatible client version.
    Refresh to update.
    New version available!
    See releases notes here
    Refresh to enjoy new features.
    Your user state has changed.
    Refresh to load new user state.

    Sign in

    Forgot password
    or
    Sign in via Facebook Sign in via X(Twitter) Sign in via GitHub Sign in via Dropbox Sign in with Wallet
    Wallet ( )
    Connect another wallet

    New to HackMD? Sign up

    By signing in, you agree to our terms of service.

    Help

    • English
    • 中文
    • Français
    • Deutsch
    • 日本語
    • Español
    • Català
    • Ελληνικά
    • Português
    • italiano
    • Türkçe
    • Русский
    • Nederlands
    • hrvatski jezik
    • język polski
    • Українська
    • हिन्दी
    • svenska
    • Esperanto
    • dansk

    Documents

    Help & Tutorial

    How to use Book mode

    Slide Example

    API Docs

    Edit in VSCode

    Install browser extension

    Contacts

    Feedback

    Discord

    Send us email

    Resources

    Releases

    Pricing

    Blog

    Policy

    Terms

    Privacy

    Cheatsheet

    Syntax Example Reference
    # Header Header 基本排版
    - Unordered List
    • Unordered List
    1. Ordered List
    1. Ordered List
    - [ ] Todo List
    • Todo List
    > Blockquote
    Blockquote
    **Bold font** Bold font
    *Italics font* Italics font
    ~~Strikethrough~~ Strikethrough
    19^th^ 19th
    H~2~O H2O
    ++Inserted text++ Inserted text
    ==Marked text== Marked text
    [link text](https:// "title") Link
    ![image alt](https:// "title") Image
    `Code` Code 在筆記中貼入程式碼
    ```javascript
    var i = 0;
    ```
    var i = 0;
    :smile: :smile: Emoji list
    {%youtube youtube_id %} Externals
    $L^aT_eX$ LaTeX
    :::info
    This is a alert area.
    :::

    This is a alert area.

    Versions and GitHub Sync
    Get Full History Access

    • Edit version name
    • Delete

    revision author avatar     named on  

    More Less

    Note content is identical to the latest version.
    Compare
      Choose a version
      No search result
      Version not found
    Sign in to link this note to GitHub
    Learn more
    This note is not linked with GitHub
     

    Feedback

    Submission failed, please try again

    Thanks for your support.

    On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?

    Please give us some advice and help us improve HackMD.

     

    Thanks for your feedback

    Remove version name

    Do you want to remove this version name and description?

    Transfer ownership

    Transfer to
      Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

        Link with GitHub

        Please authorize HackMD on GitHub
        • Please sign in to GitHub and install the HackMD app on your GitHub repo.
        • HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.
        Learn more  Sign in to GitHub

        Push the note to GitHub Push to GitHub Pull a file from GitHub

          Authorize again
         

        Choose which file to push to

        Select repo
        Refresh Authorize more repos
        Select branch
        Select file
        Select branch
        Choose version(s) to push
        • Save a new version and push
        • Choose from existing versions
        Include title and tags
        Available push count

        Pull from GitHub

         
        File from GitHub
        File from HackMD

        GitHub Link Settings

        File linked

        Linked by
        File path
        Last synced branch
        Available push count

        Danger Zone

        Unlink
        You will no longer receive notification when GitHub file changes after unlink.

        Syncing

        Push failed

        Push successfully