René's URL Explorer Experiment


Title: systemd · Issue #132 · codcodog/Blog · GitHub

Open Graph Title: systemd · Issue #132 · codcodog/Blog

X Title: systemd · Issue #132 · codcodog/Blog

Description: systemd systemd 是 Linux 控制系统和管理服务的工具,基本上所有的发行版都支持使用. 基础 启动 / 停止 # 启动服务 $ systemctl start application.service # 停止服务 $ systemctl stop application.service # 重启服务 $ systemctl restart application.service # 查看服务状态 $ systemctl status applicati...

Open Graph Description: systemd systemd 是 Linux 控制系统和管理服务的工具,基本上所有的发行版都支持使用. 基础 启动 / 停止 # 启动服务 $ systemctl start application.service # 停止服务 $ systemctl stop application.service # 重启服务 $ systemctl restart application.servi...

X Description: systemd systemd 是 Linux 控制系统和管理服务的工具,基本上所有的发行版都支持使用. 基础 启动 / 停止 # 启动服务 $ systemctl start application.service # 停止服务 $ systemctl stop application.service # 重启服务 $ systemctl restart application.servi...

Opengraph URL: https://github.com/codcodog/Blog/issues/132

X: @github

direct link

Domain: github.com


Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"systemd","articleBody":"systemd\r\n========\r\n\r\n`systemd` 是 Linux 控制系统和管理服务的工具,基本上所有的发行版都支持使用.\r\n\r\n### 基础\r\n\r\n#### 启动 / 停止\r\n\r\n```bash\r\n# 启动服务\r\n$ systemctl start application.service\r\n\r\n# 停止服务\r\n$ systemctl stop application.service\r\n\r\n# 重启服务\r\n$ systemctl restart application.service\r\n\r\n# 查看服务状态\r\n$ systemctl status application.service\r\n\r\n# 杀死服务的所有子进程\r\n$ systemctl kill application.service\r\n```\r\n\r\n#### 重新加载配置\r\n```bash\r\n# 重新加载某服务配置文件\r\n$ systemctl reload application.service\r\n\r\n# 重新加载所有 unit 服务的配置文件\r\n$ systemctl daemon-reload\r\n```\r\n\r\n##### `reload` 和 `daemon-reload` 的区别\r\n\r\n`reload` 是重新加载某服务的配置,例如:apache 有 `httpd.conf` 配置,  `reload` 的时候,`systemd` 会发送一个 `SIGHUP` 信号让 `apache` 重新加载 `httpd.conf` 配置.   \r\n\r\n`daemon-reload` 则是重新加载 `systemd` 的配置文件,例如:某服务 `application.service` 文件在 `/etc/systemd/systemd/` 目录下,设置5秒超时时间,则需要在 `application.service` 文件添加 `TimeoutSec`\r\n```\r\n$ systemctl cat application.service\r\n[Unit]\r\nDescription=ATD daemon\r\n\r\n[Service]\r\nType=forking\r\nExecStart=/usr/bin/atd\r\nTimeoutSec=5\r\n\r\n[Install]\r\nWantedBy=multi-user.target\r\n```\r\n修改完之后,使用 `daemon-reload` 重新加载下 `systemd` 服务文件配置,则5秒超时时间才会生效。\r\n\u003e `/etc/systemd/systemd/` 目录下文件发生变更之后,都应该 `daemon-reload` 一下\r\n\r\n#### 开机启动\r\n\r\n```bash\r\n# 开机启动\r\n$ systemctl enable application.service\r\n\r\n# 禁止开机启动\r\n$ systemctl disable application.service\r\n```\r\n\r\n`enable` 通常是从 `/lib/systemd/system/` 或者 `/etc/systemd/system/`   \r\n创建一个软链接到 `/etc/systemd/system/some_target.target.wants`\r\n```\r\n~ $ ll /etc/systemd/system/multi-user.target.wants/\r\ntotal 0\r\nlrwxrwxrwx 1 root root 40 Feb 13 18:25 openntpd.service -\u003e /usr/lib/systemd/system/openntpd.service\r\nlrwxrwxrwx 1 root root 40 Feb 13 18:19 remote-fs.target -\u003e /usr/lib/systemd/system/remote-fs.target\r\n```\r\n\r\n#### 查看日志\r\n\r\n```bash\r\n# 查看系统所有服务日志\r\n$ journalctl\r\n\r\n# 查看某服务日志\r\n$ journalctl -u application.service\r\n\r\n# 实时滚动日志\r\n$ journalctl -u application.service -f\r\n\r\n# 查看尾部最新日志,不指定,默认10行\r\n$ journalctl -u application.service -n 20\r\n```\r\n\r\n### 配置文件\r\n\r\n配置文件主要在 `/usr/lib/systemd/system/` 或者 `/etc/systemd/system/`.\r\n\r\n```\r\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\r\n```\r\n\u003e 配置文件的区块名和字段名,都是大小写敏感\r\n\r\n#### [Unit] 块\r\n\r\n- `Description` 简短描述\r\n- `Documentation` 文档地址\r\n- `Requires` 当前 Unit 依赖的其他 Unit,如果它们没有运行,当前 Unit 会启动失败\r\n- `Wants` 与当前 Unit 配合的其他 Unit,如果它们没有运行,当前 Unit 不会启动失败\r\n- `BindsTo` 与Requires类似,它指定的 Unit 如果退出,会导致当前 Unit 停止运行\r\n- `Before` 如果该字段指定的 Unit 也要启动,那么必须在当前 Unit 之后启动\r\n- `After` 如果该字段指定的 Unit 也要启动,那么必须在当前 Unit 之前启动\r\n- `Conflicts` 这里指定的 Unit 不能与当前 Unit 同时运行\r\n- ...\r\n\r\n#### [Service] 块\r\n\r\n`[Service]` 区块用来 Service 的配置,只有 Service 类型的 Unit 才有这个区块.\r\n\r\n- `Type` 定义了启动时进程的行为\r\n    + simple 默认值,执行 ExecStart 指定的命令,启动主进程\r\n    + forking 以 fork 方式从父进程创建子进程,创建后父进程会立即退出\r\n    + oneshot 一次性进程,Systemd 会等当前服务退出,再继续往下执行\r\n    + dbus 当前服务通过D-Bus启动\r\n    + notify 当前服务启动完毕,会通知 Systemd,再继续往下执行\r\n    + idle 若有其他任务执行完毕,当前服务才会运行\r\n- `ExecStart` 启动当前服务的命令\r\n- `ExecStartPre` 启动当前服务之前执行的命令\r\n- `ExecStartPost` 启动当前服务之后执行的命令\r\n- `ExecReload` 重启当前服务时执行的命令\r\n- `ExecStop` 停止当前服务时执行的命令\r\n- `ExecStopPost` 停止当前服务之后执行的命令\r\n- `KillMode` Systemd 如何停止服务\r\n    + control-group 默认值,当前控制组里面的所有子进程,都会被杀掉\r\n    + process 只杀主进程\r\n    + mixed 主进程将收到 SIGTERM 信号,子进程收到 SIGKILL 信号\r\n    + none 没有进程会被杀掉,只是执行服务的 stop 命令\r\n- `RestartSec` 自动重启当前服务间隔的秒数\r\n- `Restart` 定义何种情况 Systemd 会自动重启当前服务\r\n    + no 默认值,退出后不会重启\r\n    + always 不管是什么退出原因,总是重启\r\n    + on-success 只有正常退出时(退出状态码为0),才会重启\r\n    + on-failure 非正常退出时(退出状态码非0),包括被信号终止和超时,才会重启\r\n    + on-abnormal 只有被信号终止和超时,才会重启\r\n    + on-abort 只有在收到没有捕捉到的信号终止时,才会重启\r\n    + on-watchdog 超时退出,才会重启\r\n- `TimeoutSec` 定义 Systemd 停止当前服务之前等待的秒数\r\n- `Environment` 指定环境变量\r\n\r\n\r\n#### [Install] 块\r\n\r\n定义如何启动,以及是否开机启动.\r\n\r\n- `WantedBy` 它的值是一个或多个 Target,当前 Unit 激活时(enable)符号链接会放入 `/etc/systemd/system` 目录下面以 Target 名 + .wants后缀构成的子目录中\r\n- `RequiredBy` 它的值是一个或多个 Target,当前 Unit 激活时,符号链接会放入 `/etc/systemd/system` 目录下面以 Target 名 + .required后缀构成的子目录中\r\n- `Alias` 当前 Unit 可用于启动的别名\r\n- `Also` 当前 Unit 激活(enable)时,会被同时激活的其他 Unit\r\n\r\n### Target\r\n\r\n启动计算机的时候,需要启动大量的 Unit。如果每一次启动,都要一一写明本次启动需要哪些 Unit,显然非常不方便。Systemd 的解决方案就是 `Target`.\r\n\r\n简单说,`Target` 就是一个 Unit 组,包含许多相关的 Unit。 启动某个 `Target` 的时候,Systemd 就会启动里面所有的 Unit.\r\n\r\n### 参考\r\n\r\n- man systemctl\r\n- man 5 systemd.unit\r\n- [How To Use Systemctl to Manage Systemd Services and Units](https://www.digitalocean.com/community/tutorials/how-to-use-systemctl-to-manage-systemd-services-and-units)\r\n- [Systemd 入门教程:命令篇](https://www.ruanyifeng.com/blog/2016/03/systemd-tutorial-commands.html)\r\n","author":{"url":"https://github.com/codcodog","@type":"Person","name":"codcodog"},"datePublished":"2022-02-15T15:54:59.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":0},"url":"https://github.com/132/Blog/issues/132"}

