From 6749197e761bf58997928db5d9a504c999871d7a Mon Sep 17 00:00:00 2001 From: Thang Vo Date: Mon, 21 Sep 2020 14:22:00 +0700 Subject: [PATCH 1/3] Add basic AWS CLI commands --- README.md | 1 + tools/aws.sh | 39 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+) create mode 100644 tools/aws.sh diff --git a/README.md b/README.md index 29ce392..05bf96f 100644 --- a/README.md +++ b/README.md @@ -116,6 +116,7 @@ Feel free to take a look. You might learn new things. They have been designed to - [Nanobox CLI](tools/nanobox_cli.sh) - [Nginx](tools/nginx.sh) - [Ubuntu](tools/ubuntu.sh) +- [AWS CLI](tools/aws.sh) ## 🙌🏼 How to Contribute? diff --git a/tools/aws.sh b/tools/aws.sh new file mode 100644 index 0000000..7509cd3 --- /dev/null +++ b/tools/aws.sh @@ -0,0 +1,39 @@ +############################################################################## +# AWS +############################################################################## + +# General +aws help +aws --version # Show the current AWS CLI version +aws configure # Configure your AWS Key ID, AWS Secret, default region and default output format for the AWS CLI +aws configure --profile # Configure using the profile name. By default, the list of profile is stored in ~/.aws.credentials (Linux and MacOS) + +# EC2 +## We need to specify a region to use ec2 commands. We can configure a default region with "aws configure" or set the AWS_DEFAULT_REGION environment variable before the command line +## Example: AWS_DEFAULT_REGION=us-east-1 aws ec2 describe-instances + +aws ec2 describe-instances # Desribe all instances in the current region +aws ec2 describe-instances --instance-ids # Describe specific instances by their IDs +aws ec2 describe-instances --filters Name= # Filter and describe instances by name + +aws ec2 start-instances --instance-ids # Start previously stopped instances by their IDs +aws ec2 stop-instances --instance-ids # Stop running instances by their IDs +aws ec2 terminate-instances --instance-ids # Shutdown the specific instances by their IDs + + +# S3 +## To specify the root directory of a S3 bucket, use this syntax: s3:// + +aws s3 ls # List S3 objects and common prefixes under a prefix or all S3 buckets +aws s3 ls s3:// # List objects and common prefixes under a specified bucket and prefix +aws s3 mb s3:// # Create a specific S3 bucket +aws s3 rb s3:// # Remove an empty specific S3 bucket by name + +aws s3 mv s3:/// # Move a file in local_file_path to a specific bucket in destination_file_path +## Example: aws s3 mv text.txt s3://mybucket/text.txt +aws s3 mv s3:// s3:// --recursive # Move all objects from bucket_name_1 to bucket_name_2 + +aws sync # Sync all contents from source to a target directory. This will copy and update all missing or outdated files or objects between source and target +## Examples: aws sync . s3://mybucket +## aws sync s3://bucket_1 s3://bucket_2 +aws sync --delete # Sync all contents from source to target, but this will remove all missing files and objects from the target that are not present in source From 9dc86ca020e12a7a05f57b82baae55571fac3339 Mon Sep 17 00:00:00 2001 From: Thang Vo Date: Mon, 21 Sep 2020 14:39:49 +0700 Subject: [PATCH 2/3] Reorder aws in readme.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 05bf96f..e2588ce 100644 --- a/README.md +++ b/README.md @@ -109,6 +109,7 @@ Feel free to take a look. You might learn new things. They have been designed to #### Infrastructure +- [AWS CLI](tools/aws.sh) - [Docker](tools/docker.sh) - [Heroku CLI](tools/heroku.sh) - [Kubernetes](tools/kubernetes.md) @@ -116,7 +117,6 @@ Feel free to take a look. You might learn new things. They have been designed to - [Nanobox CLI](tools/nanobox_cli.sh) - [Nginx](tools/nginx.sh) - [Ubuntu](tools/ubuntu.sh) -- [AWS CLI](tools/aws.sh) ## 🙌🏼 How to Contribute? From a6ff7b33d1bb187b8219ddc0849b0dbceb39b37a Mon Sep 17 00:00:00 2001 From: Thang Vo Date: Mon, 21 Sep 2020 16:59:02 +0700 Subject: [PATCH 3/3] Add PM2 cheat sheet + various additions --- README.md | 1 + languages/bash.sh | 1 + tools/aws.sh | 8 ++++---- tools/docker.sh | 1 + tools/git.sh | 4 ++++ tools/pm2.sh | 26 ++++++++++++++++++++++++++ tools/ubuntu.sh | 2 ++ 7 files changed, 39 insertions(+), 4 deletions(-) create mode 100644 tools/pm2.sh diff --git a/README.md b/README.md index e2588ce..d629e9c 100644 --- a/README.md +++ b/README.md @@ -116,6 +116,7 @@ Feel free to take a look. You might learn new things. They have been designed to - [Nanobox Boxfile](tools/nanobox_boxfile.yml) - [Nanobox CLI](tools/nanobox_cli.sh) - [Nginx](tools/nginx.sh) +- [PM2](tools/pm2.sh) - [Ubuntu](tools/ubuntu.sh) diff --git a/languages/bash.sh b/languages/bash.sh index b7a1d22..d77d54c 100644 --- a/languages/bash.sh +++ b/languages/bash.sh @@ -139,6 +139,7 @@ ps -u yourusername # lists your processes kill # kills the processes with the ID you gave killall # kill all processes with the name top # displays your currently active processes +lsof # lists open files bg # lists stopped or background jobs ; resume a stopped job in the background fg # brings the most recent job in the foreground fg # brings job to the foreground diff --git a/tools/aws.sh b/tools/aws.sh index 7509cd3..d90525a 100644 --- a/tools/aws.sh +++ b/tools/aws.sh @@ -33,7 +33,7 @@ aws s3 mv s3:/// # Move a ## Example: aws s3 mv text.txt s3://mybucket/text.txt aws s3 mv s3:// s3:// --recursive # Move all objects from bucket_name_1 to bucket_name_2 -aws sync # Sync all contents from source to a target directory. This will copy and update all missing or outdated files or objects between source and target -## Examples: aws sync . s3://mybucket -## aws sync s3://bucket_1 s3://bucket_2 -aws sync --delete # Sync all contents from source to target, but this will remove all missing files and objects from the target that are not present in source +aws s3 sync # Sync all contents from source to a target directory. This will copy and update all missing or outdated files or objects between source and target +## Examples: aws s3 sync . s3://mybucket +## aws s3 sync s3://bucket_1 s3://bucket_2 +aws s3 sync --delete # Sync all contents from source to target, but this will remove all missing files and objects from the target that are not present in source diff --git a/tools/docker.sh b/tools/docker.sh index a24f374..c19579e 100644 --- a/tools/docker.sh +++ b/tools/docker.sh @@ -16,6 +16,7 @@ docker rm $(docker ps -a -q) # Remove all containers from this ma docker images -a # Show all images on this machine docker rmi # Remove the specified image from this machine docker rmi $(docker images -q) # Remove all images from this machine +docker logs -f # Live tail a container's logs docker login # Log in this CLI session using your Docker credentials docker tag username/repository:tag # Tag for upload to registry docker push username/repository:tag # Upload tagged image to registry diff --git a/tools/git.sh b/tools/git.sh index 0f32f4a..2e630ad 100644 --- a/tools/git.sh +++ b/tools/git.sh @@ -46,6 +46,10 @@ git stash branch my-branch stash@{1} # creates a branch from your stash git stash drop stash@{1} # deletes the {1} stash git stash clear # clears all the stash +git rebase -i # Rebase commits from a commit ID +git rebase --abort # Abort a running rebase +git rebase --continue # Continue rebasing after fixing all conflicts + git clean -f # clean untracked files permanently git clean -f -d/git clean -fd # To remove directories permanently git clean -f -X/git clean -fX # To remove ignored files permanently diff --git a/tools/pm2.sh b/tools/pm2.sh new file mode 100644 index 0000000..ecdfc04 --- /dev/null +++ b/tools/pm2.sh @@ -0,0 +1,26 @@ +############################################################################## +# PM2 +############################################################################## + +# Start commands +pm2 start # Start an application +pm2 start # Start a stopped application +pm2 start ecosystem.config.js # Start an app with the configuration in ecosystem file +pm2 start -i # Start an app in cluster mode with n duplicated instances + +# Management commands +pm2 ls # List all processes +pm2 save # Save process list to respawn at reboot +pm2 restart # Restart an app by ID +pm2 reload # Reload an app by ID +pm2 stop # Stop an app by ID +pm2 stop all # Stop all running instances +pm2 delete # Delete an app by ID +pm2 delete all # Delete all instances +pm2 ecosystem # Generate a sample ecosystem.config.js file + +# Monitoring +pm2 show # Show a specific app's description +pm2 logs --lines= # Show the last n lines of logs of an app +pm2 env # Show all environment variables of an app +pm2 monit # Monitor all applications' logs, metrics,etc diff --git a/tools/ubuntu.sh b/tools/ubuntu.sh index 65a7280..f2f89c4 100644 --- a/tools/ubuntu.sh +++ b/tools/ubuntu.sh @@ -11,3 +11,5 @@ sudo ufw allow from remote_IP_address to any port 3306 # Allow external ip to ac scp user@remote_host:remote_file local_file # download: remote -> local scp local_file user@remote_host:remote_file # upload: local -> remote + +cat /proc//maps # Show the current virtual memory usage of a Linux process