系统中经常会使用到 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. shell中mail发邮件的问题

    今天为了监控一下脚本,按照网上说的利用mail 发邮件,mail -s "error预警2" peien@1221.qq.com<'邮件内容',发现出现cc,不知道啥问题,也 ...

  2. 修改centos 7 系统时间

    查看当前系统时间 date 修改当前系统时间 date -s "2018-2-22 19:10:30 查看硬件时间 hwclock --show 修改硬件时间 hwclock --set - ...

  3. spring cloud+.net core搭建微服务架构:配置中心续(五)

    前言 上一章最后讲了,更新配置以后需要重启客户端才能生效,这在实际的场景中是不可取的.由于目前Steeltoe配置的重载只能由客户端发起,没有实现处理程序侦听服务器更改事件,所以还没办法实现彻底实现这 ...

  4. python学习之语法

    看过python的语法,才知道,这中编程语言是最简洁的,比如if a==b这种判断a和b的值是否相等,其他编程语言是需要小括号的,这个就不用. if语句: cars = ['audi', 'bmw', ...

  5. 解决Android Studio 3.x版本的安装时没有SDK,运行时出现SDK tools错误

    好久没更新了,最近手机上的闹钟APP没一个好用的,所以想自己写个. 那Android开发环境搭起来,注意先装好jdk. 1.安装Android Studio google的Android开发网站已经有 ...

  6. tf.estimator.Estimator类的用法

    官网链接:https://www.tensorflow.org/api_docs/python/tf/estimator/Estimator Estimator - 一种可极大地简化机器学习编程的高阶 ...

  7. LearnOpenGL学习笔记(一)——现有代码理解

    首先,给出这次学习的代码原网址.------>原作者的源代码 (黑体是源码,注释是写的.) 引用的库(预编译): #include <glad/glad.h> //控制编译时函数的具 ...

  8. leetcode — longest-palindromic-substring

    import java.util.Arrays; /** * Source : https://oj.leetcode.com/problems/longest-palindromic-substri ...

  9. An Exploration of ARM TrustZone Technology

    墙外通道:https://genode.org/documentation/articles/trustzone ARM TrustZone technology has been around fo ...

  10. 【jQuery源码】整体架构

    jQuery源码可以精简为以下内容: 方框上面的代码根据Jq注释我们可以知道是对AMD规范的支持. jQuery整体上被包裹在一个匿名函数中,这个匿名函数再作为另一个匿名函数的参数被传入,形参fact ...