How to use tmux inside release pipeline - azure

I have an azure release pipeline to run my backend application on a DigitalOcean server.
I would like to use a tmux window so I can still see the terminal in case I need to debug the production backend.
tmux new-session -A -s tmuxWindowName
pkill java
mv backend/demo-0.0.1-SNAPSHOT.jar backend/backend.jar
java -Xmx800M -jar backend/backend.jar
tmux detach
but this doesn't work because the azure ssh connection is not attached to a terminal. I get the following error:
##[error]open terminal failed: not a terminal
I tried setting the term with "TERM=xterm" and googling this issue comes up with lots of people that are able to manipulate the SSH connection command but I can't since I use an SSH service connection.
What to do?

You can create a detached tmux session by adding -d to new-session which will not require a terminal (until you attach it which will be presumably from somewhere else).

Related

Using Huey with Django: How to keep run_huey command running?

I'm using Django on Ubuntu 18.04.
I've got everything set up. And I type python manage.py run_huey in the server (through an SSH connection) to start huey, and it works.
However this is done through the command line through SSH and it will shut off when I close the SSH connection.
How do I keep run_huey running so that it will stay active at all times? Furthermore, after a system reboot, how do I get run_huey to automatically start?
You may explore supervisorctl utility for ubuntu, it keeps process running and can log into file and any other features. Google it.

running SSH script command from jenkins using SSH

To deploy application on linux ubuntu server I have bunch of SSH commands that i currently run using PuTTY. The server has local account serviceaccount1. In PuTTY i connect to server using serviceaccount1 and executes the following commands one by one
cd /home/serviceaccount1/cr-ml
script /dev/null
screen -S data_and_status
cd cr-ml/notebooks
source activate crml
unset XDG_RUNTIME_DIR
jupyter kernelgateway --api='kernel_gateway.notebook_http' --seed_uri='data_and_status_api.ipynb' --port 8894 --ip 0.0.0.0
...
...
and so on
Now i want automate this using Jenkins. I installed SSH plugin, configured credential using SSH Username serviceaccount1 with private key
Then created a new jenkins project and added a build step Execute shell scripts on remote host using ssh and then add all the above commands.
When i build the jenkins project, it get stuck at executing 2nd command script /dev/null
i see the following console output
To me, it seems the culprit is the screen -S data_and_status command. Once you start a screen, I don't think you would be able to execute the subsequent commands over the SSH connection.
Alternatively, you can try using a tool like Ansible to run a bunch of commands against a remote server.

Start nodejs app on linux server with ssh-if i close the ssh connection,app stopped why?)

Start nodejs app on linux server with ssh(if i close the ssh connection,app stopped why?)
1-create nodejs app -its oke
2-run on linux server -its oke(i stop the apache server)
But if i close the ssh connection(with my windows pc),app stopped.How can i solve this problem?
The most correct thing to do is to write a service file for it so whatever init system you have (likely systemd) will keep it running and manage the start/stop/restart stuff for you.
Failing that (and I don't blame you...) you can run it within the screen utility. Launch it with screen -d -m /path/to/start/script and then you can come back later and reconnect to it with screen -r or screen -r <pid of the screen session>.
Note that launching it that way won't restart it, etc. To do that, you could do something like
#!/bin/sh
while true
do
sleep 3s
/path/to/start/script
done
And call that with the screen command.
Use the nohup command to start the application. Like:
nohup THE_COMMAND_YOU_DONT_WANT_TO_STOP_WHEN_YOU_LOGOUT &
With nodemon it might be helpful to put the command to start the server in a file called myserver.sh containing:
nodemon server.js
Make sure the file is executable:
chmod +x myserver.js
And then run
nohup myserver.sh &

Geddy CLI closes on SSH drop

In a remote CentOS VM Geddy application with MonogoDB wrapper is deployed. The application starts and listen to port 80 when below command is executed.
geddy -e production &
The problem in this CLI command is when the SSH connection to VM was disconnected the process automatically gets closed. To make application working SSH needs to be opened always which is not possible. Is there any alternative method to keep it running as background service.
This happens because processes that are merely backgrounded will be sent a SIGHUP signal when their controlling terminal (the SSH connection) is closed.
The traditional method of preventing this is using the nohup utility:
nohup geddy -e production &
Alternatively, you can use terminal multiplexers like screen or tmux to create persistent terminal sessions (ones that remain active when you log out, and that can be reattached when you log in again at a later time).

Start a server running with screen in a vagrant box

I'm trying to run a server automatically when my vagrant box boots.
Similar to start screen detached in a vagrant box with ssh, how?, except I'm trying to do it with a provisioning script set to run: "always".
I'm doing something like this: nohup screen -S server -mL -d bash -c 'start-my-server.sh'.
The server starts fine, and if I would have done this within the shell, I could switch to the server with screen -r server.
When I go in after with vagrant ssh, it doesn't find any screens...I'm assuming this is because its not the same shell session.
Is there anyway to get a hold of that screen session?
Edit
Forgot to mention that I had prefixed the screen command with nohup
The answer is that vagrant provision was running as a privileged user, and therefore I couldn't see the screen logging in as the vagrant user.

Resources