Skip to content

mike-reinders/Control.Sh

Repository files navigation

Control.Sh

A shell script for running applications in foreground or background

Description

Control.sh is used for running applications in foreground or background.
Simply configure it within the Control.sh-file or within a control.cfg-file

Installation & Usage

Installation

Download or Clone: control.sh

  1. Download or Clone the Control.sh-file into your folder
  2. Execute apt-get update; apt-get install screen sudo in your putty/console/terminal.
  3. Configure your control.sh or create a control.cfg within the folder where your control.sh is located in

Commands

./control.sh start Starts the managed application
./control.sh stop Stops the managed application
./control.sh run Runs the managed application in foreground
./control.sh restart Restarts the managed application
./control.sh status Shows running status of the managed application
./control.sh last-exit-code Returns and displays the last exit code
./control.sh join Joins the application and exits when waittime was reached or application stops
./control.sh console Gets you into the console of the managed application
./control.sh help Displays help/all commands

Note:
When you use ./control.sh console and you want to get out, you only can leave the screen by using CTRL + A + D. Use it multiple times if it doesnt work! if you use CTRL + C it KILLS the managed application which might leads to data loss

Quick Configuration-Steps

Change following lines/variables:

42: SCREEN_NAME="ApplicationScreenName" # change it when using multiple applications under the same user
43: EXECUTION_FILE="startfile -parameter1 -parameter2" # your commandline
44: EXECUTING_USER="root" # under which user the commandline is executed

Configuration

There are two types of configuration sections:

  • >>> NOVICE-SETUP <<<     for simple configurations (contains 10 variables)
  • >>> ADVANCED-SETUP <<<     for advanced configurations (contains 2 variables, 1 function)

Simple Configuration

APPLICATION_NAME (Line 41)
  Specifies the name of the managed application.
  default: "Application-Server"

SCREEN_NAME (Line 42)
  Specifies the Screen-Name which is used to identify the managed application.
  Note: Every Character except Whitespaces, Dots and no lead with K_ are allowed.
  default: "ApplicationScreenName"

EXECUTION_FILE (Line 43)
  Specifies the command line your managed application shall run.
  default: "startfile -parameter1 -parameter2"

EXECUTING_USER (Line 44)
  Specifies the user under which the managed application and its' keeper is executed.
  Note: The specified user must be root or the user you'r going to run control.sh with.
  default: "root"

SCREEN_KEEPER (Line 46)
  Specifies whether the screen-keeper will be started on ./control.sh start
  The keeper restarts your application on exit.
  default: false

MIN_ELAPSED_TIME (Line 47)
  Specifies the time in seconds which has to be elapsed between start and exit
  of the managed application to consider the start as success.
  default: 30

MAXCOUNT_TIME_EXCEEDED (Line 48)
  Specifies how much times the keeper will restart your managed application after a failed start.
  default: 3

RESTART_DELAY (Line 49)
  Specifies the restart-delay the keeper waits until the managed application is restarted.
  default: 0

RESTART_ONFAILURE_ONLY (Line 50)
  Specifies whether the screen keeper only restarts the managed application on non-zero exit code.
  default: true

CONFIG_FILE (Line 52)
  Specifies the Configuration-File
  default: control.cfg

Advanced Configuration

NOT_RECOMMEND_FORCE_RUN (Line 56)
  Specifies whether the script does not run a distribution-check.
  defaukt: false

ENABLE_USERDEFINED_STOP (Line 58)
  Specifies whether the script executes the function userdefined_stop() instead of sending a unix SIGTERM signal
  when stopping the managed application.
  default: false

function userdefined_stop() (Line 59)
  Contains the routine which is executed when stopping the managed application.
  Note: After execution the managed application has got 10 seconds to terminate
            until the normal shutdown routine is beeing executed.
  default: (empty)

function custom_printlog() (Line 59)
  Contains the routine which is executed when logging a message.
  Parameter:   default: (empty)