All in vain

Some rants about technology, PHP, people, tools, web etc from a developers perspective. Feel free to copy ideas, code or anything from here.

Tuesday, November 24, 2015

see the output from unit files created using template

No comments
if you are wondering how to see the output of multiple systemd unit files launched via template units then you have come to the right place. On CoreOS i created multiple instances of a service file using template files. Systemd Unit files are of this format:

foo@.service

[Unit]
Description=Preview Application service

After=etcd.service
After=docker.service
After=docker-connect.service

Requires=docker.service

[Service]
TimeoutStartSec=0
EnvironmentFile=/etc/environment
User=core
ExecStartPre=-/usr/bin/docker kill hg-doc-preview-%i
ExecStartPre=-/usr/bin/docker rm hg-doc-preview-%i
ExecStartPre=/usr/bin/docker pull localhost:5000/hg-doc-preview
Restart=always
ExecStart=/usr/bin/docker run --name hg-doc-preview-%i -m 500m \
    -e COREOS_PRIVATE_IPV4=${COREOS_PRIVATE_IPV4} \
    -e "HG_CACHE_BACKEND=MultilevelCache" \
    -e "SERVICE_%i_NAME=hg-doc-preview" \
    -e 'SERVICE_%i_ROUTE=Host("mock-server.test-easywebats.com")' \
    -p ${COREOS_PRIVATE_IPV4}:%i:7090  \
    --add-host backends:${COREOS_PRIVATE_IPV4} \
    localhost:5000/hg-doc-preview
ExecStop=/usr/bin/docker stop hg-doc-preview-%i

[X-Fleet]
Conflicts=hg-doc-preview@%i.service


You can then start instances of this service like so:
fleetctl start foo\@1234.service to launch on external port 1234. Now if you follow this there would be many unit files and you would like to watch the output of all these units.

Just run this command to see the logs for all such units:
fleetctl list-units | grep foo | awk '{ printf " -u %s ", $1 }' | xargs journalctl -f