摘要
我的系列文档
Netkiller Architect 手札 | Netkiller Developer 手札 | Netkiller PHP 手札 | Netkiller Python 手札 | Netkiller Testing 手札 |
---|---|---|---|---|
Netkiller Cryptography 手札 | Netkiller Linux 手札 | Netkiller Debian 手札 | Netkiller CentOS 手札 | Netkiller FreeBSD 手札 |
Netkiller Shell 手札 | Netkiller Security 手札 | Netkiller Web 手札 | Netkiller Monitoring 手札 | Netkiller Storage 手札 |
Netkiller Mail 手札 | Netkiller Docbook 手札 | Netkiller Project 手札 | Netkiller Database 手札 | Netkiller PostgreSQL 手札 |
Netkiller MySQL 手札 | Netkiller NoSQL 手札 | Netkiller LDAP 手札 | Netkiller Network 手札 | Netkiller Cisco IOS 手札 |
Netkiller H3C 手札 | Netkiller Multimedia 手札 | Netkiller Perl 手札 | Netkiller Amateur Radio 手札 | Netkiller DevOps 手札 |
您可以使用iBook阅读当前文档
目录
systemd是Linux电脑操作系统之下的一套中央化系统及设置管理程序(init软件),包括有守护进程、程序库跟应用软件,由Lennart Poettering带头开发。 其开发目标是提供更优秀的框架以表示系统服务间的依赖关系,并依此实现系统初始化时服务的并行启动,同时达到降低Shell的系统开销的效果,最终代替现在常用的System V与BSD风格init程序。
与多数发行版使用的System V风格init相比,systemd采用了以下新技术:
CentOS 7 开始系统默认使用 systemd,对于用户来说就是service被systemctl替代了。
基本上从 Redhat 派生出的Linux操作系统基本都切换到了 systemd,Ubuntu也采用了systemd
由Lennart Poettering带头开发
下面是一个启动tomcat的systemd脚本,以此脚本为例我带大家进入 systemd 的世界。
例 1. /usr/lib/systemd/system/tomcat.service
####################################################
# Homepage: http://netkiller.github.io
# Author: netkiller<netkiller@msn.com>
# Script: https://github.com/oscm/shell
# Date: 2015-11-03
####################################################
[Unit]
Description=Apache Tomcat Web Application Container
After=network.target
After=syslog.target
[Service]
Type=forking
User=www
Group=www
#EnvironmentFile=/etc/sysconfig/tomcat
ExecStartPre="rm -rf /srv/apache-tomcat/logs/*"
ExecStart=/srv/apache-tomcat/bin/startup.sh
#ExecStartPost=
ExecStop=/srv/apache-tomcat/bin/shutdown.sh
[Install]
WantedBy=multi-user.target
脚本安装到 /usr/lib/systemd/system/tomcat.service 下面
systemctl enable tomcat
systemctl start tomcat
systemctl stop tomcat
systemctl disable tomcat
启用脚本的时候会创建一个符号链接
[neo@netkiller ~]# ll /etc/systemd/system/multi-user.target.wants/tomcat.service
lrwxrwxrwx 1 root root 38 Nov 3 04:06 /etc/systemd/system/multi-user.target.wants/tomcat.service -> /usr/lib/systemd/system/tomcat.service
Description 写一段文字描述该脚本
After 等待网络就绪后运行
Type 启动类型
User, Group 运行 ExecStart 脚本的用户,相当于 su - user -c ExecStart
Environment 环境变量,EnvironmentFile 环境变量文件
ExecStartPre 开始之前运行的脚本,ExecStart 启动脚本, ExecStartPost 启动之后运行的脚本
ExecStop 停止脚本
WantedBy=multi-user.target 安装到多用户模式