oeasy@localhost:/etc/systemd/system$ ls
bluetooth.target.wants dbus-org.freedesktop.nm-dispatcher.service face_upgrade.service graphical.target.wants multi-user.target.wants sockets.target.wants sysinit.target.wants
dbus-org.bluez.service default.target final.target.wants hibernate.target.wants network-online.target.wants sshd.service syslog.service
dbus-org.freedesktop.Avahi.service display-manager.service getty.target.wants hybrid-sleep.target.wants printer.target.wants suspend.target.wants timers.target.wants
===============================================================================================================================================================
oeasy@localhost:/etc/systemd/system$ cat face_upgrade.service ## vim face_upgrade.service ## 建立face_upgrade.service文件,root用戶權限下編輯node
[Unit]
Description=face node upgrade service
After=network.targetpython
[Service]
User=root ## 可不寫此行vim
WorkingDirectory=/home/oeasy/Client
ExecStart=/usr/bin/python /home/oeasy/Client/check_crontab.py
ExecReload=/bin/kill -HUP $MAINPID
KillMode=process
Restart=always
RestartSec=10sdom
[Install]
WantedBy=multi-user.targetssh
=============================================================================================================socket
[Install]
WantedBy=multi-user.target
oeasy@localhost:/etc/systemd/system$ systemctl enable face_upgrade
==== AUTHENTICATING FOR org.freedesktop.systemd1.manage-unit-files ===
Authentication is required to manage system service or unit files.
Authenticating as: oeasy
Password:
=============================================================================================================
oeasy@localhost:/etc/systemd/system$ systemctl start face_upgrade
==== AUTHENTICATING FOR org.freedesktop.systemd1.manage-units ===
Authentication is required to start 'face_upgrade.service'.
Authenticating as: oeasy
Password:ui
=============================================================================================================spa
oeasy@localhost:/etc/systemd/system$ systemctl stop face_upgrade
==== AUTHENTICATING FOR org.freedesktop.systemd1.manage-units ===
Authentication is required to stop 'face_upgrade.service'.
Authenticating as: oeasy
Password:
=============================================================================================================
oeasy@localhost:/etc/systemd/system$ ps -ef | grep check
oeasy 19878 17024 0 10:41 pts/1 00:00:00 grep --color=auto check
oeasy@localhost:/etc/systemd/system$ systemctl start face_upgrade
=============================================================================================================
==== AUTHENTICATING FOR org.freedesktop.systemd1.manage-units ===
Authentication is required to start 'face_upgrade.service'.
Authenticating as: oeasy
Password:
==== AUTHENTICATION COMPLETE ===
=============================================================================================================
oeasy@localhost:/etc/systemd/system$ ps -ef | grep check
root 19891 1 9 10:41 ? 00:00:00 /usr/bin/python /home/oeasy/Client/check_crontab.py
oeasy 19897 17024 0 10:41 pts/1 00:00:00 grep --color=auto checkhibernate
oeasy@localhost:/etc/systemd/system$ sudo kill 19891
sudo: unable to resolve host localhost.localdomaincrontab
oeasy@localhost:/etc/systemd/system$ ps -ef | grep check
root 19945 1 18 10:42 ? 00:00:00 /usr/bin/python /home/oeasy/Client/check_crontab.py
oeasy 19951 17024 0 10:42 pts/1 00:00:00 grep --color=auto check
=============================================================================================================
文件路徑:
/etc/systemd/system
[Unit]
Description=face node upgrade service
After=network.target
[Service]
User=root ## 默認root權限啓動可去掉
WorkingDirectory=/home/oeasy/Client
ExecStart=/usr/bin/python /home/oeasy/Client/check_crontab.py
ExecReload=/bin/kill -HUP $MAINPID
KillMode=process
Restart=always
RestartSec=10s
[Install]
WantedBy=multi-user.target
文件路徑:
/etc/systemd/system
[Unit]
Description=face node upgrade service
After=network.target
[Service]
User=root ## 默認root權限啓動可去掉
WorkingDirectory=/home/oeasy/Client # 目錄
ExecStart=/usr/bin/python /home/oeasy/Client/check_crontab.py # 執行腳本
ExecReload=/bin/kill -HUP $MAINPID
KillMode=process
Restart=always
RestartSec=10s
[Install] WantedBy=multi-user.target