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用户权限下编辑
[Unit] Description=face node upgrade service After=network.target
[Service] User=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
=============================================================================================================
[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:
=============================================================================================================
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 check
oeasy@localhost:/etc/systemd/system$ sudo kill 19891 sudo: unable to resolve host localhost.localdomain
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
sudo systemctl daemon-reload 重启一下
文件路径: /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