Tuesday, August 30, 2022

[SOLVED] Running a script in screen through Rundeck

Issue

I have a mostly working job on rundeck which near the end attempts to open a screen with the command

screen -S s1

However I see the error in my rundeck logs

must be connected to terminal

The screen does not get created

Is there a way to simulate connection to terminal through rundeck, or a different way I could be structuring the command? My end goal is to run a script inside the screen, so that when the job ends the script continues to run. The target server runs on Centos 7.6


Solution

Rundeck doesn't work as a terminal screen manager or as a interactive shell, that's because screen opens a new multiplexed terminal, Rundeck works more like a script interpreter focused on automation, the easiest way to run a script is on a step (inline-script) on your job, and call it with some interpreter (bash, python, etc).

I leave an example:

<joblist>
  <job>
    <defaultTab>nodes</defaultTab>
    <description></description>
    <executionEnabled>true</executionEnabled>
    <id>bfd52579-5161-4003-8cf4-ac570fbf5e7b</id>
    <loglevel>INFO</loglevel>
    <name>HelloWorld</name>
    <nodeFilterEditable>false</nodeFilterEditable>
    <plugins />
    <scheduleEnabled>true</scheduleEnabled>
    <sequence keepgoing='false' strategy='node-first'>
      <command>
        <fileExtension>.sh</fileExtension>
        <script><![CDATA[#!/bin/sh
echo "hi"]]></script>
        <scriptargs />
        <scriptinterpreter>/bin/bash</scriptinterpreter>
      </command>
    </sequence>
    <uuid>bfd52579-5161-4003-8cf4-ac570fbf5e7b</uuid>
  </job>
</joblist>


Answered By - MegaDrive68k
Answer Checked By - Willingham (WPSolving Volunteer)