fetch-ec2-data: Update for systemd
This commit is contained in:
parent
892b3f6ad6
commit
98c6c5b730
@ -8,21 +8,20 @@ with pkgs.lib;
|
|||||||
|
|
||||||
{
|
{
|
||||||
|
|
||||||
jobs.fetchEC2Data =
|
boot.systemd.services."fetch-ec2-data" =
|
||||||
{ name = "fetch-ec2-data";
|
{ description = "Fetch EC2 Data";
|
||||||
|
|
||||||
startOn = "ip-up";
|
wantedBy = [ "multi-user.target" ];
|
||||||
|
before = [ "sshd.service" ];
|
||||||
task = true;
|
|
||||||
|
|
||||||
path = [ pkgs.curl pkgs.iproute ];
|
path = [ pkgs.curl pkgs.iproute ];
|
||||||
|
|
||||||
script =
|
script =
|
||||||
''
|
''
|
||||||
ip route del blackhole 169.254.169.254/32 || true
|
ip route del blackhole 169.254.169.254/32 || true
|
||||||
|
|
||||||
curl="curl --retry 3 --retry-delay 0 --fail"
|
curl="curl --retry 3 --retry-delay 0 --fail"
|
||||||
|
|
||||||
echo "setting host name..."
|
echo "setting host name..."
|
||||||
${optionalString (config.networking.hostName == "") ''
|
${optionalString (config.networking.hostName == "") ''
|
||||||
${pkgs.nettools}/bin/hostname $($curl http://169.254.169.254/1.0/meta-data/hostname)
|
${pkgs.nettools}/bin/hostname $($curl http://169.254.169.254/1.0/meta-data/hostname)
|
||||||
@ -60,12 +59,15 @@ with pkgs.lib;
|
|||||||
# accessed from now on.
|
# accessed from now on.
|
||||||
ip route add blackhole 169.254.169.254/32
|
ip route add blackhole 169.254.169.254/32
|
||||||
'';
|
'';
|
||||||
|
|
||||||
|
serviceConfig.Type = "oneshot";
|
||||||
|
serviceConfig.RemainAfterExit = true;
|
||||||
};
|
};
|
||||||
|
|
||||||
jobs.printHostKey =
|
boot.systemd.services."print-host-key" =
|
||||||
{ name = "print-host-key";
|
{ description = "Print SSH Host Key";
|
||||||
task = true;
|
wantedBy = [ "multi-user.target" ];
|
||||||
startOn = "started sshd";
|
after = [ "sshd.service" ];
|
||||||
script =
|
script =
|
||||||
''
|
''
|
||||||
# Print the host public key on the console so that the user
|
# Print the host public key on the console so that the user
|
||||||
@ -75,10 +77,8 @@ with pkgs.lib;
|
|||||||
${pkgs.openssh}/bin/ssh-keygen -l -f /etc/ssh/ssh_host_dsa_key.pub > /dev/console
|
${pkgs.openssh}/bin/ssh-keygen -l -f /etc/ssh/ssh_host_dsa_key.pub > /dev/console
|
||||||
echo "-----END SSH HOST KEY FINGERPRINTS-----" > /dev/console
|
echo "-----END SSH HOST KEY FINGERPRINTS-----" > /dev/console
|
||||||
'';
|
'';
|
||||||
|
serviceConfig.Type = "oneshot";
|
||||||
|
serviceConfig.RemainAfterExit = true;
|
||||||
};
|
};
|
||||||
|
|
||||||
# Only start sshd after we've obtained the host key (if given in the
|
|
||||||
# user data), otherwise the sshd job will generate one itself.
|
|
||||||
jobs.sshd.startOn = mkOverride 90 "stopped fetch-ec2-data";
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user