touch /etc/systemd/system/name.service
chmod 664 /etc/systemd/system/name.service
1 2 3 4 5 6 7 8 9 10 11 12 |
[Unit] Description=service_description After=network.target [Service] ExecStart=path_to_executable Type=forking EnvironmentFile=-/etc/sysconfig/memcached PIDFile=path_to_pidfile [Install] WantedBy=default.target |
systemctl daemon-reload
systemctl start name.service
Type=forking vs Type=simple
Type=simple 表示服务是一个简单的服务,没有实现守护进程(daemonize) 功能,所以systemd需要将其变成守护进程(daemonize),比如memcached.service
Type=forking 表示服务直接实现了daemonize功能,比如MySQL.service
参考文档
Creating Custom Unit Files
Posted in: Linux
Comments are closed.