Skip to content

Commit

Permalink
Merge pull request #254 from sealink/TF-704-add-run-on-startup-script
Browse files Browse the repository at this point in the history
[TF-704] Add run-on-startup script
  • Loading branch information
sam-wan authored Aug 18, 2023
2 parents 194d551 + 5ab7a85 commit 863283c
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 8 deletions.
12 changes: 5 additions & 7 deletions .ebextensions/01-nfs-mount.config
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,10 @@ commands:
03_create_mount_directory:
command: mkdir /mnt/nfs

04_mount_sftp_server:
04_download_remount_script:
command: |
SFTP_PASSWORD=$(sudo /opt/elasticbeanstalk/bin/get-config environment -k SFTP_PASSWORD)
echo "$SFTP_PASSWORD" > /tmp/credentials
sudo sshfs -o allow_other,StrictHostKeyChecking=no,password_stdin sftp-user@172.18.0.12:/ /mnt/nfs < /tmp/credentials
rm /tmp/credentials
wget -O /home/ec2-user/remount_sftp.sh https://raw.githubusercontent.com/sealink/quickprint/master/bin/remount_sftp.sh
chmod +x /home/ec2-user/remount_sftp.sh

05_restart_docker:
command: sudo service docker restart
05_mount_sftp_server:
command: /home/ec2-user/remount_sftp.sh
44 changes: 44 additions & 0 deletions .ebextensions/99-run-on-startup.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
files:
"/etc/init.d/run_on_startup.sh":
mode: "000755"
owner: root
group: root
content: |
#!/bin/bash
### BEGIN INIT INFO
# Provides: run_on_startup.sh
# Required-Start: $local_fs $remote_fs
# Required-Stop:
# Default-Start: 2 3 4 5
# Default-Stop:
# Short-Description: My Custom Startup Script
### END INIT INFO

echo "$1" >> "/tmp/hello-$(date +"%d-%m-%Y").txt"
case "$1" in
start)
echo "Starting run_on_startup..."
/home/ec2-user/remount_sftp.sh
;;
stop)
echo "Umount /mnt/nfs endpoint..."
umount /mnt/nfs/
;;
restart)
$0 stop
$0 start
;;
*)
echo "Usage: $0 {start|stop|restart}"
exit 1
esac

exit 0

commands:
01_run_on_startup:
command: chmod +x /etc/init.d/run_on_startup.sh
02_run_on_startup:
command: |
chkconfig --add run_on_startup.sh
chkconfig --level 2345 run_on_startup.sh on
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
## Unreleased

* [TF-695] Fix nfs-mount config script
* [TF-704] Add run-on-startup script

## 1.6.1

Expand Down
2 changes: 1 addition & 1 deletion bin/remount_sftp.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ else

SFTP_PASSWORD=$(sudo /opt/elasticbeanstalk/bin/get-config environment -k SFTP_PASSWORD)
echo "$SFTP_PASSWORD" > /tmp/credentials
sudo sshfs -o allow_other,StrictHostKeyChecking=no,password_stdin sftp-user@172.18.0.12:/ /mnt/nfs < /tmp/credentials
sudo sshfs -o allow_other,StrictHostKeyChecking=no,ServerAliveInterval=15,ServerAliveCountMax=3,password_stdin sftp-user@172.18.0.12:/ /mnt/nfs < /tmp/credentials
rm /tmp/credentials

echo "Mounting complete."
Expand Down

0 comments on commit 863283c

Please sign in to comment.