summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjrb <jrb@voxy.com>2014-12-03 15:22:36 -0500
committerjrb <jrb@voxy.com>2014-12-03 15:22:36 -0500
commit5c5411a4fa0d1a306ec034460195879dd4b12446 (patch)
tree520ce2620b8602e75e28f22060daf0b0f99e4769
parentd470b49c7b5e4124afcd1d9053583f144a5953cc (diff)
downloadvyatta-cfg-system-5c5411a4fa0d1a306ec034460195879dd4b12446.tar.gz
vyatta-cfg-system-5c5411a4fa0d1a306ec034460195879dd4b12446.zip
Adding initial support for loading a config from AWS EC2 user-data
-rw-r--r--Makefile.am2
-rwxr-xr-xdebian/vyatta-cfg-system.postinst.in4
-rw-r--r--etc/init.d/ec2-vyos-init (renamed from etc/init.d/ec2-fetch-ssh-public-key)22
-rwxr-xr-xscripts/install/install-image-existing4
4 files changed, 26 insertions, 6 deletions
diff --git a/Makefile.am b/Makefile.am
index dd9586b6..283f59c2 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -19,7 +19,7 @@ checkparamsonreboot_SCRIPTS =
checkparamsonreboot_DATA =
checkparamsonreboot_DATA += scripts/check-params-on-reboot.d/README
-initd_SCRIPTS += etc/init.d/ec2-fetch-ssh-public-key
+initd_SCRIPTS += etc/init.d/ec2-vyos-init
initd_SCRIPTS += etc/init.d/vyatta-config-reboot-params
initd_SCRIPTS += etc/init.d/vyos-intfwatchd
checkparamsonreboot_SCRIPTS += scripts/check-params-on-reboot.d/ipv6_disable_blacklist
diff --git a/debian/vyatta-cfg-system.postinst.in b/debian/vyatta-cfg-system.postinst.in
index 8c4b1534..37c19275 100755
--- a/debian/vyatta-cfg-system.postinst.in
+++ b/debian/vyatta-cfg-system.postinst.in
@@ -214,8 +214,8 @@ update-rc.d vyatta-config-reboot-params start 20 S
# set vyos-intfwatchd to start at boot
update-rc.d vyos-intfwatchd start 2345
-# set ec2-fetch-ssh-public-key to start on boot
-update-rc.d ec2-fetch-ssh-public-key start 2345
+# set ec2-vyos-init to start on boot
+update-rc.d ec2-vyos-init start 2345
# Local Variables:
# mode: shell-script
diff --git a/etc/init.d/ec2-fetch-ssh-public-key b/etc/init.d/ec2-vyos-init
index 9af8ba1d..271648bc 100644
--- a/etc/init.d/ec2-fetch-ssh-public-key
+++ b/etc/init.d/ec2-vyos-init
@@ -1,6 +1,6 @@
#!/bin/bash
### BEGIN INIT INFO
-# Provides: ec2-fetch-ssh-public-key
+# Provides: ec2-vyos-init
# Required-Start: vyatta-router
# Required-Stop:
# Default-Start: 2 3 4 5
@@ -37,7 +37,9 @@ SHELL_API=/bin/cli-shell-api
COMMIT=/opt/vyatta/sbin/my_commit
SAVE=/opt/vyatta/sbin/vyatta-save-config.pl
LOADKEY=/opt/vyatta/sbin/vyatta-load-user-key.pl
+LOADCONFIG=/opt/vyatta/sbin/vyatta-load-config.pl
+userdata_url=http://169.254.169.254/latest/user-data
public_key_url=http://169.254.169.254/latest/meta-data/public-keys/0/openssh-key
username='vyos'
ssh_dir="/home/$username/.ssh"
@@ -61,6 +63,13 @@ if [ $? -ne 0 ]; then
exit 0
fi
+load_user_data ()
+{
+ $LOADCONFIG $userdata_url
+ $COMMIT
+ $SAVE
+}
+
load_ssh_public_key ()
{
# Doesn't work.
@@ -84,6 +93,17 @@ load_ssh_public_key ()
$SAVE
}
+# Try to load config from instance user-data
+log_action_msg "EC2: -----BEGIN FETCH CONFIG-----"
+log_action_msg "EC2: Requesting config from EC2 instance user-data"
+if (curl --silent -f $userdata_url | grep 'vyatta-config-version' >/dev/null); then
+ log_action_msg "EC2: Found Vyos config in EC2 instance user-data"
+ load_user_data
+else
+ log_action_msg "EC2: No Vyos config found in EC2 instance user-data"
+fi
+
+log_action_msg "EC2: -----END FETCH CONFIG-----"
# Try to get the ssh public key from instance metadata
log_action_msg "EC2: -----BEGIN FETCH SSH PUBLIC KEY-----"
log_action_msg "EC2: Requesting ssh public key from EC2 instance metadata"
diff --git a/scripts/install/install-image-existing b/scripts/install/install-image-existing
index 2705ce5c..7d58cd96 100755
--- a/scripts/install/install-image-existing
+++ b/scripts/install/install-image-existing
@@ -49,8 +49,8 @@ is_amazon_ec2_ami () {
if [ -n "$ami_id" ]; then
echo "Installing on VyOS AMI"
- # Create init script links for /etc/init.d/ec2-fetch-ssh-public-key
- chroot $INST_ROOT update-rc.d ec2-fetch-ssh-public-key defaults &>/dev/null
+ # Create init script links for /etc/init.d/ec2-vyos-init
+ chroot $INST_ROOT update-rc.d ec2-vyos-init defaults &>/dev/null
# Dijkstra, forgive us!
return 0