๐Ÿ AUTO launchd with conda virtual env

Lightmanยท2022๋…„ 8์›” 15์ผ
1

CS: PYTHON๐Ÿ & โ“‡

๋ชฉ๋ก ๋ณด๊ธฐ
5/14

๐Ÿšง๐Ÿ‘ทโ€โ™‚๏ธ๐Ÿšง๐Ÿ‘ทโ€โ™‚๏ธ๐Ÿšง๐Ÿ‘ทโ€โ™‚๏ธ๐Ÿšง๐Ÿ‘ทโ€โ™‚๏ธ๐Ÿšง๐Ÿ‘ทโ€โ™‚๏ธ๐Ÿšง๐Ÿ‘ทโ€โ™‚๏ธ๐Ÿšง๐Ÿ‘ทโ€โ™‚๏ธ๐Ÿšง๐Ÿ‘ทโ€โ™‚๏ธ๐Ÿšง

Launchd Tutorial

๊ณต์‹์‚ฌ์ดํŠธ
A Simple Launchd Tutorial

launchd

  • error01
    • ๊ฐ€์ƒํ™˜๊ฒฝ์—์„œ ์‹คํ–‰ํ•˜๊ธฐ
    • shell script๋ฅผ ์ด์šฉํ•œ๋‹ค: ์‰˜ ์Šคํฌ๋ฆฝํŠธ๋ฅผ ์ด์šฉํ•˜์—ฌ plist๋ฅผ ์ž‘์„ฑํ•˜๋Š” ๋ฐฉ๋ฒ•
  • error02
  • error03
    • [๋ฌธ์ œ1] ํŠน์ • ํด๋”์—์„œ๋Š” ๊ดœ์ฐฎ์•˜์ง€๋งŒ, ํด๋ผ์šฐ๋“œ๋กœ ๊ณต์œ ๋˜๊ณ  ์žˆ๋Š” ํด๋”์—์„œ๋Š” ์ž‘๋™ํ•˜์ง€ ์•Š๊ณ  ๋‹ค์Œ ์˜ค๋ฅ˜๋ฅผ ๋ฑ‰์Œ
      - shell-init: error retrieving current directory: getcwd: cannot access parent directories: Operation not permitted
      /bin/bash: ./launchd_test.sh: Operation not permitted
      - ํ•ด๊ฒฐ: bash์— ๊ถŒํ•œ๋ถ€์—ฌ(sh, zsh๊ฐ€ ํ•„์š”ํ• ์ˆ˜๋„)

LAUNCHD ์‹ค๋ฌด ์‚ฌ์šฉ ์‚ฌ๋ก€

  1. ํƒ€๊ฒŸํด๋” > pyํŒŒ์ผ ์ž‘์„ฑ

    title: [REF]bq_upload.py
    #! /usr/bin/env python3
  2. ํƒ€๊ฒŸํด๋” > shell ํŒŒ์ผ ์ž‘์„ฑ ๋ฐ ์‹คํ–‰(chmod +x) ๊ถŒํ•œ๋ถ€์—ฌ

    title: [REF]bq_upload.sh
    #! /bin/bash
    export PATH=/Users/mori/anaconda3/bin:/Users/mori/anaconda3/condabin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin
    
    source /Users/mori/anaconda3/etc/profile.d/conda.sh
    conda activate socar
    python [REF]bq_upload.py >> ./bq_upload.result.log
  3. ~/Library/LaunchAgents/plist ํŒŒ์ผ ์ž‘์„ฑ

    title: bq.upload.daemon.plist
    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
    <plist version="1.0">
      <dict>
    
        <key>Label</key>
        <string>bq.upload.daemon.plist</string>
    
        <key>RunAtLoad</key>
        <true/>
    
        <key>StartInterval</key>
        <integer>30</integer>
    
        <key>StandardErrorPath</key>
        <string>ํƒ€๊ฒŸํด๋”/stderr.log</string>
    
        <key>StandardOutPath</key>
        <string>ํƒ€๊ฒŸํด๋”/stdout.log</string>
    
        <key>WorkingDirectory</key>
        <string>ํƒ€๊ฒŸํด๋”</string>
    
        <key>ProgramArguments</key>
        <array>
          <string>./[REF]bq_upload.sh</string>
        </array>
    
      </dict>
    </plist>

    4.launchdctl์„ ์ด์šฉํ•˜์—ฌ launchd๋ฅผ control

    launchdctl load ~/Library/LaunchAgents/*.plist 
    launchdctl unload ~/Library/LaunchAgents/*.plist 

์˜๋ฌธ์‚ฌํ•ญ

  • conda๊ฐ€ ์ฐธ์กฐํ•˜๋Š” ํด๋”๋“ค์€ ์–ด๋””์–ด๋””์ธ์ง€? ์ €๊ฒƒ๋“ค ๊ฐ๊ฐ์ด ๋‹ค๋ฅธ ์˜๋ฏธ๊ฐ€ ์žˆ๋Š”์ง€?

LESSON LEARNED

  • ์˜์™ธ๋กœ ํด๋”๋ช…์˜ ํ•œ๊ธ€, ๋„์–ด์“ฐ๊ธฐ๋Š” ์˜ํ–ฅ์„ ์ฃผ์ง€ ์•Š์Œ

๊ธฐํƒ€๋‚ด์šฉ

  • conda์˜ ์ ˆ๋Œ€์œ„์น˜ ์ฐพ๊ธฐ: which -p conda
    what is <!CDATA>
profile
ํ˜„์ง ๋ฐ์ดํ„ฐ ๋ถ„์„๊ฐ€ / ๋ฐ์ดํ„ฐ ๊ณผํ•™์˜ ์ •๋„๋ฅผ ๋”ฐ๋ผ ๐Ÿšฒ / About DEV DA ML

0๊ฐœ์˜ ๋Œ“๊ธ€