我可以使用 cloud-init 启动单元,以便之后可以由舰队管理吗?
似乎,云单元只能启动正常的 systemd 服务,但不能让它们处于舰队控制之下。这是正确的吗?
在集群启动后自动启动特定服务的可能解决方案是什么?
解决了:
#cloud-config
write_files:
- path: /home/core/foo.service
owner: core:core
permissions: 0644
content: |
[Unit]
Description=Foo
Requires=docker.service
After=docker.service
[Service]
User=core
TimeoutStartSec=0
KillMode=none
EnvironmentFile=/etc/environment
ExecStartPre=-/usr/bin/docker kill foo
ExecStartPre=-/usr/bin/docker rm foo
ExecStartPre=/usr/bin/docker pull registry.example.com/foo
ExecStart=/usr/bin/docker run --name foo registry.example.com/foo
ExecStop=/usr/bin/docker stop foo
coreos:
etcd:
discovery: https://discovery.etcd.io/<token>
addr: $private_ipv4:4001
peer-addr: $private_ipv4:7001
units:
- name: etcd.service
command: start
- name: fleet.service
command: start
- name: auto-start-foo.service
command: start
content: |
[Unit]
Description=Autostarts foo-service
Requires=docker.service
After=docker.service
[Service]
WorkingDirectory=/home/core/
ExecStart=/usr/bin/fleetctl start foo.service
Type=oneshot