系统中经常会使用到 systemctl 去管理systemd程序,刚刚看了一篇关于 systemd 和 SysV 相关的文章,这里简要记录一下:

systemd定义: (英文来解释更为原汁原味)

systemd is a system and service manager for Linux, compatible with SysV and LSB init scripts. systemd provides:

  • Aggressive parallelization capabilities

  • Uses socket and D-Bus activation for starting services

  • Offers on-demand starting of daemons, keeps track of processes using Linux cgroups

  • Supports snapshotting and restoring of the system state

  • Maintains mount and automount points

  • Implements an elaborate transactional dependency-based service control logic.

The systemctl command is the primary tool to manage systemd. It combines the functionality of SysVinit’s service and chkconfig commands into a single tool you can use to enable and disable services permanently or only for the current session.

systemd manages units, which are representations of system resources and services. This following list shows the unit types that systemd can manage:

service

A service on the system, including instructions for starting, restarting, and stopping the service.

socket

A network socket associated with a service.

device

A device specifically managed with systemd.

mount

A mountpoint managed with systemd.

automount

A mountpoint automatically mounted on boot.

swap

Swap space on the system.

target

A synchronization point for other units. Usually used to start enabled services on boot.

path

A path for path-based activation. For example, you can start services based on the state of a certain path, such as whether it exists or not.

timer

A timer to schedule activation of another unit.

snapshot

A snapshot of the current systemd state. Usually used to rollback after making temporary changes to systemd.

slice

Restrivtion of resources through Linux Control Group nodes (cgroups).

scope

Information from systemd bus interfaces. Usually used to manage external system processes.

systemctl 常用管理命令:

# systemctl start foo
# systemctl stop foo
# systemctl restart foo
# systemctl status foo
# systemctl enable foo
# systemctl disable foo
# systemctl mask foo
# systemctl is-enabled foo

systemctl service 创建:

systemctl service在两个目录中: /etc/systemd/system 和 /usr/lib/systemd/system 之中

我们一般自己创建的service 直接放在 /etc/systemd/system 之中即可:

vim xuyaowen.service 创建文件

输入如下内容:

[Unit]
Description=xuyaowen custom service
Requires=network.target [Service]
Type=simple
ExecStart=/usr/bin/sleep infinity [Install]
WantedBy=multi-user.target

保存退出后,使用 systemctl start xuyaowen 启动后,使用 systemctl status 查看service 状态:

➜  system systemctl status xuyaowen.service
● xuyaowen.service - xuyaowen custom service
Loaded: loaded (/etc/systemd/system/xuyaowen.service; disabled; vendor preset: disabled)
Active: active (running) since Thu -- :: CST; 38min ago
Main PID: (sleep)
Tasks: (limit: )
Memory: .0K
CGroup: /system.slice/xuyaowen.service
└─ /usr/bin/sleep infinity Aug :: yaowenxu systemd[]: Started xuyaowen custom service.

service 创建成功。具体systemd 与 SysV 之间的关系可以在网络上较为容易查找到,我这里只是作为简要记录。关于systemd 更为详细的内容,请参考fedora doc .


保持更新,转载请注明出处。如果您觉得本文对你有帮助请点右下角推荐,谢谢

