Skip to content

Files

Latest commit

 

History

History
302 lines (225 loc) · 10.7 KB

Commands.md

File metadata and controls

302 lines (225 loc) · 10.7 KB

Useful Commands

Here are some useful commands (and notes) for installers and developers working with EDAPT.


General

See my notes on bash for an introduction to bash and shells.


System Check

When everything is situated for running in production, one can check that all systems are up and running with these commands:
systemctl status ufw (check if loaded, enabled, and active)
systemctl status nginx (check if loaded, enabled, and active)
systemctl status pm2-username (check if loaded, enabled, and active)
systemctl status mysql (check if loaded, enabled, and active)
ufw status (check specific settings re OpenSSH, HTTPS)
pm2 ls (see that "edapt" or "edapt-demo" is online)


EDAPT

For top-level dev work, see the npm scripts in package.json. For example:
npm run install-all
npm run dev-demo
npm run build-prod
npm run serve-prod
npm run build-demo
npm run serve-demo

Testing front-end only (in the web-app client directory):
npm run dev

A couple tests:
node database-api/test-runs/test-run-example.js
node email-handler/test-runs/test-run.js


SSH & SCP

ssh username@ip.add.re.ss (log in to machine at ip.add.re.ss via OpenSSH from local machine; SSH = Secure SHell)
scp source target (copy from source to target using OpenSSH)
scp path/to/local/src-file username@ip.add.re.ss:path/to/dest-file (copy from local to remote)
scp username@ip.add.re.ss:path/to/dest-file path/to/local/src-file (copy from remote to local)


SystemD

Example systemd service units:
ufw (ufw.service)
nginx (nginx.service)
pm2-username (pm2-username.service)
mysql (mysql.service)

See this tutorial on systemd. The systemd manager, with its systemctl utility command, is involved here, and these commands generalize to other systemd service "units", generically listed as application.service where the .service suffix can be omitted (eg, mysql and mysql.service are interchangeable in this context):
systemctl list-units (see a huge list of units)
systemctl list-units | grep mysql
systemctl list-unit-files
systemctl cat application.service (view unit file)
systemctl status application.service (view status)
sudo systemctl stop application.service (current-session)
sudo systemctl start application.service (current-session)
sudo systemctl restart application.service (current-session)
sudo systemctl reload application.service (current-session)
sudo systemctl disable application.service (daemon)
sudo systemctl enable application.service (daemon)
sudo systemctl mask application.service ("make unavailable")
sudo systemctl unmask application.service ("make available")
See more of the tutorial for info on safely editing the service unit files and other topics. For info on manually deleting services/units, see this forum post.


UFW

ufw = uncomplicated firewall; (see ubuntu docs)
man ufw
sudo ufw status
sudo ufw status verbose
sudo ufw app list (list the available ufw apps)
sudo ufw allow [item] (add an "allow" rule for [item], where [item] can be a port number -- such as 80, 443, 8080, 50000, etc -- or a ufw app such as 'Nginx Full')
sudo ufw delete allow [item] (remove the "allow" rule for [item], if it exists)
sudo ufw enable (turn on the firewall, and so apply the existing rules)
sudo ufw disable (turn off the firewall)
See above for the many systemctl commands available for ufw (ufw.service).


Node (& Nvm & Npm & Npx)

Nvm is optional (for development use).

nvm - node version manager (controlling node+npm+npx)
node - Node.js (a JavaScript "back-end" runtime environment)
npm - node package manager (node tool to control packages for node)
npx - node package executer (node tool to execute npm package binaries)

install/version check

command -V nvm (note that which nvm does not work, since nvm is a shell function, and thus it will also not have a man(ual) page)
nvm -v

command -V node
node -v

command -V npm
npm -v

command -V npx
npx -v

nvm (if using)

nvm --help
nvm ls (see node+npm versions installed and available on your system)
nvm current (see the currently-active/used version)
nvm use [version] (switch version being used)
See the nvm website curl or wget command for updating nvm.

node

man node
node [executable.js] (execute code with node runtime)

npm

man npm
npm help
npm init -y (create and initialize a package.json file to record installed npm packages)
npm install [package] (install node package in the current directory's module)
npm ls -g --depth 0 (see globally installed packages for the currently-used version of node+npm)

npx

For reference (and not really needed for further work on this project):
man npx
npx create-react-app app-name
npx create-react-app app-name --template typescript (if using TypeScript)


MySQL

install/version check

command -V mysql
mysql -V

Depending on how MySQL was installed, to gain MySQL root user access in the mysql repl, you may have to use either sudo mysql or mysql -u root -p.

gnu/linux

sudo mysqladmin status (show server status)

ps -A | grep -i mysql (see all processes that involve mysql)

systemctl status mysql (show status of daemon and session server)
sudo systemctl start mysql (start daemon)
sudo systemctl stop mysql (stop daemon)

sudo mysql (enter mysql shell)

sudo mysqldump database_name > dump-file.sql (save a copy of a database)
sudo mysqldump database_name table_name > dump-file.sql (save a copy of a database table)
sudo mysql < dump-file.sql (restore database)
sudo mysql database_name < dump-file.sql (restore table)

mac os

I'm not exactly sure about the distinction between what I'm calling the "session server(s)" and the "daemon server(s)"; hopefully I'm roughly correct.

mysqladmin -u root -p status (see status of mysql server(s); looks like when mysql is running, there are 2 threads correspond to two servers, as shown with ps command below)

ps -A | grep -i mysql (see all processes that involve mysql, including this usage of grep; when mysql is running, it looks like there are actually two daemons that operate: mysqld_safe and mysqld)

mysql.server status (see if session server is running)
mysql.server start (start the server)
mysql.server stop (stop the server; note: if the daemon / brew-service is running, this stops the server(s) but they immediately start again, as can be seen with the ps command above, with new process IDs)

brew services (if you installed mysql with Homebrew, this controls daemons, including mysql daemon)
brew services list | grep mysql (check mysql daemon status)
brew services start mysql (start daemon)
brew services stop mysql (stop daemon)
Note: If the daemon server is running, then the session server is running, but the reverse isn't true: if the session server is running, the daemon server may or may not be running.

mysql -u root -p (enter mysql shell)

mysqldump -u root -p database_name > dump-file.sql (save a copy of a database)
mysqldump -u root -p database_name table_name > dump-file.sql (save a copy of a database table)
mysql -u root -p < dump-file.sql (restore database)
mysql -u root -p database_name < dump-file.sql (restore table)

mysql shell

In the mysql client shell (REPL), with a mysql> prompt:

exit; (exit mysql)
show databases;
use [database_name]; (select a database for further exploration or editing)
show tables; (show all the tables in the selected database)
select * from [table_name]; (show all records in table)
drop [table_name]; (delete table)


Nginx

command -V nginx
ps -A | grep -i nginx
man nginx
nginx -h (help)
sudo nginx -t (test the configuration file)
See above for the many systemctl commands available for nginx (nginx.service).


PM2

command -V pm2
ps -A | grep -i pm2
pm2 --help
pm2 kill
pm2 ls
pm2 start "code here" --name "process-name-here"
pm2 start npm --name "pm2-process-name-here" -- run {npm-script-name-here} (for turning npm run scripts into pm2 processes)
pm2 stop process-name
pm2 start process-name
pm2 save
pm2 startup systemd
pm2 unstartup
See above for the many systemctl commands available for pm2-username (pm2-username.service).