route-pattern/_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format)
route-controllervoltron_issues_fragments
route-actionissue_layout
fetch-noncev2:397a7d43-f9c3-dc85-7d80-4e888d9654fc
current-catalog-service-hash81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114
request-idB2DA:2EEF02:46E7E2:5E3FD0:6A4C2F7C
html-safe-nonce37abf2b90cce675453ce1bda4d4acfa063b6e8e6811deae7415790a82737b93f
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCMkRBOjJFRUYwMjo0NkU3RTI6NUUzRkQwOjZBNEMyRjdDIiwidmlzaXRvcl9pZCI6IjU4OTAyNTQ5NTkxMTEwNTcyNzYiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ==
visitor-hmacea03ae62a7c980fd4e923a769244275be501358d19d39f9557d395d20722fcbd
hovercard-subject-tagissue:1138882652
github-keyboard-shortcutsrepository,issues,copilot
google-site-verificationApib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I
octolytics-urlhttps://collector.github.com/github/collect
analytics-location///voltron/issues_fragments/issue_layout
fb:app_id1401488693436528
apple-itunes-appapp-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/codcodog/Blog/132/issue_layout
twitter:imagehttps://opengraph.githubassets.com/9e030de8e105988caaca185d6088d8f92a9e8d0238b713958eefb3dba6d568f1/codcodog/Blog/issues/132
twitter:cardsummary_large_image
og:imagehttps://opengraph.githubassets.com/9e030de8e105988caaca185d6088d8f92a9e8d0238b713958eefb3dba6d568f1/codcodog/Blog/issues/132
og:image:altsystemd systemd 是 Linux 控制系统和管理服务的工具,基本上所有的发行版都支持使用. 基础 启动 / 停止 # 启动服务 $ systemctl start application.service # 停止服务 $ systemctl stop application.service # 重启服务 $ systemctl restart application.servi...
og:image:width1200
og:image:height600
og:site_nameGitHub
og:typeobject
og:author:usernamecodcodog
hostnamegithub.com
expected-hostnamegithub.com
None1b6b16d04026f131a36d57e3b01d0f4d26a51800edf48bf5ed0256e0ac905511
turbo-cache-controlno-preview
go-importgithub.com/codcodog/Blog git https://github.com/codcodog/Blog.git
octolytics-dimension-user_id18098145
octolytics-dimension-user_logincodcodog
octolytics-dimension-repository_id75478736
octolytics-dimension-repository_nwocodcodog/Blog
octolytics-dimension-repository_publictrue
octolytics-dimension-repository_is_forkfalse
octolytics-dimension-repository_network_root_id75478736
octolytics-dimension-repository_network_root_nwocodcodog/Blog
turbo-body-classeslogged-out env-production page-responsive
disable-turbofalse
browser-stats-urlhttps://api.github.com/_private/browser/stats
browser-errors-urlhttps://api.github.com/_private/browser/errors
release9ee13484b32cf23e15fde191da4c9aa47d41201c
ui-targetfull
theme-color#1e2327
color-schemelight dark

