7월, 2020의 게시물 표시

Python daemonize

The process of daemonization in a Linux system always goes through the same process regardless of the development language. In general, the ID of the parent process is 1 (init process id) through a double fork processing. Also, since the daemon needs to operate regardless of input/output, it dedirects stdout, stderr, and stdin to /dev/null. Here is a very simple Python code. It simply displays Hello World in the loop statement. The only part I care about is adding code for handling the termination signal. Normal Python Program import time import os , sys import signal ''' For Smooth Closing ''' def stop (sig, frame): print( 'Process Exit' ) sys . exit( 0 ) signal . signal(signal . SIGINT, stop) signal . signal(signal . SIGTERM, stop) while True : time . sleep( 1 ) print( 'Hello World' ) <normal.py> If you run the code, you may see this screen output. [root @ gcloud-seoul-a093086b769c683771dee9c71...

Python Flask - Give https to Flask WebServer

이미지
Earlier, I briefly looked at how to use the Flask web server and how to use the domain name. This time I will see how to apply https. Recently, it is recommended to use https instead of weak security http. And if you are providing important information through REST API, use of https is necessary to prevent this information from being leaked. Let's Encrypt Select Certbot from "With Shell Access" at https://letsencrypt.org/getting-started/ . On the CertBot page, select the web server and operating system. The Flask we use is not included in the web server list. Therefore, select "None of the above". The operating system is the operating system of the device you connected the domain name to earlier. I am using CentOS7 but you can choose your operating system. Now, looking at the bottom of the screen, it guides you through the appropriate installation method for the operating system and web server. When using Flask on CentOS 7, you will be prompted to add the EPEL r...

Python Flask - Give domain name to Flask WebServer

이미지
This article continues with the previous post . In the simple web server using Flask, the IP address was used to connect directly.This time, I'll change it to use the domain name. The test server does not have any problems using the public IP. However, if you use a router, you can use the port forwarding function to connect to the test server over the Internet. In this article I will configure a server that uses public IP directly. Buy a domain name Most domain names are purchased for a fee and used for a period of time, but there are domains that are available for free, including domains in some African countries. Get a domain for free and use it on a Flask web server on a server with a public IP. Get a free domain at www.freenom.com Visit https://www.freenom.com and search for the domain name you want to use. I used the domain name spypiggy, which was mostly available in African country domains. Select the domain you want to use and click the Checkout button at the top. Now Free...

Python Flask - Running a simple web server

이미지
Flask is a web application framework powered by Python. It is lighter than the Django framework, and can be built from small scale servers to large scale servers, and includes Jinja and Werkzeug. In particular, Flask can be easily used for development purposes such as providing REST APIs rather than the homepage for many unspecified users. Flask framework homepage: https://palletsprojects.com/p/flask/ Flask installation  I always use Python3. Therefore, install the package using pip3 instead of pip. # Install Flask $ pip3 install flask # Flask check $ flask -- version If you get the following error message: [root@zabbix-server ~]# pip3 install flask Retrying ( Retry (total = 4 , connect = None , read = None , redirect = None , status = None )) after connection broken by 'SSLError(SSLError(1,' [ SSL : CERTIFICATE_VERIFY_FAILED ] certificate verify failed ( _ssl . c : 877 ) '),)' : If you get an SSLError message like / packages / f2 / 28 / 2 a03252d...