Start one unit file automatically after another unit file - Not working

88 views
Skip to first unread message

Karthik Jayaraman

unread,
Oct 2, 2014, 10:18:06 PM10/2/14
to coreo...@googlegroups.com
abc-epg@.service Unit File

[Unit]
Description=abc EPG Service
Wants=epg-discovery@%i.service
Before=epg-discovery@%i.service

# Requirements
Requires=etcd.service
Requires=docker.service

# Dependency ordering
After=etcd.service
After=docker.service

[Service]
User=core
# Let processes take awhile to start up (for first run Docker containers)
TimeoutStartSec=0

# Change killmode from "control-group" to "none" to let Docker remove
# work correctly.
KillMode=none

# Get CoreOS environmental variables
EnvironmentFile=/etc/environment

# Pre-start and Start
## Directives with "=-" are allowed to fail without consequence
ExecStartPre=-/usr/bin/docker kill abc-epg
ExecStartPre=-/usr/bin/docker rm abc-epg
ExecStartPre=/usr/bin/docker -D  pull abcuser/abc-repository:abc-epg
ExecStart=/usr/bin/docker run --name abc-epg -p 8080:8080 abcuser/abc-repository:abc-epg

# Stop
ExecStop=/usr/bin/docker stop abc-epg
TimeoutStartSec=5m
TimeoutStopSec=20s
RestartSec=30s

[X-Fleet]
X-Conflicts=abc-epg@*.service

epg-discovery@.service Unit File
[Unit]
Description=abc etcd Service

# Requirements
Requires=etcd.service

# Dependency ordering
After=etcd.service
After=abc-epg@%i.service
BindsTo=abc-epg@%i.service

[Service]
User=core
# Let processes take awhile to start up (for first run Docker containers)
TimeoutStartSec=0

# Change killmode from "control-group" to "none" to let Docker remove
# work correctly.
KillMode=none

# Get CoreOS environmental variables
EnvironmentFile=/etc/environment

# Pre-start and Start
## Directives with "=-" are allowed to fail without consequence

ExecStart=/bin/bash -c '\
  while true; do \
    curl -f ${COREOS_PUBLIC_IPV4}:8080; \
    if [ $? -eq 0 ]; then \
      etcdctl set /services/epg/${COREOS_PUBLIC_IPV4} ${COREOS_PUBLIC_IPV4}:8080 --ttl 30; \
    else \
      etcdctl rm /services/epg/${COREOS_PUBLIC_IPV4}; \
    fi; \
    sleep 20; \
  done'


[X-Fleet]
X-ConditionMachineOf=abc-epg@%i.service

With the aforementioned configuration, with wants and after, the discovery unit must be started right after the service unit right ? But eventhough the service unit is started successfully, the discovery unit is not. Any problems with my config. ?

Brian Waldon

unread,
Oct 3, 2014, 12:29:18 PM10/3/14
to Karthik Jayaraman, coreos-user
What fleetctl commands are you using? The Wants/Before options are only consumed by systemd, not by fleet, so you do have to make sure the units are scheduled (fleetctl load) before starting abc...@N.service.

--
You received this message because you are subscribed to the Google Groups "CoreOS User" group.
To unsubscribe from this group and stop receiving emails from it, send an email to coreos-user...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Karthik Jayaraman

unread,
Oct 3, 2014, 2:08:01 PM10/3/14
to coreo...@googlegroups.com, aswi...@gmail.com
thanks for your prompt response. I just now found that. 

Karthik Jayaraman

unread,
Oct 3, 2014, 2:08:15 PM10/3/14
to coreo...@googlegroups.com, aswi...@gmail.com
thanks for your prompt response. I just now found that. 

On Friday, October 3, 2014 9:29:18 AM UTC-7, Brian Waldon wrote:

Karthik Jayaraman

unread,
Oct 3, 2014, 4:15:58 PM10/3/14
to coreo...@googlegroups.com, aswi...@gmail.com
Even after i load units, the loaded unit does not start by itself.

fleetctl submit tve-epg\@.service epg-discovery\@.service
fleetctl submit tve-epg\@{1..2}.service  epg-discovery\@{1..2}.service
fleetctl load tve-epg\@{1..2}.service  epg-discovery\@{1..2}.service
--------------------------------------------------------------------------------------
Unit tve...@1.service loaded on 0fc6daa6.../292.268.222.24
Unit tve...@2.service loaded on 275df756.../292.268.222.27
Unit epg-di...@1.service loaded on 0fc6daa6.../292.268.222.24
Unit epg-di...@2.service loaded on 275df756.../292.268.222.27
--------------------------------------------------------------------------------------

fleetctl start tve-epg\@{1..2}.service
--------------------------------------------------------------------------------------
Unit tve...@1.service launched
Unit tve...@2.service launched on 275df756.../192.168.111.17
--------------------------------------------------------------------------------------

fleetctl list-units
--------------------------------------------------------------------------------------
UNIT                    MACHINE                         ACTIVE          SUB
epg-di...@1.service 0fc6daa6.../192.168.111.14      inactive        dead
epg-di...@2.service 275df756.../192.168.111.17      inactive        dead
tve...@1.service       0fc6daa6.../192.168.111.14      active          running
tve...@2.service       275df756.../192.168.111.17      active          running
--------------------------------------------------------------------------------------

Jonathan Boulle

unread,
Oct 14, 2014, 5:42:08 PM10/14/14
to Karthik Jayaraman, coreos-user
Can you file an issue against fleet to troubleshoot this further?

Karthik Jayaraman

unread,
Oct 14, 2014, 7:05:17 PM10/14/14
to coreo...@googlegroups.com, aswi...@gmail.com
Thanks for your response. The issue was with my unit files. Corrected them and loaded them as per my constraints. It worked. Thanks.
Reply all
Reply to author
Forward
0 new messages