Ignition config - run shell command

1,088 views
Skip to first unread message

Denriful

unread,
May 12, 2017, 3:31:59 AM5/12/17
to CoreOS User
Is there any way to run shell command after bootup the node via ignition config? 

Rob Szumski

unread,
May 12, 2017, 12:04:26 PM5/12/17
to Denriful, CoreOS User
You can write out a “oneshot” unit that contains ExecStart=/bin/sh…


 - Rob

On May 12, 2017, at 12:31 AM, 'Denriful' via CoreOS User <coreo...@googlegroups.com> wrote:

Is there any way to run shell command after bootup the node via ignition config? 

--
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.

Denriful

unread,
May 15, 2017, 6:20:10 AM5/15/17
to CoreOS User, sobr...@mail.ru
Thanks! 
but i still can't start it on boot:

consul-install.sh:
#!/bin/bash
unzip consul_0.8.1_linux_amd64.zip
sudo chmod +x consul
sudo mkdir -p /opt/bin
sudo mv consul /opt/bin/
sudo mkdir -p /etc/consul.d
sudo chmod a+w /etc/consul.d
sudo mkdir -p /opt/consul/data
sudo mkdir -p /var/log/consul
sudo chmod a+w /var/log/consul
nohup /opt/bin/consul agent -config-file /etc/consul.d/consul-core1.json  >consul.log  2>&1 &




consul.service:
[Unit]
Description=Setup Consul Cluster

[Service]
Type=oneshot
ExecStart=/opt/bin/consul-install.sh
RemainAfterExit=true

[Install]
WantedBy=multi-user.target


Then the node is booted there is no running consul service
i need to run "systemctl start consul.service" to start it.

How to run just created systemd service on first boot?



пятница, 12 мая 2017 г., 23:04:26 UTC+7 пользователь Rob Szumski написал:

paul...@coreos.com

unread,
Jun 2, 2017, 11:54:08 AM6/2/17
to CoreOS User, sobr...@mail.ru
It might make sense to do a one-shot for install, and then run a normal service unit file for regular use.

Euan Kemp

unread,
Jun 2, 2017, 2:43:00 PM6/2/17
to coreo...@googlegroups.com
> On Monday, May 15, 2017 at 3:20:10 AM UTC-7, Denriful wrote:
> consul.service:
> |
> [Unit]
> Description=Setup Consul Cluster
>
> [Service]
> Type=oneshot
> ExecStart=/opt/bin/consul-install.sh
> RemainAfterExit=true
>
> [Install]
> WantedBy=multi-user.target
>
> |
>
> Then the node is booted there is no running consul service
> i need to run "systemctl start consul.service" to start it.
>
> How to run just created systemd service on first boot?
>

If you enable the service file (e.g. using ignition's 'enable' option
when creating it or using `systemctl enable`) it should run on boot boot.

You'll probably also have to have 'After=network-online.target' and
'Requires=network-online.target' in order to ensure the 'wget' in the
script works.

One other cool trick you can use is adding>
ConditionPathExists=!/opt/bin/consul
to the unit which downloads agent so it only runs once.

This assumes you do split out running the agent to its own unit, which
you probably should.

Best,
Euan

signature.asc
Reply all
Reply to author
Forward
0 new messages