본문 바로가기

Linux_ubuntu

파이썬 코드 우분투 시작 프로그램 등록

 

 

라즈베리파이용 status_log 파이썬 코드

60초마다 라즈베리파이의 UPS 전압, 충전량, CPU온도를 mysql에 저장하는 파이썬 코드 smbus, pymysql 필요 smbus 설치 sudo apt-get install i2c-tools python3-smbus venv 구성 및 pymysql 설치 sudo apt-get in..

geagolas.tistory.com

위의 파이썬 코드를 우분투 시작 시 자동 실행 되도록 설정

 

service 파일 작성

sudo vim /etc/systemd/system/ups_status.service
[Unit]
Description=ups status log
After=multi-user.target				

[Service]
Type=idle
PermissionsStartOnly=true
WorkingDirectory=/home/geagolas
ExecStart=nohup /usr/bin/python3 -u /home/geagolas/.ups_status.py
StandardOutput=file:/home/geagolas/log/ups_status.log
StandardError=file:/home/geagolas/log/ups_status_err.log
Restart=on-failure

[Install]
WantedBy=multi-user.target
 

Systemd: Service File Examples - ShellHacks

Example of how to create a systemd service file to run some script on boot and how to restart systemd without reboot to reload unit files and enable a new service.

www.shellhacks.com

 

sevice mount & check status

sudo systemctl daemon-reload
sudo systemctl enable ups_status.service
sudo systemctl restart ups_status.service
systemctl status ups_status

 

'Linux_ubuntu' 카테고리의 다른 글

우분투 서버_설치 프로그램 리스트  (0) 2022.05.14
라즈베리파이에 우분투 서버 설치  (0) 2022.05.14
MyCli Error  (0) 2022.04.21