Skip to main content

Work with Linux instance

Meet prerequisites

Before you start working with a Linux instance, check that the following prerequisites are met:

  • You have an SSH client, for example, OpenSSH client, installed.
  • You have a public or private key pair generated.
info

Before working with the instance console, run the inject-ssh-key job to inject your local SSH public key into the instance. For Linux, it is located in /home/user_name/.ssh/*.pub.

Connect to instance type in terminal

To connect to an instance type in the terminal, run the following command:

ssh -i path_to_your_private_key ec2-user@host -t "sudo su - wfuser"

Example:

ssh -i ~/.ssh/id_rsa ec2-user@core-1234-wfaw-10061-master1.wflab.io -t "sudo su - wfuser"

Configure port forwarding

You can use port forwarding for remote debugging. To configure, run the following command:

ssh -i path_to_your_private_key -L localhost:local_port:remote_host:remote_port  ec2-user@remote_host

Example:

ssh -i ~/.ssh/id_rsa -L localhost:7999:core-1234-wfaw-10061-master1.wflab.io:4444 ec2-user@core-1234-wfaw-10061-master1.wflab.io

where:

  • localhost:7999 is a local configuration for debugging in IntelliJ IDEA.

  • core-1234-wfaw-10061-master1.wflab.io:4444 is a remote host with the port opened for debugging. Set the following Tomcat run property: -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=4444.

Copy file from remote server

To copy a file from the remote server, execute the following command:

ssh -i ~/.ssh/id_rsa ec2-user@core-15872-v2-wfaw-10061-master1.workfusion.com 'sudo -u wfuser dd if=/opt/workfusion/workspace/workspace.jar' | dd of=~/Downloads/from_remote/ws.jar

Run Ansible playbook

To run an Ansible playbook, do as follows:

  1. Log in as wfuser:

    sudo su - wfuser
  2. Execute the following commands:

    source /opt/workfusion/environment.sh
    cd /opt/workfusion/wf_installer
    export ANSIBLE_VAULT_PASS=<password here>
    export ANSIBLE_PRIVATE_KEY_FILE=id_rsa
    export ANSIBLE_REMOTE_USER=wfuser
  3. Install the playbook using the following command:

    ./install.sh <allowed_tag_name> <playbook_name>

    where:

    • allowed_tag_name is listed in install.sh in the allowed_actions variable.

    • playbook_name is located in the playbooks directory.

  4. To finish the configuration, run the following command:

    ./install.sh configure workspace

View useful console commands

Below is a list of useful console commands and their usage examples:

  • netstat -tulpn | grep LISTEN to show ports bound to specific processes.

    • To show the ports bound only to Java processes sorted by PID, for example, netstat -tulpn | grep LISTEN | grep java | sort -k 7nr

    • To show Java processes with working directories, for example, netstat -tulpn | grep LISTEN | grep java | sort -k 7nr | awk '{print $7}' | grep -o '[0-9]*' | uniq | awk -F',' '{ system("pwdx "$1) | getline vpwdx; printf vpwdx}'

  • tail -f -n200 /path/to/log to display the last 200 lines of the log.

  • ps -aux to show processes.

  • kill -9 <PID> to kill a process with a specific ID.

  • nohup ./start.sh & to run the sh script in the background.

  • pwdx <PID> to show the current working directory for the process.

  • locate a_word_to_search to find all files with a specific word. Requires the mlocate utility installed.

  • wfmanager <status | stop | start > to manage WorkFusion services on instances.

  • find /root/path -name file_name.ext to find a file in a directory.

  • gunzip -c *.gz | grep "string to be searched" to find a string in GZ files.

Consider useful console utilities

The console utilities below serve the following purposes:

  • sudo yum install mc installs a two-panel file manager for the console. To run, type - mc in the console.

  • sudo yum install mlocate installs a utility to search a string in system files, for example, locate workspace | grep -vE "/workfusion/workspace|workfusion/wf_installer".

  • sudo yum install tree -y installs a utility for displaying the directory hierarchy as a tree.