Changes between Initial Version and Version 1 of Systemd


Ignore:
Timestamp:
04/05/22 03:31:55 (3 years ago)
Author:
krit
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • Systemd

    v1 v1  
     1= Systemd service =
     2
     3Ref [https://medium.com/codex/setup-a-python-script-as-a-service-through-systemctl-systemd-f0cc55a42267 here]
     4
     51. Setup script to run as service called test.py
     6{{{
     7#!python
     8import time
     9from datetime import datetime
     10while True:
     11    with open("timestamp.txt", "a") as f:
     12        f.write("The current timestamp is: " + str(datetime.now()))
     13        f.close()
     14    time.sleep(10)
     15}}}
     16
     172. nano /etc/systemd/system/test.service (name of the service which is test in this case)
     18{{{
     19[Unit]
     20Description=My test service
     21After=multi-user.target
     22
     23[Service]
     24Type=simple
     25Restart=always
     26ExecStart=/usr/bin/python3 /home/<username>/test.py
     27
     28[Install]
     29WantedBy=multi-user.target
     30}}}
     31
     323. reload systemctl daemon
     33{{{
     34#!sh
     35sudo systemctl daemon-reload
     36sudo systemctl enable test.service
     37sudo systemctl start test.service
     38sudo systemctl stop test.service
     39sudo systemctl restart test.service
     40sudo systemctl status test.service
     41}}}
     42