2023-04-26 17:22:52 +00:00
|
|
|
#!/sbin/openrc-run
|
|
|
|
# vim:set ts=8 noet ft=sh:
|
|
|
|
#
|
|
|
|
|
2023-08-18 15:17:00 +00:00
|
|
|
description="CloudBender - setup meta_data, mount additional volumes, send shutdown messages"
|
2023-04-26 17:22:52 +00:00
|
|
|
|
|
|
|
depend() {
|
2023-08-18 15:17:00 +00:00
|
|
|
need net
|
|
|
|
before sshd
|
|
|
|
after tiny-cloud-main
|
2023-04-26 17:22:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
start() {
|
2023-08-18 15:17:00 +00:00
|
|
|
source /usr/lib/cloudbender/common.sh
|
2023-04-26 17:22:52 +00:00
|
|
|
|
2023-08-18 15:17:00 +00:00
|
|
|
get_meta_data
|
|
|
|
import_meta_data
|
2023-04-26 17:22:52 +00:00
|
|
|
|
2023-08-18 15:17:00 +00:00
|
|
|
# various initial OS tweaks
|
|
|
|
setup_instance
|
2023-04-26 17:22:52 +00:00
|
|
|
|
2023-08-18 15:17:00 +00:00
|
|
|
# mount extra optional volumes
|
|
|
|
mount_volumes "$VOLUMES"
|
2023-04-26 17:22:52 +00:00
|
|
|
|
2023-08-18 15:17:00 +00:00
|
|
|
# add optional ssh keys, eg. via IAM for AWS
|
|
|
|
configure_sshd
|
|
|
|
|
|
|
|
set_hostname $CUSTOMHOSTNAME
|
|
|
|
|
|
|
|
# if fixed hostname use persistent sshd keys
|
|
|
|
[ -n "$CUSTOMHOSTNAME" ] && persistent_sshd_hostkeys "/_ssh/${ARTIFACT}/${CONGLOMERATE}/${HOSTNAME}"
|
|
|
|
|
2023-10-05 16:46:40 +00:00
|
|
|
associate_eip $INSTANCE_ID $ELASTICIP && PUBLIC_IP_ADDRESS=$ELASTICIP
|
|
|
|
|
|
|
|
register_service_dns
|
|
|
|
|
|
|
|
is_enabled $LOGGING_ENABLED && setup_fluentbit $LOGGING_HOST
|
|
|
|
|
|
|
|
# cleanup previous reboot logs
|
|
|
|
rm -f /tmp/shutdown.log
|
|
|
|
|
|
|
|
eend 0
|
2023-04-26 17:22:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
stop() {
|
2023-08-18 15:17:00 +00:00
|
|
|
source /usr/lib/cloudbender/common.sh
|
2023-04-26 17:22:52 +00:00
|
|
|
|
2023-08-18 15:17:00 +00:00
|
|
|
import_meta_data
|
2023-04-26 17:22:52 +00:00
|
|
|
|
2023-08-18 15:17:00 +00:00
|
|
|
unmount_volumes "$VOLUMES"
|
2023-04-26 17:22:52 +00:00
|
|
|
|
2023-08-18 15:17:00 +00:00
|
|
|
[ -n "$DEBUG" ] && [ -r /tmp/shutdown.log ] && SHUTDOWNLOG="$(cat /tmp/shutdown.log)"
|
2023-04-26 17:22:52 +00:00
|
|
|
|
2023-08-18 15:17:00 +00:00
|
|
|
[ -n "$RC_REBOOT" ] && ACTION="rebooting" || ACTION="terminated"
|
|
|
|
[ -z "$DISABLE_SCALING_EVENTS" ] && /var/lib/cloud/sns_alarm.sh "Instance $ACTION" "" Info "$SHUTDOWNLOG"
|
2023-04-26 17:22:52 +00:00
|
|
|
|
2023-10-05 16:46:40 +00:00
|
|
|
eend 0
|
2023-04-26 17:22:52 +00:00
|
|
|
}
|