728x90
* 배경
프로세스로 실행하는 기능들을 서비스화 시켜서 stop, start 가 가능하도록 하고싶다
* 자동화 보고서를 생성하는 Allure를 서비스화 하는 과정
1. /Library/LaunchAgents에 서비스 파일을 생성
vi /Library/LaunchAgents/com.allure.server.plist
2. 서비스의 config를 생성
<?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>RunAtLoad</key>
<true/>
<key>Label</key>
<string>com.allure.server</string>
<key>ProgramArguments</key>
<array>
<string>/opt/homebrew/bin/allure</string>
<string>serve</string>
<string>파일 위치</string>
<string>--port</string>
<string>포트번호</string>
</array>
<key>StandardErrorPath</key>
<string>/tmp/test-err.log</string>
<key>StandardOutPath</key>
<string>/tmp/test-out.log</string>
</dict>
</plist>
- 서비스가 죽으면 자동으로 실행되게 하고자할 경우 아래 옵션 추가
<key>KeepAlive</key>
<true />
3. 서비스 등록
launchctl load /Library/LaunchAgents/com.allure.server.plist
4. 서비스 시작
launchctl start com.allure.server
- 서비스가 시작되지 않을 경우 서비스 상태 파악
launchctl list | grep allure
- status가 78 일 경우 config의 해당 부분의 문제일 가능성이 있음 (/tmp 폴더의 권한 문제)
<key>StandardErrorPath</key>
<string>/tmp/test-err.log</string>
<key>StandardOutPath</key>
<string>/tmp/test-out.log</string>
5. 서비스 중지
launchctl stop com.allure.server
6. 서비스 삭제
launchctl unload /Library/LaunchAgents/com.allure.server.plist
위의 방법으로 다른 프로세스도 서비스화가 가능함