Links:

Skip to contenthttps://github.com/codcodog/Blog/issues/132#start-of-content
https://github.com/
Sign in https://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fcodcodog%2FBlog%2Fissues%2F132
GitHub CopilotWrite better code with AIhttps://github.com/features/copilot
GitHub Copilot appDirect agents from issue to mergehttps://github.com/features/ai/github-app
MCP RegistryNewIntegrate external toolshttps://github.com/mcp
ActionsAutomate any workflowhttps://github.com/features/actions
CodespacesInstant dev environmentshttps://github.com/features/codespaces
IssuesPlan and track workhttps://github.com/features/issues
Code ReviewManage code changeshttps://github.com/features/code-review
GitHub Advanced SecurityFind and fix vulnerabilitieshttps://github.com/security/advanced-security
Code securitySecure your code as you buildhttps://github.com/security/advanced-security/code-security
Secret protectionStop leaks before they starthttps://github.com/security/advanced-security/secret-protection
Why GitHubhttps://github.com/why-github
Documentationhttps://docs.github.com
Bloghttps://github.blog
Changeloghttps://github.blog/changelog
Marketplacehttps://github.com/marketplace
View all featureshttps://github.com/features
Enterpriseshttps://github.com/enterprise
Small and medium teamshttps://github.com/team
Startupshttps://github.com/enterprise/startups
Nonprofitshttps://github.com/solutions/industry/nonprofits
App Modernizationhttps://github.com/solutions/use-case/app-modernization
DevSecOpshttps://github.com/solutions/use-case/devsecops
DevOpshttps://github.com/solutions/use-case/devops
CI/CDhttps://github.com/solutions/use-case/ci-cd
View all use caseshttps://github.com/solutions/use-case
Healthcarehttps://github.com/solutions/industry/healthcare
Financial serviceshttps://github.com/solutions/industry/financial-services
Manufacturinghttps://github.com/solutions/industry/manufacturing
Governmenthttps://github.com/solutions/industry/government
View all industrieshttps://github.com/solutions/industry
View all solutionshttps://github.com/solutions
AIhttps://github.com/resources/articles?topic=ai
Software Developmenthttps://github.com/resources/articles?topic=software-development
DevOpshttps://github.com/resources/articles?topic=devops
Securityhttps://github.com/resources/articles?topic=security
View all topicshttps://github.com/resources/articles
Customer storieshttps://github.com/customer-stories
Events & webinarshttps://github.com/resources/events
Ebooks & reportshttps://github.com/resources/whitepapers
Business insightshttps://github.com/solutions/executive-insights
GitHub Skillshttps://skills.github.com
Documentationhttps://docs.github.com
Customer supporthttps://support.github.com
Community forumhttps://github.com/orgs/community/discussions
Trust centerhttps://github.com/trust-center
Partnershttps://github.com/partners
View all resourceshttps://github.com/resources
GitHub SponsorsFund open source developershttps://github.com/sponsors
Security Labhttps://securitylab.github.com
Maintainer Communityhttps://maintainers.github.com
Acceleratorhttps://github.com/accelerator
GitHub Starshttps://stars.github.com
Archive Programhttps://archiveprogram.github.com
Topicshttps://github.com/topics
Trendinghttps://github.com/trending
Collectionshttps://github.com/collections
Enterprise platformAI-powered developer platformhttps://github.com/enterprise
GitHub Advanced SecurityEnterprise-grade security featureshttps://github.com/security/advanced-security
Copilot for BusinessEnterprise-grade AI featureshttps://github.com/features/copilot/copilot-business
Premium SupportEnterprise-grade 24/7 supporthttps://github.com/premium-support
Pricinghttps://github.com/pricing
Search syntax tipshttps://docs.github.com/search-github/github-code-search/understanding-github-code-search-syntax
documentationhttps://docs.github.com/search-github/github-code-search/understanding-github-code-search-syntax
Sign in https://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fcodcodog%2FBlog%2Fissues%2F132
Sign up https://github.com/signup?ref_cta=Sign+up&ref_loc=header+logged+out&ref_page=%2F%3Cuser-name%3E%2F%3Crepo-name%3E%2Fvoltron%2Fissues_fragments%2Fissue_layout&source=header-repo&source_repo=codcodog%2FBlog
Reloadhttps://github.com/codcodog/Blog/issues/132
Reloadhttps://github.com/codcodog/Blog/issues/132
Reloadhttps://github.com/codcodog/Blog/issues/132
codcodog https://github.com/codcodog
Bloghttps://github.com/codcodog/Blog
Notifications https://github.com/login?return_to=%2Fcodcodog%2FBlog
Fork 1 https://github.com/login?return_to=%2Fcodcodog%2FBlog
Star 20 https://github.com/login?return_to=%2Fcodcodog%2FBlog
Code https://github.com/codcodog/Blog
Issues 135 https://github.com/codcodog/Blog/issues
Pull requests 0 https://github.com/codcodog/Blog/pulls
Actions https://github.com/codcodog/Blog/actions
Wiki https://github.com/codcodog/Blog/wiki
Security and quality 0 https://github.com/codcodog/Blog/security
Insights https://github.com/codcodog/Blog/pulse
Code https://github.com/codcodog/Blog
Issues https://github.com/codcodog/Blog/issues
Pull requests https://github.com/codcodog/Blog/pulls
Actions https://github.com/codcodog/Blog/actions
Wiki https://github.com/codcodog/Blog/wiki
Security and quality https://github.com/codcodog/Blog/security
Insights https://github.com/codcodog/Blog/pulse
systemdhttps://github.com/codcodog/Blog/issues/132#top
Linuxhttps://github.com/codcodog/Blog/issues?q=state%3Aopen%20label%3A%22Linux%22
systemdhttps://github.com/codcodog/Blog/issues?q=state%3Aopen%20label%3A%22systemd%22
https://github.com/codcodog
codcodoghttps://github.com/codcodog
on Feb 15, 2022https://github.com/codcodog/Blog/issues/132#issue-1138882652
How To Use Systemctl to Manage Systemd Services and Unitshttps://www.digitalocean.com/community/tutorials/how-to-use-systemctl-to-manage-systemd-services-and-units
Systemd 入门教程:命令篇https://www.ruanyifeng.com/blog/2016/03/systemd-tutorial-commands.html
Linuxhttps://github.com/codcodog/Blog/issues?q=state%3Aopen%20label%3A%22Linux%22
systemdhttps://github.com/codcodog/Blog/issues?q=state%3Aopen%20label%3A%22systemd%22
https://github.com
Termshttps://docs.github.com/site-policy/github-terms/github-terms-of-service
Privacyhttps://docs.github.com/site-policy/privacy-policies/github-privacy-statement
Securityhttps://github.com/security
Statushttps://www.githubstatus.com/
Communityhttps://github.community/
Docshttps://docs.github.com/
Contacthttps://support.github.com?tags=dotcom-footer

Viewport: width=device-width


URLs of crawlers that visited me.