create_service.sh 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. #!/bin/Bash
  2. #1단계 : 작업 디렉토리 & 서비스 명 받기
  3. read -p "설치된 디렉토리 (ex: /mnt/openNAMU) : " working_directory
  4. echo $working_directory
  5. read -p "원하는 서비스명 (ex: opennamu): " service_name
  6. echo $service_name
  7. read -p "설명 (ex: OpenNAMU 서비스입니다): " description
  8. echo $description
  9. read -p "로그위치 (ex: /var/log/openNAMU.log) : " log_path
  10. echo $log_path
  11. #2단계 : 파일제작
  12. cat <<EOF > /lib/systemd/system/${service_name}.service
  13. [Unit]
  14. Description=$description
  15. [Service]
  16. Type=simple
  17. WorkingDirectory=$working_directory
  18. ExecStart=/usr/bin/python3 $working_directory/app.py
  19. Restart=on-failure
  20. PIDFile=/run/$service_name.pid
  21. #rsyslog 사용
  22. #StandardOutput=syslog
  23. #StandardError=syslog
  24. #SyslogIdentifier=$service_name
  25. #systemctl 245 이후 로깅
  26. StandardOutput=append:$log_path
  27. StandardError=append:$log_path
  28. [Install]
  29. WantedBy=multi-user.target
  30. EOF
  31. #3단계 : 서비스 확인
  32. systemctl daemon-reload
  33. systemctl start $service_name
  34. systemctl status $service_name