Skip to content

Commit

Permalink
Add PM2 cheat sheet + various additions
Browse files Browse the repository at this point in the history
  • Loading branch information
thangvo38 committed Sep 21, 2020
1 parent d00eb33 commit a6ff7b3
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 4 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
</details>

Expand Down
1 change: 1 addition & 0 deletions languages/bash.sh
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ ps -u yourusername # lists your processes
kill <PID> # kills the processes with the ID you gave
killall <processname> # 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 <job> # brings job to the foreground
Expand Down
8 changes: 4 additions & 4 deletions tools/aws.sh
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ aws s3 mv <local_file_path> s3://<bucket_name>/<destination_file_path> # Move a
## Example: aws s3 mv text.txt s3://mybucket/text.txt
aws s3 mv s3://<bucket_name_1> s3://<bucket_name_2> --recursive # Move all objects from bucket_name_1 to bucket_name_2

aws sync <source> <target> # 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 <source> <target> --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 <source> <target> # 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 <source> <target> --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
1 change: 1 addition & 0 deletions tools/docker.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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 <imagename> # Remove the specified image from this machine
docker rmi $(docker images -q) # Remove all images from this machine
docker logs <container-id> -f # Live tail a container's logs
docker login # Log in this CLI session using your Docker credentials
docker tag <image> username/repository:tag # Tag <image> for upload to registry
docker push username/repository:tag # Upload tagged image to registry
Expand Down
4 changes: 4 additions & 0 deletions tools/git.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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 <commit_id> # 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
Expand Down
26 changes: 26 additions & 0 deletions tools/pm2.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
##############################################################################
# PM2
##############################################################################

# Start commands
pm2 start <file> # Start an application
pm2 start <app_id> # Start a stopped application
pm2 start <app_id> ecosystem.config.js # Start an app with the configuration in ecosystem file
pm2 start <file> -i <number_of_instances> # 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 <app_id> # Restart an app by ID
pm2 reload <app_id> # Reload an app by ID
pm2 stop <app_id> # Stop an app by ID
pm2 stop all # Stop all running instances
pm2 delete <app_id> # Delete an app by ID
pm2 delete all # Delete all instances
pm2 ecosystem # Generate a sample ecosystem.config.js file

# Monitoring
pm2 show <app_id> # Show a specific app's description
pm2 logs <app_id> --lines=<number_of_lines> # Show the last n lines of logs of an app
pm2 env <app_id> # Show all environment variables of an app
pm2 monit # Monitor all applications' logs, metrics,etc
2 changes: 2 additions & 0 deletions tools/ubuntu.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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/<process_id>/maps # Show the current virtual memory usage of a Linux process

0 comments on commit a6ff7b3

Please sign in to comment.