CentOS 7 如何添加Service并自动启动
建立service配置文件在/user/lib/systemd/system目录建立一个文件[service_name].service, 内容类似:[Unit]Description=Docker Compose gitlab ServiceRequires=docker.serviceAfter=docker.service[Service]Type=oneshotR...
·
建立service配置文件
在/usr/lib/systemd/system目录建立一个文件[service_name].service, 内容类似:
[Unit]
Description=Docker Compose gitlab Service
Requires=docker.service
After=docker.service
[Service]
Type=oneshot
RemainAfterExit=yes
WorkingDirectory=/opt/data/docker/gitlab
ExecStart=/usr/local/bin/docker-compose up -d
ExecStop=/usr/local/bin/docker-compose down
TimeoutStartSec=0
[Install]
WantedBy=multi-user.target
更新Service配置
sudo systemctl daemon-reload
启动服务及设置自动启动
sudo systemctl enable [service_name]
会在/etc/systemd/system目录下相应的target建立符号链接
sudo systemctl start [service_name]
查看服务启动日志
journalctl -u service-name.service
参考:
https://scottlinux.com/2014/12/08/how-to-create-a-systemd-service-in-linux-centos-7/
systemd - How to see full log from systemctl status service? - Unix & Linux Stack Exchange
更多推荐
已为社区贡献2条内容
所有评论(0)