系统服务systemd是一个替代init管理开机启动项,以及服务依赖的一组命令。
传统init启动进程或者服务通过编写init.d下conf,作为启动重启停止的操作命令。
系统服务systemd替代init即pid为1,可以并行启动服务,服务启动状态顺序清晰可追溯。
1,编辑systemd默认加载的配置
#nano /etc/systemd/system/ftpServer.service #vim /etc/systemd/system/ftpServer.service
2,设置使能服务
systemctl enable ftpServer.service
3,重启系统检查状态
systemctl list-unit-files 其他查询命令: systemctl status systemctl --failed systemctl list-units systemctl list-unit-files 其他操作命令: systemctl start ftpServer.service systemctl status ftpServer.service systemctl is-enabled ftpServer.service 其他无关命令: service --status-all update-rc.d xxx defaults NN
/etc/systemd/system/ftpServer.service
#nano ftpServer.service #vim ftpServer.service # This file is part of systemd. # # systemd is free software; you can redistribute it and/or modify it # under the terms of the GNU Lesser General Public License as published by # the Free Software Foundation; either version 2.1 of the License, or # (at your option) any later version. # This unit gets pulled automatically into multi-user.target by # systemd-rc-local-generator if ftpServer is executable. [Unit] Description=ftpServer service ConditionFileIsExecutable=/root/ftpServer After=network.target [Service] Type=forking ExecStart=/root/ftpServer TimeoutSec=0 RemainAfterExit=yes GuessMainPID=no [Install] WantedBy=multi-user.target Alias=ftpServer.service