{"id":16507,"date":"2022-10-12T21:25:39","date_gmt":"2022-10-12T13:25:39","guid":{"rendered":"http:\/\/lrxjmw.cn\/?p=16507"},"modified":"2022-10-12T21:25:44","modified_gmt":"2022-10-12T13:25:44","slug":"systemd-bestry-artikel","status":"publish","type":"post","link":"https:\/\/lrxjmw.cn\/systemd-bestry-artikel.html","title":{"rendered":"Systemd \u5165\u95e8\u6559\u7a0b\uff1a\u5b9e\u6218\u7bc7"},"content":{"rendered":"

\u4e0a\u4e00\u7bc7\u6587\u7ae0\uff0c\u4ecb\u7ecd\u4e86 Systemd \u7684\u4e3b\u8981\u547d\u4ee4<\/a>\uff0c\u8fd9\u7bc7\u6587\u7ae0\u4e3b\u8981\u4ecb\u7ecd\u5982\u4f55\u4f7f\u7528 Systemd \u6765\u7ba1\u7406\u6211\u4eec\u7684\u670d\u52a1,\u4ee5\u53ca\u5404\u9879\u7684\u542b\u4e49\uff1b<\/p>\n

\"SYSTEMD\"<\/p>\n

\u4e00\u3001\u5f00\u673a\u542f\u52a8<\/strong><\/div>\n

\u5bf9\u4e8e\u90a3\u4e9b\u652f\u6301 Systemd \u7684\u8f6f\u4ef6\uff0c\u5b89\u88c5\u7684\u65f6\u5019\uff0c\u4f1a\u81ea\u52a8\u5728\/usr\/lib\/systemd\/system\u76ee\u5f55\u6dfb\u52a0\u4e00\u4e2a\u914d\u7f6e\u6587\u4ef6,\u5982\u679c\u4f60\u60f3\u8ba9\u8be5\u8f6f\u4ef6\u5f00\u673a\u542f\u52a8\uff0c\u5c31\u6267\u884c\u4e0b\u9762\u7684\u547d\u4ee4\uff08\u4ee5httpd.service\u4e3a\u4f8b\uff09\u3002<\/p>\n

$ sudo systemctl enable httpd<\/pre>\n

\u4e0a\u9762\u7684\u547d\u4ee4\u76f8\u5f53\u4e8e\u5728\/etc\/systemd\/system\u76ee\u5f55\u6dfb\u52a0\u4e00\u4e2a\u7b26\u53f7\u94fe\u63a5\uff0c\u6307\u5411\/usr\/lib\/systemd\/system\u91cc\u9762\u7684httpd.service\u6587\u4ef6\u3002<\/p>\n

\u8fd9\u662f\u56e0\u4e3a\u5f00\u673a\u65f6\uff0cSystemd\u53ea\u6267\u884c\/etc\/systemd\/system\u76ee\u5f55\u91cc\u9762\u7684\u914d\u7f6e\u6587\u4ef6\u3002\u8fd9\u4e5f\u610f\u5473\u7740\uff0c\u5982\u679c\u628a\u4fee\u6539\u540e\u7684\u914d\u7f6e\u6587\u4ef6\u653e\u5728\u8be5\u76ee\u5f55\uff0c\u5c31\u53ef\u4ee5\u8fbe\u5230\u8986\u76d6\u539f\u59cb\u914d\u7f6e\u7684\u6548\u679c\u3002<\/p>\n

\u4e8c\u3001\u542f\u52a8\u670d\u52a1<\/strong><\/div>\n

\u8bbe\u7f6e\u5f00\u673a\u542f\u52a8\u4ee5\u540e\uff0c\u8f6f\u4ef6\u5e76\u4e0d\u4f1a\u7acb\u5373\u542f\u52a8\uff0c\u5fc5\u987b\u7b49\u5230\u4e0b\u4e00\u6b21\u5f00\u673a\u3002\u5982\u679c\u60f3\u73b0\u5728\u5c31\u8fd0\u884c\u8be5\u8f6f\u4ef6\uff0c\u90a3\u4e48\u8981\u6267\u884csystemctl start\u547d\u4ee4\u3002<\/p>\n

$ sudo systemctl start httpd<\/pre>\n

\u6267\u884c\u4e0a\u9762\u7684\u547d\u4ee4\u4ee5\u540e\uff0c\u6709\u53ef\u80fd\u542f\u52a8\u5931\u8d25\uff0c\u56e0\u6b64\u8981\u7528systemctl status\u547d\u4ee4\u67e5\u770b\u4e00\u4e0b\u8be5\u670d\u52a1\u7684\u72b6\u6001\u3002<\/p>\n

$ sudo systemctl status httpd\r\n\r\nhttpd.service - The Apache HTTP Server\r\n   Loaded: loaded (\/usr\/lib\/systemd\/system\/httpd.service; enabled)\r\n   Active: active (running) since \u91d1 2014-12-05 12:18:22 JST; 7min ago\r\n Main PID: 4349 (httpd)\r\n   Status: \"Total requests: 1; Current requests\/sec: 0; Current traffic:   0 B\/sec\"\r\n   CGroup: \/system.slice\/httpd.service\r\n           \u251c\u25004349 \/usr\/sbin\/httpd -DFOREGROUND\r\n           \u251c\u25004350 \/usr\/sbin\/httpd -DFOREGROUND\r\n           \u251c\u25004351 \/usr\/sbin\/httpd -DFOREGROUND\r\n           \u251c\u25004352 \/usr\/sbin\/httpd -DFOREGROUND\r\n           \u251c\u25004353 \/usr\/sbin\/httpd -DFOREGROUND\r\n           \u2514\u25004354 \/usr\/sbin\/httpd -DFOREGROUND\r\n\r\n12\u6708 05 12:18:22 localhost.localdomain systemd[1]: Starting The Apache HTTP Server...\r\n12\u6708 05 12:18:22 localhost.localdomain systemd[1]: Started The Apache HTTP Server.\r\n12\u6708 05 12:22:40 localhost.localdomain systemd[1]: Started The Apache HTTP Server.\r\n<\/pre>\n

\u4e0a\u9762\u7684\u8f93\u51fa\u7ed3\u679c\u542b\u4e49\u5982\u4e0b:<\/p>\n

Loaded\u884c\uff1a\u914d\u7f6e\u6587\u4ef6\u7684\u4f4d\u7f6e\uff0c\u662f\u5426\u8bbe\u4e3a\u5f00\u673a\u542f\u52a8\r\nActive\u884c\uff1a\u8868\u793a\u6b63\u5728\u8fd0\u884c\r\nMain PID\u884c\uff1a\u4e3b\u8fdb\u7a0bID\r\nStatus\u884c\uff1a\u7531\u5e94\u7528\u672c\u8eab\uff08\u8fd9\u91cc\u662f httpd \uff09\u63d0\u4f9b\u7684\u8f6f\u4ef6\u5f53\u524d\u72b6\u6001\r\nCGroup\u5757\uff1a\u5e94\u7528\u7684\u6240\u6709\u5b50\u8fdb\u7a0b\r\n\u65e5\u5fd7\u5757\uff1a\u5e94\u7528\u7684\u65e5\u5fd7<\/pre>\n
\u4e09\u3001\u505c\u6b62\u670d\u52a1<\/strong><\/div>\n

\u7ec8\u6b62\u6b63\u5728\u8fd0\u884c\u7684\u670d\u52a1\uff0c\u9700\u8981\u6267\u884csystemctl stop\u547d\u4ee4\u3002<\/p>\n

$ sudo systemctl stop httpd.service<\/pre>\n

\u6709\u65f6\u5019\uff0c\u8be5\u547d\u4ee4\u53ef\u80fd\u6ca1\u6709\u54cd\u5e94\uff0c\u670d\u52a1\u505c\u4e0d\u4e0b\u6765\u3002\u8fd9\u65f6\u5019\u5c31\u4e0d\u5f97\u4e0d\u201d\u6740\u8fdb\u7a0b\u201d\u4e86\uff0c\u5411\u6b63\u5728\u8fd0\u884c\u7684\u8fdb\u7a0b\u53d1\u51fakill\u4fe1\u53f7\u3002<\/p>\n

$ sudo systemctl kill httpd.service<\/pre>\n

\u6b64\u5916\uff0c\u91cd\u542f\u670d\u52a1\u8981\u6267\u884csystemctl restart\u547d\u4ee4\u3002<\/p>\n

$ sudo systemctl restart httpd.service<\/pre>\n
\u56db\u3001\u8bfb\u61c2\u914d\u7f6e\u6587\u4ef6<\/strong><\/div>\n

\u4e00\u4e2a\u670d\u52a1\u600e\u4e48\u542f\u52a8\uff0c\u5b8c\u5168\u7531\u5b83\u7684\u914d\u7f6e\u6587\u4ef6\u51b3\u5b9a\u3002\u4e0b\u9762\u5c31\u6765\u770b\uff0c\u914d\u7f6e\u6587\u4ef6\u6709\u4e9b\u4ec0\u4e48\u5185\u5bb9\u3002<\/p>\n

\u524d\u9762\u8bf4\u8fc7\uff0c\u914d\u7f6e\u6587\u4ef6\u4e3b\u8981\u653e\u5728\/usr\/lib\/systemd\/system\u76ee\u5f55\uff0c\u4e5f\u53ef\u80fd\u5728\/etc\/systemd\/system\u76ee\u5f55\u3002\u627e\u5230\u914d\u7f6e\u6587\u4ef6\u4ee5\u540e\uff0c\u4f7f\u7528\u6587\u672c\u7f16\u8f91\u5668\u6253\u5f00\u5373\u53ef\u3002<\/p>\n

systemctl cat\u547d\u4ee4\u53ef\u4ee5\u7528\u6765\u67e5\u770b\u914d\u7f6e\u6587\u4ef6\uff0c\u4e0b\u9762\u4ee5sshd.service\u6587\u4ef6\u4e3a\u4f8b\uff0c\u5b83\u7684\u4f5c\u7528\u662f\u542f\u52a8\u4e00\u4e2a SSH \u670d\u52a1\u5668\uff0c\u4f9b\u5176\u4ed6\u7528\u6237\u4ee5 SSH \u65b9\u5f0f\u767b\u5f55\u3002<\/p>\n

$ systemctl cat sshd.service\r\n\r\n[Unit]\r\nDescription=OpenSSH server daemon\r\nDocumentation=man:sshd(8) man:sshd_config(5)\r\nAfter=network.target sshd-keygen.service\r\nWants=sshd-keygen.service\r\n\r\n[Service]\r\nEnvironmentFile=\/etc\/sysconfig\/sshd\r\nExecStart=\/usr\/sbin\/sshd -D $OPTIONS\r\nExecReload=\/bin\/kill -HUP $MAINPID\r\nType=simple\r\nKillMode=process\r\nRestart=on-failure\r\nRestartSec=42s\r\n\r\n[Install]\r\nWantedBy=multi-user.target<\/pre>\n

\u53ef\u4ee5\u770b\u5230\uff0c\u914d\u7f6e\u6587\u4ef6\u5206\u6210\u51e0\u4e2a\u533a\u5757\uff0c\u6bcf\u4e2a\u533a\u5757\u5305\u542b\u82e5\u5e72\u6761\u952e\u503c\u5bf9\uff0c\u4e0b\u9762\u4f9d\u6b21\u89e3\u91ca\u6bcf\u4e2a\u533a\u5757\u7684\u5185\u5bb9\u3002<\/p>\n

\u4e94\u3001 [Unit] \u533a\u5757\uff1a\u542f\u52a8\u987a\u5e8f\u4e0e\u4f9d\u8d56\u5173\u7cfb<\/strong><\/div>\n

Unit\u533a\u5757\u7684Description\u5b57\u6bb5\u7ed9\u51fa\u5f53\u524d\u670d\u52a1\u7684\u7b80\u5355\u63cf\u8ff0\uff0cDocumentation\u5b57\u6bb5\u7ed9\u51fa\u6587\u6863\u4f4d\u7f6e\u3002<\/p>\n

\u63a5\u4e0b\u6765\u7684\u8bbe\u7f6e\u662f\u542f\u52a8\u987a\u5e8f\u548c\u4f9d\u8d56\u5173\u7cfb\uff0c\u8fd9\u4e2a\u6bd4\u8f83\u91cd\u8981\u3002<\/p>\n

After\u5b57\u6bb5\uff1a\u8868\u793a\u5982\u679cnetwork.target\u6216sshd-keygen.service\u9700\u8981\u542f\u52a8\uff0c\u90a3\u4e48sshd.service\u5e94\u8be5\u5728\u5b83\u4eec\u4e4b\u540e\u542f\u52a8\u3002
\n\u76f8\u5e94\u5730\uff0c\u8fd8\u6709\u4e00\u4e2aBefore\u5b57\u6bb5\uff0c\u5b9a\u4e49sshd.service\u5e94\u8be5\u5728\u54ea\u4e9b\u670d\u52a1\u4e4b\u524d\u542f\u52a8\u3002<\/p><\/blockquote>\n

\u6ce8\u610f\uff0cAfter\u548cBefore\u5b57\u6bb5\u53ea\u6d89\u53ca\u542f\u52a8\u987a\u5e8f\uff0c\u4e0d\u6d89\u53ca\u4f9d\u8d56\u5173\u7cfb\u3002<\/p>\n

\u4e3e\u4f8b\u6765\u8bf4\uff0c\u67d0 Web \u5e94\u7528\u9700\u8981 postgresql \u6570\u636e\u5e93\u50a8\u5b58\u6570\u636e\u3002\u5728\u914d\u7f6e\u6587\u4ef6\u4e2d\uff0c\u5b83\u53ea\u5b9a\u4e49\u8981\u5728 postgresql \u4e4b\u540e\u542f\u52a8\uff0c\u800c\u6ca1\u6709\u5b9a\u4e49\u4f9d\u8d56 postgresql \u3002\u4e0a\u7ebf\u540e\uff0c\u7531\u4e8e\u67d0\u79cd\u539f\u56e0\uff0cpostgresql \u9700\u8981\u91cd\u65b0\u542f\u52a8\uff0c\u5728\u505c\u6b62\u670d\u52a1\u671f\u95f4\uff0c\u8be5 Web \u5e94\u7528\u5c31\u4f1a\u65e0\u6cd5\u5efa\u7acb\u6570\u636e\u5e93\u8fde\u63a5\u3002<\/p>\n

\u8bbe\u7f6e\u4f9d\u8d56\u5173\u7cfb\uff0c\u9700\u8981\u4f7f\u7528Wants\u5b57\u6bb5\u548cRequires\u5b57\u6bb5\u3002<\/p>\n

Wants\u5b57\u6bb5\uff1a\u8868\u793asshd.service\u4e0esshd-keygen.service\u4e4b\u95f4\u5b58\u5728\u201d\u5f31\u4f9d\u8d56\u201d\u5173\u7cfb\uff0c\u5373\u5982\u679c\u201dsshd-keygen.service\u201d\u542f\u52a8\u5931\u8d25\u6216\u505c\u6b62\u8fd0\u884c\uff0c\u4e0d\u5f71\u54cdsshd.service\u7ee7\u7eed\u6267\u884c\u3002
\nRequires\u5b57\u6bb5\u5219\u8868\u793a\u201d\u5f3a\u4f9d\u8d56\u201d\u5173\u7cfb\uff0c\u5373\u5982\u679c\u8be5\u670d\u52a1\u542f\u52a8\u5931\u8d25\u6216\u5f02\u5e38\u9000\u51fa\uff0c\u90a3\u4e48sshd.service\u4e5f\u5fc5\u987b\u9000\u51fa\u3002<\/p><\/blockquote>\n

\u6ce8\u610f\uff0cWants\u5b57\u6bb5\u4e0eRequires\u5b57\u6bb5\u53ea\u6d89\u53ca\u4f9d\u8d56\u5173\u7cfb\uff0c\u4e0e\u542f\u52a8\u987a\u5e8f\u65e0\u5173\uff0c\u9ed8\u8ba4\u60c5\u51b5\u4e0b\u662f\u540c\u65f6\u542f\u52a8\u7684\u3002<\/p>\n

\u516d\u3001[Service] \u533a\u5757\uff1a\u542f\u52a8\u884c\u4e3a<\/strong><\/div>\n

Service\u533a\u5757\u5b9a\u4e49\u5982\u4f55\u542f\u52a8\u5f53\u524d\u670d\u52a1\u3002<\/p>\n

6.1 \u542f\u52a8\u547d\u4ee4<\/strong><\/span><\/div>\n

\u8bb8\u591a\u8f6f\u4ef6\u90fd\u6709\u81ea\u5df1\u7684\u73af\u5883\u53c2\u6570\u6587\u4ef6\uff0c\u8be5\u6587\u4ef6\u53ef\u4ee5\u7528EnvironmentFile\u5b57\u6bb5\u8bfb\u53d6\u3002<\/p>\n

EnvironmentFile\u5b57\u6bb5\uff1a\u6307\u5b9a\u5f53\u524d\u670d\u52a1\u7684\u73af\u5883\u53c2\u6570\u6587\u4ef6\u3002\u8be5\u6587\u4ef6\u5185\u90e8\u7684key=value\u952e\u503c\u5bf9\uff0c\u53ef\u4ee5\u7528$key\u7684\u5f62\u5f0f\uff0c\u5728\u5f53\u524d\u914d\u7f6e\u6587\u4ef6\u4e2d\u83b7\u53d6\u3002<\/pre>\n

\u4e0a\u9762\u7684\u4f8b\u5b50\u4e2d\uff0csshd \u7684\u73af\u5883\u53c2\u6570\u6587\u4ef6\u662f\/etc\/sysconfig\/sshd\u3002<\/p>\n

\u914d\u7f6e\u6587\u4ef6\u91cc\u9762\u6700\u91cd\u8981\u7684\u5b57\u6bb5\u662fExecStart\u3002<\/p>\n

ExecStart\u5b57\u6bb5\uff1a\u5b9a\u4e49\u542f\u52a8\u8fdb\u7a0b\u65f6\u6267\u884c\u7684\u547d\u4ee4\u3002<\/pre>\n

\u4e0a\u9762\u7684\u4f8b\u5b50\u4e2d\uff0c\u542f\u52a8sshd\uff0c\u6267\u884c\u7684\u547d\u4ee4\u662f\/usr\/sbin\/sshd -D $OPTIONS\uff0c\u5176\u4e2d\u7684\u53d8\u91cf$OPTIONS\u5c31\u6765\u81eaEnvironmentFile\u5b57\u6bb5\u6307\u5b9a\u7684\u73af\u5883\u53c2\u6570\u6587\u4ef6\u3002<\/p>\n

\u4e0e\u4e4b\u4f5c\u7528\u76f8\u4f3c\u7684\uff0c\u8fd8\u6709\u5982\u4e0b\u8fd9\u4e9b\u5b57\u6bb5\u3002<\/p>\n

ExecReload\u5b57\u6bb5\uff1a\u91cd\u542f\u670d\u52a1\u65f6\u6267\u884c\u7684\u547d\u4ee4\r\nExecStop\u5b57\u6bb5\uff1a\u505c\u6b62\u670d\u52a1\u65f6\u6267\u884c\u7684\u547d\u4ee4\r\nExecStartPre\u5b57\u6bb5\uff1a\u542f\u52a8\u670d\u52a1\u4e4b\u524d\u6267\u884c\u7684\u547d\u4ee4\r\nExecStartPost\u5b57\u6bb5\uff1a\u542f\u52a8\u670d\u52a1\u4e4b\u540e\u6267\u884c\u7684\u547d\u4ee4\r\nExecStopPost\u5b57\u6bb5\uff1a\u505c\u6b62\u670d\u52a1\u4e4b\u540e\u6267\u884c\u7684\u547d\u4ee4<\/pre>\n

\u8bf7\u770b\u4e0b\u9762\u7684\u4f8b\u5b50\u3002<\/p>\n

[Service]\r\nExecStart=\/bin\/echo execstart1\r\nExecStart=\r\nExecStart=\/bin\/echo execstart2\r\nExecStartPost=\/bin\/echo post1\r\nExecStartPost=\/bin\/echo post2<\/pre>\n

\u4e0a\u9762\u8fd9\u4e2a\u914d\u7f6e\u6587\u4ef6\uff0c\u7b2c\u4e8c\u884cExecStart\u8bbe\u4e3a\u7a7a\u503c\uff0c\u7b49\u4e8e\u53d6\u6d88\u4e86\u7b2c\u4e00\u884c\u7684\u8bbe\u7f6e\uff0c\u8fd0\u884c\u7ed3\u679c\u5982\u4e0b\u3002<\/p>\n

execstart2\r\npost1\r\npost2<\/pre>\n

\u6240\u6709\u7684\u542f\u52a8\u8bbe\u7f6e\u4e4b\u524d\uff0c\u90fd\u53ef\u4ee5\u52a0\u4e0a\u4e00\u4e2a\u8fde\u8bcd\u53f7\uff08-\uff09\uff0c\u8868\u793a\u201d\u6291\u5236\u9519\u8bef\u201d\uff0c\u5373\u53d1\u751f\u9519\u8bef\u7684\u65f6\u5019\uff0c\u4e0d\u5f71\u54cd\u5176\u4ed6\u547d\u4ee4\u7684\u6267\u884c\u3002\u6bd4\u5982\uff0cEnvironmentFile=-\/etc\/sysconfig\/sshd\uff08\u6ce8\u610f\u7b49\u53f7\u540e\u9762\u7684\u90a3\u4e2a\u8fde\u8bcd\u53f7\uff09\uff0c\u5c31\u8868\u793a\u5373\u4f7f\/etc\/sysconfig\/sshd\u6587\u4ef6\u4e0d\u5b58\u5728\uff0c\u4e5f\u4e0d\u4f1a\u629b\u51fa\u9519\u8bef\u3002<\/p>\n

6.2 \u542f\u52a8\u7c7b\u578b<\/strong><\/span><\/div>\n

Type\u5b57\u6bb5\u5b9a\u4e49\u542f\u52a8\u7c7b\u578b\u3002\u5b83\u53ef\u4ee5\u8bbe\u7f6e\u7684\u503c\u5982\u4e0b\u3002<\/p>\n

simple\uff08\u9ed8\u8ba4\u503c\uff09\uff1aExecStart\u5b57\u6bb5\u542f\u52a8\u7684\u8fdb\u7a0b\u4e3a\u4e3b\u8fdb\u7a0b\r\nforking\uff1aExecStart\u5b57\u6bb5\u5c06\u4ee5fork()\u65b9\u5f0f\u542f\u52a8\uff0c\u6b64\u65f6\u7236\u8fdb\u7a0b\u5c06\u4f1a\u9000\u51fa\uff0c\u5b50\u8fdb\u7a0b\u5c06\u6210\u4e3a\u4e3b\u8fdb\u7a0b\r\noneshot\uff1a\u7c7b\u4f3c\u4e8esimple\uff0c\u4f46\u53ea\u6267\u884c\u4e00\u6b21\uff0cSystemd \u4f1a\u7b49\u5b83\u6267\u884c\u5b8c\uff0c\u624d\u542f\u52a8\u5176\u4ed6\u670d\u52a1\r\ndbus\uff1a\u7c7b\u4f3c\u4e8esimple\uff0c\u4f46\u4f1a\u7b49\u5f85 D-Bus \u4fe1\u53f7\u540e\u542f\u52a8\r\nnotify\uff1a\u7c7b\u4f3c\u4e8esimple\uff0c\u542f\u52a8\u7ed3\u675f\u540e\u4f1a\u53d1\u51fa\u901a\u77e5\u4fe1\u53f7\uff0c\u7136\u540e Systemd \u518d\u542f\u52a8\u5176\u4ed6\u670d\u52a1\r\nidle\uff1a\u7c7b\u4f3c\u4e8esimple\uff0c\u4f46\u662f\u8981\u7b49\u5230\u5176\u4ed6\u4efb\u52a1\u90fd\u6267\u884c\u5b8c\uff0c\u624d\u4f1a\u542f\u52a8\u8be5\u670d\u52a1\u3002\u4e00\u79cd\u4f7f\u7528\u573a\u5408\u662f\u4e3a\u8ba9\u8be5\u670d\u52a1\u7684\u8f93\u51fa\uff0c\u4e0d\u4e0e\u5176\u4ed6\u670d\u52a1\u7684\u8f93\u51fa\u76f8\u6df7\u5408<\/pre>\n

\u4e0b\u9762\u662f\u4e00\u4e2aoneshot\u7684\u4f8b\u5b50\uff0c\u7b14\u8bb0\u672c\u7535\u8111\u542f\u52a8\u65f6\uff0c\u8981\u628a\u89e6\u6478\u677f\u5173\u6389\uff0c\u914d\u7f6e\u6587\u4ef6\u53ef\u4ee5\u8fd9\u6837\u5199\u3002<\/p>\n

[Unit]\r\nDescription=Switch-off Touchpad\r\n\r\n[Service]\r\nType=oneshot\r\nExecStart=\/usr\/bin\/touchpad-off\r\n\r\n[Install]\r\nWantedBy=multi-user.target<\/pre>\n

\u4e0a\u9762\u7684\u914d\u7f6e\u6587\u4ef6\uff0c\u542f\u52a8\u7c7b\u578b\u8bbe\u4e3aoneshot\uff0c\u5c31\u8868\u660e\u8fd9\u4e2a\u670d\u52a1\u53ea\u8981\u8fd0\u884c\u4e00\u6b21\u5c31\u591f\u4e86\uff0c\u4e0d\u9700\u8981\u957f\u671f\u8fd0\u884c\u3002<\/p>\n

\u5982\u679c\u5173\u95ed\u4ee5\u540e\uff0c\u5c06\u6765\u67d0\u4e2a\u65f6\u5019\u8fd8\u60f3\u6253\u5f00\uff0c\u914d\u7f6e\u6587\u4ef6\u4fee\u6539\u5982\u4e0b\u3002<\/p>\n

[Unit]\r\nDescription=Switch-off Touchpad\r\n\r\n[Service]\r\nType=oneshot\r\nExecStart=\/usr\/bin\/touchpad-off start\r\nExecStop=\/usr\/bin\/touchpad-off stop\r\nRemainAfterExit=yes\r\n\r\n[Install]\r\nWantedBy=multi-user.target<\/pre>\n

\u4e0a\u9762\u914d\u7f6e\u6587\u4ef6\u4e2d\uff0cRemainAfterExit\u5b57\u6bb5\u8bbe\u4e3ayes\uff0c\u8868\u793a\u8fdb\u7a0b\u9000\u51fa\u4ee5\u540e\uff0c\u670d\u52a1\u4ecd\u7136\u4fdd\u6301\u6267\u884c\u3002\u8fd9\u6837\u7684\u8bdd\uff0c\u4e00\u65e6\u4f7f\u7528systemctl stop\u547d\u4ee4\u505c\u6b62\u670d\u52a1\uff0cExecStop\u6307\u5b9a\u7684\u547d\u4ee4\u5c31\u4f1a\u6267\u884c\uff0c\u4ece\u800c\u91cd\u65b0\u5f00\u542f\u89e6\u6478\u677f\u3002<\/p>\n

6.3 \u91cd\u542f\u884c\u4e3a<\/strong><\/span><\/div>\n

Service\u533a\u5757\u6709\u4e00\u4e9b\u5b57\u6bb5\uff0c\u5b9a\u4e49\u4e86\u91cd\u542f\u884c\u4e3a\u3002<\/p>\n

KillMode\u5b57\u6bb5\uff1a\u5b9a\u4e49 Systemd \u5982\u4f55\u505c\u6b62 sshd \u670d\u52a1\u3002<\/pre>\n

\u4e0a\u9762\u8fd9\u4e2a\u4f8b\u5b50\u4e2d\uff0c\u5c06KillMode\u8bbe\u4e3aprocess\uff0c\u8868\u793a\u53ea\u505c\u6b62\u4e3b\u8fdb\u7a0b\uff0c\u4e0d\u505c\u6b62\u4efb\u4f55sshd \u5b50\u8fdb\u7a0b\uff0c\u5373\u5b50\u8fdb\u7a0b\u6253\u5f00\u7684 SSH session \u4ecd\u7136\u4fdd\u6301\u8fde\u63a5\u3002\u8fd9\u4e2a\u8bbe\u7f6e\u4e0d\u592a\u5e38\u89c1\uff0c\u4f46\u5bf9 sshd \u5f88\u91cd\u8981\uff0c\u5426\u5219\u4f60\u505c\u6b62\u670d\u52a1\u7684\u65f6\u5019\uff0c\u4f1a\u8fde\u81ea\u5df1\u6253\u5f00\u7684 SSH session \u4e00\u8d77\u6740\u6389\u3002<\/p>\n

KillMode\u5b57\u6bb5\u53ef\u4ee5\u8bbe\u7f6e\u7684\u503c\u5982\u4e0b\u3002<\/p>\n

control-group\uff08\u9ed8\u8ba4\u503c\uff09\uff1a\u5f53\u524d\u63a7\u5236\u7ec4\u91cc\u9762\u7684\u6240\u6709\u5b50\u8fdb\u7a0b\uff0c\u90fd\u4f1a\u88ab\u6740\u6389\r\nprocess\uff1a\u53ea\u6740\u4e3b\u8fdb\u7a0b\r\nmixed\uff1a\u4e3b\u8fdb\u7a0b\u5c06\u6536\u5230 SIGTERM \u4fe1\u53f7\uff0c\u5b50\u8fdb\u7a0b\u6536\u5230 SIGKILL \u4fe1\u53f7\r\nnone\uff1a\u6ca1\u6709\u8fdb\u7a0b\u4f1a\u88ab\u6740\u6389\uff0c\u53ea\u662f\u6267\u884c\u670d\u52a1\u7684 stop \u547d\u4ee4\u3002<\/pre>\n

\u63a5\u4e0b\u6765\u662fRestart\u5b57\u6bb5\u3002<\/p>\n

Restart\u5b57\u6bb5\uff1a\u5b9a\u4e49\u4e86 sshd \u9000\u51fa\u540e\uff0cSystemd \u7684\u91cd\u542f\u65b9\u5f0f\u3002
\n\u4e0a\u9762\u7684\u4f8b\u5b50\u4e2d\uff0cRestart\u8bbe\u4e3aon-failure\uff0c\u8868\u793a\u4efb\u4f55\u610f\u5916\u7684\u5931\u8d25\uff0c\u5c31\u5c06\u91cd\u542fsshd\u3002\u5982\u679c sshd \u6b63\u5e38\u505c\u6b62\uff08\u6bd4\u5982\u6267\u884csystemctl stop\u547d\u4ee4\uff09\uff0c\u5b83\u5c31\u4e0d\u4f1a\u91cd\u542f\u3002<\/p>\n

Restart\u5b57\u6bb5\u53ef\u4ee5\u8bbe\u7f6e\u7684\u503c\u5982\u4e0b\u3002<\/p>\n

no\uff08\u9ed8\u8ba4\u503c\uff09\uff1a\u9000\u51fa\u540e\u4e0d\u4f1a\u91cd\u542f\r\non-success\uff1a\u53ea\u6709\u6b63\u5e38\u9000\u51fa\u65f6\uff08\u9000\u51fa\u72b6\u6001\u7801\u4e3a0\uff09\uff0c\u624d\u4f1a\u91cd\u542f\r\non-failure\uff1a\u975e\u6b63\u5e38\u9000\u51fa\u65f6\uff08\u9000\u51fa\u72b6\u6001\u7801\u975e0\uff09\uff0c\u5305\u62ec\u88ab\u4fe1\u53f7\u7ec8\u6b62\u548c\u8d85\u65f6\uff0c\u624d\u4f1a\u91cd\u542f\r\non-abnormal\uff1a\u53ea\u6709\u88ab\u4fe1\u53f7\u7ec8\u6b62\u548c\u8d85\u65f6\uff0c\u624d\u4f1a\u91cd\u542f\r\non-abort\uff1a\u53ea\u6709\u5728\u6536\u5230\u6ca1\u6709\u6355\u6349\u5230\u7684\u4fe1\u53f7\u7ec8\u6b62\u65f6\uff0c\u624d\u4f1a\u91cd\u542f\r\non-watchdog\uff1a\u8d85\u65f6\u9000\u51fa\uff0c\u624d\u4f1a\u91cd\u542f\r\nalways\uff1a\u4e0d\u7ba1\u662f\u4ec0\u4e48\u9000\u51fa\u539f\u56e0\uff0c\u603b\u662f\u91cd\u542f<\/pre>\n

\u5bf9\u4e8e\u5b88\u62a4\u8fdb\u7a0b\uff0c\u63a8\u8350\u8bbe\u4e3aon-failure\u3002\u5bf9\u4e8e\u90a3\u4e9b\u5141\u8bb8\u53d1\u751f\u9519\u8bef\u9000\u51fa\u7684\u670d\u52a1\uff0c\u53ef\u4ee5\u8bbe\u4e3aon-abnormal\u3002<\/p>\n

\u6700\u540e\u662fRestartSec\u5b57\u6bb5\u3002<\/p>\n

RestartSec\u5b57\u6bb5\uff1a\u8868\u793a Systemd \u91cd\u542f\u670d\u52a1\u4e4b\u524d\uff0c\u9700\u8981\u7b49\u5f85\u7684\u79d2\u6570\u3002\u4e0a\u9762\u7684\u4f8b\u5b50\u8bbe\u4e3a\u7b49\u5f8542\u79d2\u3002<\/pre>\n
\u4e03\u3001[Install] \u533a\u5757<\/strong><\/div>\n

Install\u533a\u5757\uff0c\u5b9a\u4e49\u5982\u4f55\u5b89\u88c5\u8fd9\u4e2a\u914d\u7f6e\u6587\u4ef6\uff0c\u5373\u600e\u6837\u505a\u5230\u5f00\u673a\u542f\u52a8\u3002<\/p>\n

WantedBy\u5b57\u6bb5\uff1a\u8868\u793a\u8be5\u670d\u52a1\u6240\u5728\u7684 Target\u3002<\/pre>\n

Target\u7684\u542b\u4e49\u662f\u670d\u52a1\u7ec4\uff0c\u8868\u793a\u4e00\u7ec4\u670d\u52a1\u3002WantedBy=multi-user.target\u6307\u7684\u662f\uff0csshd \u6240\u5728\u7684 Target \u662fmulti-user.target\u3002<\/p>\n

\u8fd9\u4e2a\u8bbe\u7f6e\u975e\u5e38\u91cd\u8981\uff0c\u56e0\u4e3a\u6267\u884csystemctl enable sshd.service\u547d\u4ee4\u65f6\uff0csshd.service\u7684\u4e00\u4e2a\u7b26\u53f7\u94fe\u63a5\uff0c\u5c31\u4f1a\u653e\u5728\/etc\/systemd\/system\u76ee\u5f55\u4e0b\u9762\u7684multi-user.target.wants\u5b50\u76ee\u5f55\u4e4b\u4e2d\u3002<\/p>\n

Systemd \u6709\u9ed8\u8ba4\u7684\u542f\u52a8 Target\u3002<\/p>\n

$ systemctl get-default\r\nmulti-user.target<\/pre>\n

\u4e0a\u9762\u7684\u7ed3\u679c\u8868\u793a\uff0c\u9ed8\u8ba4\u7684\u542f\u52a8 Target \u662fmulti-user.target\u3002\u5728\u8fd9\u4e2a\u7ec4\u91cc\u7684\u6240\u6709\u670d\u52a1\uff0c\u90fd\u5c06\u5f00\u673a\u542f\u52a8\u3002\u8fd9\u5c31\u662f\u4e3a\u4ec0\u4e48systemctl enable\u547d\u4ee4\u80fd\u8bbe\u7f6e\u5f00\u673a\u542f\u52a8\u7684\u539f\u56e0\u3002<\/p>\n

\u4f7f\u7528 Target \u7684\u65f6\u5019\uff0csystemctl list-dependencies\u547d\u4ee4\u548csystemctl isolate\u547d\u4ee4\u4e5f\u5f88\u6709\u7528\u3002<\/p>\n

# \u67e5\u770b multi-user.target \u5305\u542b\u7684\u6240\u6709\u670d\u52a1\r\n$ systemctl list-dependencies multi-user.target\r\n\r\n# \u5207\u6362\u5230\u53e6\u4e00\u4e2a target\r\n# shutdown.target \u5c31\u662f\u5173\u673a\u72b6\u6001\r\n$ sudo systemctl isolate shutdown.target<\/pre>\n

\u4e00\u822c\u6765\u8bf4\uff0c\u5e38\u7528\u7684 Target \u6709\u4e24\u4e2a\uff1a\u4e00\u4e2a\u662fmulti-user.target\uff0c\u8868\u793a\u591a\u7528\u6237\u547d\u4ee4\u884c\u72b6\u6001\uff1b\u53e6\u4e00\u4e2a\u662fgraphical.target\uff0c\u8868\u793a\u56fe\u5f62\u7528\u6237\u72b6\u6001\uff0c\u5b83\u4f9d\u8d56\u4e8emulti-user.target\u3002\u5b98\u65b9\u6587\u6863\u6709\u4e00\u5f20\u975e\u5e38\u6e05\u6670\u7684 Target \u4f9d\u8d56\u5173\u7cfb\u56fe\u3002<\/p>\n

\u516b\u3001Target \u7684\u914d\u7f6e\u6587\u4ef6<\/strong><\/div>\n

Target \u4e5f\u6709\u81ea\u5df1\u7684\u914d\u7f6e\u6587\u4ef6\u3002<\/p>\n

$ systemctl cat multi-user.target\r\n\r\n[Unit]\r\nDescription=Multi-User System\r\nDocumentation=man:systemd.special(7)\r\nRequires=basic.target\r\nConflicts=rescue.service rescue.target\r\nAfter=basic.target rescue.service rescue.target\r\nAllowIsolate=yes<\/pre>\n

\u6ce8\u610f\uff0cTarget \u914d\u7f6e\u6587\u4ef6\u91cc\u9762\u6ca1\u6709\u542f\u52a8\u547d\u4ee4\u3002<\/p>\n

\u4e0a\u9762\u8f93\u51fa\u7ed3\u679c\u4e2d\uff0c\u4e3b\u8981\u5b57\u6bb5\u542b\u4e49\u5982\u4e0b\u3002<\/p>\n

Requires\u5b57\u6bb5\uff1a\u8981\u6c42basic.target\u4e00\u8d77\u8fd0\u884c\u3002\r\nConflicts\u5b57\u6bb5\uff1a\u51b2\u7a81\u5b57\u6bb5\u3002\u5982\u679crescue.service\u6216rescue.target\u6b63\u5728\u8fd0\u884c\uff0cmulti-user.target\u5c31\u4e0d\u80fd\u8fd0\u884c\uff0c\u53cd\u4e4b\u4ea6\u7136\u3002\r\nAfter\uff1a\u8868\u793amulti-user.target\u5728basic.target \u3001 rescue.service\u3001 rescue.target\u4e4b\u540e\u542f\u52a8\uff0c\u5982\u679c\u5b83\u4eec\u6709\u542f\u52a8\u7684\u8bdd\u3002\r\nAllowIsolate\uff1a\u5141\u8bb8\u4f7f\u7528systemctl isolate\u547d\u4ee4\u5207\u6362\u5230multi-user.target\u3002<\/pre>\n
\u4e5d\u3001\u4fee\u6539\u914d\u7f6e\u6587\u4ef6\u540e\u91cd\u542f<\/strong><\/div>\n

\u4fee\u6539\u914d\u7f6e\u6587\u4ef6\u4ee5\u540e\uff0c\u9700\u8981\u91cd\u65b0\u52a0\u8f7d\u914d\u7f6e\u6587\u4ef6\uff0c\u7136\u540e\u91cd\u65b0\u542f\u52a8\u76f8\u5173\u670d\u52a1\u3002<\/p>\n

# \u91cd\u65b0\u52a0\u8f7d\u914d\u7f6e\u6587\u4ef6\r\n$ sudo systemctl daemon-reload\r\n\r\n# \u91cd\u542f\u76f8\u5173\u670d\u52a1\r\n$ sudo systemctl restart foobar<\/pre>\n
\n

\u539f\u6587\u6765\u81ea\uff1ahttp:\/\/www.ruanyifeng.com\/\u2026\/systemd-tutorial-part-two.html<\/a>\u4f5c\u8005\uff1a\u962e\u4e00\u5cf0<\/span><\/p>\n

\u8f6c\u8f7d\u5730\u5740\uff1ahttp:\/\/www.codeceo.com\/article\/systemd-coding.html<\/a><\/p>\n

\u672c\u6587\u5730\u5740\uff1ahttp:\/\/lrxjmw.cn\/systemd-bestry-artikel.html<\/a>\u7f16\u8f91\uff1a\u5cb3\u6c38\uff0c\u5ba1\u6838\u5458\uff1a\u51af\u632f\u534e<\/span><\/p>\n<\/blockquote>\n","protected":false},"excerpt":{"rendered":"

\u4e0a\u4e00\u7bc7\u6587\u7ae0\uff0c\u4ecb\u7ecd\u4e86 Systemd \u7684\u4e3b\u8981\u547d\u4ee4\uff0c\u8fd9\u7bc7\u6587\u7ae0\u4e3b\u8981\u4ecb\u7ecd\u5982\u4f55\u4f7f\u7528 Systemd \u6765\u7ba1\u7406\u6211\u4eec\u7684\u670d\u52a1,\u4ee5 […]<\/p>\n","protected":false},"author":63,"featured_media":14714,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[55],"tags":[],"class_list":["post-16507","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-thread"],"acf":[],"_links":{"self":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/16507","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/users\/63"}],"replies":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/comments?post=16507"}],"version-history":[{"count":16,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/16507\/revisions"}],"predecessor-version":[{"id":254637,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/16507\/revisions\/254637"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media\/14714"}],"wp:attachment":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media?parent=16507"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/categories?post=16507"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/tags?post=16507"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}