systemd 和 如何修改和创建一个 systemd service (Understanding and administering systemd)的更多相关文章

  1. C#创建一个Windows Service

    Windows Service这一块并不复杂,但是注意事项太多了,网上资料也很凌乱,偶尔自己写也会丢三落四的.所以本文也就产生了,本文不会写复杂的东西,完全以基础应用的需求来写,所以不会对Window ...

  2. Step by Step 创建一个WCF Service

    原创地址:http://www.cnblogs.com/jfzhu/p/4025448.html 转载请注明出处 (一)创建WCF Service (1)创建WCF Service类库 创建一个Cla ...

  3. Step by Step 创建一个 Web Service

    原创地址:http://www.cnblogs.com/jfzhu/p/4022139.html 转载请注明出处 (一)创建Web Service 创建第一个项目,类型选择ASP.NET Empty ...

  4. 转载——Step by Step 创建一个 Web Service

    原创地址:http://www.cnblogs.com/jfzhu/p/4022139.html 转载请注明出处 (一)创建Web Service 创建第一个项目,类型选择ASP.NET Empty ...

  5. 如何在Kubernetes里创建一个Nginx service

    Jerry之前的文章如何在Kubernetes里创建一个Nginx应用,已经使用kubectl命令行创建了Pod,但是在kubernetes中,Pod的IP地址会随着Pod的重启而变化,因此用Pod的 ...

  6. 使用Windows Service Wrapper快速创建一个Windows Service

    前言 今天介绍一个小工具的使用.我们都知道Windows Service是一种特殊的应用程序,它的好处是可以一直在后台运行,相对来说,比较适合一些需要一直运行同时不需要过多用户干预的应用程序,这一类我 ...

  7. 使用Windows Service Wrapper快速创建一个Windows Service 如nginx

    前言 今天介绍一个小工具的使用.我们都知道Windows Service是一种特殊的应用程序,它的好处是可以一直在后台运行,相对来说,比较适合一些需要一直运行同时不需要过多用户干预的应用程序,这一类我 ...

  8. 创建一个Windows Service 程序

    1.新建Windows项目,选择"Windows服务"类型的项目. 2.在生成的Service1.cs中代码中写你需要的代码,如下: using System; using Sys ...

  9. 如何创建一个AJAX-Enabled WCF Service

      原创地址:http://www.cnblogs.com/jfzhu/p/4041638.html 转载请注明出处   前面的文章中介绍过<Step by Step 创建一个WCF Servi ...

随机推荐

  1. 配置redis

    配置Redis 配置相关redis.conf bind 127.0.0.1                                                 注释掉 否则其它远程计算机无 ...

  2. 课程四(Convolutional Neural Networks),第一周(Foundations of Convolutional Neural Networks) —— 0.Learning Goals

    Learning Goals Understand the convolution operation Understand the pooling operation Remember the vo ...

  3. MySQL笔记(7)---事务

    1.前言 前面具体讲了MySQL中的锁实现的方式,解释了是如何保证数据在并发情况下的可靠性,并提到了事务REPETABLE READ和READ COMMITTED,解释了一下这两种事务的不同.本章讲具 ...

  4. 把本地项目放进新建的仓库(idea)

    1,获取仓库地址 比如: git@bitbucket.org:360717118/springboot_servlet-filter-listener-file.git,   2,idea 设置:

  5. Java第三方支付接入案例(支付宝)

    开源项目链接 Kitty 开源权限管理系统 项目地址:https://gitee.com/liuge1988/kitty 演示地址:http://139.196.87.48:9002/kitty 用户 ...

  6. 怎么样在windows命令下创建一个没有文件名的文件?

    直接上图 echo ' ' >> .aa //创建一个空字符的 .aa 的文件

  7. 实验吧 burpsuie拦截修改请求

    Forbidden 解题链接:http://ctf5.shiyanbar.com/basic/header/ 把language改成zh-hk,go,flag到手 Forms 题目地址:http:// ...

  8. Gradle学习笔记(1)创建简单的Java项目

      Gradle是一个基于Apache Ant和Apache Maven概念的项目自动化构建工具.它使用一种基于Groovy的特定领域语言(DSL)来声明项目设置,抛弃了基于XML的各种繁琐配置.当前 ...

  9. vuex学习及使用

    什么是vuex? 在SPA单页面组件的开发中vuex称为状态管理:简单的理解就是你在state中定义了一个数据之后,你可以在所在项目中的任何一个组件里进行获取.进行修改,并且你的修改可以得到全局的响应 ...

  10. 初识scss:配置与运行

    1.SCSS和Sass Sass 和 SCSS 其实是同一种东西,我们平时都称之为 Sass.他们都是用Ruby开发Css预处理器,boostrap4已经将less换成了sass. 不同之处: 文件拓 ...