【systemd】关于 Active: active (exited)

# yum  -y install  iptables  iptables-services

# vim  /etc/sysconfig/iptables

############################################################### 

# sample configuration for iptables service

# you can edit this manually or use system-config-firewall

# please do not ask us to add additional ports/services to this default configuration

*filter

:INPUT ACCEPT [0:0]

:FORWARD ACCEPT [0:0]

:OUTPUT ACCEPT [0:0]

-A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT

-A INPUT -p icmp -j ACCEPT

-A INPUT -i lo -j ACCEPT

-A INPUT -p tcp -m state --state NEW -m tcp --dport 22 -j ACCEPT

-A INPUT -j REJECT --reject-with icmp-host-prohibited

-A FORWARD -j REJECT --reject-with icmp-host-prohibited

COMMIT

####################################################################

# systemctl  start   iptables

# systemctl  status  iptables

# vim  /usr/lib/systemd/system/iptables.service

##############################

[Unit]

Description=IPv4 firewall with iptables

Before=ip6tables.service

After=syslog.target

AssertPathExists=/etc/sysconfig/iptables

[Service]

Type=oneshot

RemainAfterExit=yes

ExecStart=/usr/libexec/iptables/iptables.init start

ExecReload=/usr/libexec/iptables/iptables.init reload

ExecStop=/usr/libexec/iptables/iptables.init stop

Environment=BOOTUP=serial

Environment=CONSOLETYPE=serial

StandardOutput=syslog

StandardError=syslog

[Install]

WantedBy=basic.target

##############################


服务类型

编写自定义的 service 文件时,可以选择几种不同的服务启动方式。

启动方式可通过配置文件[Service]段中的Type=参数进行设置。

Type=simple:(默认值) systemd认为该服务将立即启动。服务进程不会 fork 。如果该服务要启动其他服务,不要使用此类型启动,除非该服务是socket 激活型。

Type=forking:systemd认为当该服务进程fork,且父进程退出后服务启动成功。对于常规的守护进程(daemon),除非你确定此启动方式无法满足需求,使用此类型启动即可。使用此启动类型应同时指定PIDFile=,以便 systemd 能够跟踪服务的主进程。

Type=oneshot :这一选项适用于只执行一项任务、随后立即退出的服务。可能需要同时设置 RemainAfterExit=yes 使得 systemd 在服务进程退出之后仍然认为服务处于激活状态。

Type=notify:与Type=simple相同,但约定服务会在就绪后向 systemd 发送一个信号。这一通知的实现由libsystemd-daemon.so提供。

Type=dbus:若以此方式启动,当指定的BusName出现在DBus系统总线上时,systemd认为服务就绪。

Type=idle:systemd会等待所有任务处理完成后,才开始执行idle类型的单元。其他行为与Type=simple类似。

type 的更多解释可以参考 systemd.service(5)

https://wiki.archlinux.org/index.php/systemd_(%E7%AE%80%E4%BD%93%E4%B8%AD%E6%96%87)

https://www.freedesktop.org/software/systemd/man/systemd.service.html#Type=

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容