[LINUX] I made a daemon with Python

I made a daemon with Python, so a memo of the procedure

environment

environment version
OS 2020-05-27-raspios-buster-arm64
Python 3.7.3
python3-systemd 234-2+b1

What i did

  1. Install python-systemd
  2. sudo apt-get install python-systemd python3-systemd
  3. Create ~ / foo.py with the following contents
from systemd import journal
journal.send('Hello world')
journal.send('Hello, again, world', FIELD2='Greetings!', FIELD3='Guten tag')
journal.send('Binary message', BINARY=b'\xde\xad\xbe\xef')
  1. Grant execute permission
  2. chmod 755 ~/foo.py
  3. Create a systemd definition file as follows
  4. Write the following content as sudo nano /etc/systemd/system/foo.service
[Unit]
Description = Foo

[Service]
ExecStart = python3 /home/pi/foo.py
Restart = always
Type = simple

[Install]
WantedBy = multi-user.target
  1. Enable the daemon
  2. sudo systemctl enable foo.service
  3. Start the daemon
  4. sudo systemctl start foo.service
  5. View the journal
  6. systemctl status roomenv.service
  7. Success if some log comes out
  8. If you write sudo in ʻExecStart`, it will not work (it seems to work with root privileges)

Recommended Posts

I made a daemon with Python
I made a fortune with Python.
I made a character counter with Python
I made a Hex map with Python
I made a roguelike game with Python
I made a simple blackjack with Python
I made a configuration file with Python
I made a neuron simulator with Python
I made blackjack with python!
I made a python text
I made blackjack with Python.
I made wordcloud with Python.
I made a weather forecast bot-like with Python.
I made a GUI application with Python + PyQt5
I made a Twitter fujoshi blocker with Python ①
[Python] I made a Youtube Downloader with Tkinter.
I made a bin picking game with Python
I made a Mattermost bot with Python (+ Flask)
I made a Twitter BOT with GAE (python) (with a reference)
I made a Line-bot using Python!
I made a Christmas tree lighting game with Python
I made a net news notification app with Python
I made a Python3 environment on Ubuntu with direnv.
I made a LINE BOT with Python and Heroku
I made a simple typing game with tkinter in Python
I made a package to filter time series with python
I made a simple book application with python + Flask ~ Introduction ~
I made a payroll program in Python!
I drew a heatmap with seaborn [Python]
I tried a functional language with Python
What I did with a Python array
I made a life game with Numpy
After studying Python3, I made a Slackbot
I made a WEB application with Django
〇✕ I made a game
I made a library to easily read config files with Python
I made a package that can compare morphological analyzers with Python
A story about adding a REST API to a daemon made with Python
I made a lot of files for RDP connection with Python
[Python] I made an image viewer with a simple sorting function.
I made a shuffle that can be reset (reverted) with Python
I made a poker game server chat-holdem using websocket with python
I made a segment tree with python, so I will introduce it
I made a stamp substitute bot with line
I made a python dictionary file for Neocomplete
I want to make a game with Python
Procedure for creating a LineBot made with Python
I made a simple Bitcoin wallet with pycoin
I made a LINE Bot with Serverless Framework!
I made a random number graph with Numpy
I want to write to a file with Python
I made a Caesar cryptographic program in Python.
I made a Python Qiita API wrapper "qiipy"
I made a QR code image with CuteR
I made a tool to automatically browse multiple sites with Selenium (Python)
I tried to discriminate a 6-digit number with a number discrimination application made with python
I made a tool that makes decompression a little easier with CLI (Python3)
I made a module PyNanaco that can charge nanaco credit with python
I tried fp-growth with python
I tried scraping with Python
I made a discord bot