Before reading this post, please take a look Install Consul and Consul Template in Ubuntu 14.04 to know how to installing Consul and Consul-Template. And now, this post will help you run them in background.
With Ubuntu 14.04, you should use Upstart to make your services run in background and on startup.
You create consul-server.conf file at /etc/init/ directory with content:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
description "Consul Agent" # make sure network is up start on (local-filesystems and net-device-up IFACE!=lo) start on runlevel [2345] stop on runlevel [!2345] setuid root setgid root exec consul agent -server -bootstrap-expect 1 \ -data-dir /tmp/consul -node=agent-one -bind=172.20.20.10 \ -client=0.0.0.0 \ -config-dir /etc/consul.d -ui-dir /opt/consul-ui/ |
And create consul-template.conf file at /etc/init/ directory with content:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
description "Consul Template Jobs" start on runlevel [2345] stop on runlevel [!2345] # run after consul-server start on filesystem and started consul-server setuid root setgid root exec consul-template \ -consul 127.0.0.1:8500 \ -template "/opt/consul-template/nginx.ctmpl:/etc/nginx/sites-available/default:service nginx restart" \ -retry 30s |
Now, we run them:
1 2 |
start consul-server start consul-template |
You can troubleshoot your service by command tail -f upstart log files:
1 |
tail -f /var/log/upstart/*log |