cloudnativedaysjp / observability

0 stars 0 forks source link

Refactor co2-sensor #81

Closed faruryo closed 1 year ago

faruryo commented 1 year ago

co2-sensorのスクリプトとインストール方法を整理しました。

自動起動、自動再起動や、ログの管理面からsystemdでスクリプトを動作するようにします。

faruryo commented 1 year ago

環境変数修正とリスタートするとこんな感じになります。

observability@rasnky:~/observability/co2-sensor$ sudo systemctl edit co2-sensor
observability@rasnky:~/observability/co2-sensor$ sudo systemctl daemon-reload
observability@rasnky:~/observability/co2-sensor$ sudo systemctl restart co2-sensor.service
observability@rasnky:~/observability/co2-sensor$ sudo systemctl status co2-sensor.service
● co2-sensor.service - Measure co2 and upload data
     Loaded: loaded (/etc/systemd/system/co2-sensor.service; enabled; vendor preset: enabled)
    Drop-In: /etc/systemd/system/co2-sensor.service.d
             └─override.conf
     Active: active (running) since Sun 2022-11-13 01:27:15 JST; 1s ago
   Main PID: 7169 (python)
      Tasks: 1 (limit: 4164)
        CPU: 270ms
     CGroup: /system.slice/co2-sensor.service
             └─7169 /home/observability/observability/co2-sensor/venv/bin/python -u /home/observability/observability/co2-sensor/main.py

11月 13 01:27:15 rasnky systemd[1]: Started Measure co2 and upload data.
11月 13 01:27:15 rasnky python[7169]: PUSHGATEWAY_ADDRESS = https://pushgateway.dev.cloudnativedays.jp
11月 13 01:27:15 rasnky python[7169]: INTERVAL_SEC        = 10 second
11月 13 01:27:15 rasnky sudo[7170]:     root : PWD=/home/observability/observability/co2-sensor ; USER=root ; COMMAND=/usr/bin/systemctl stop serial-getty@serial0.service
11月 13 01:27:15 rasnky sudo[7170]: pam_unix(sudo:session): session opened for user root(uid=0) by (uid=0)
11月 13 01:27:15 rasnky sudo[7170]: pam_unix(sudo:session): session closed for user root