Git Product home page Git Product logo

bash-service-manager's Introduction

Bash Service Manager

Bash Script's for Service Manager

Create your custom service for development.

Usage

  1. Create your service script.
  2. Define the configuration environment variables: PID_FILE_PATH, LOG_FILE_PATH and LOG_ERROR_FILE_PATH.
  3. Define the configuration variables
    • Mandatory configuration variables: $action, $serviceName, $command (array)
    • Optional configuration variables: $workDir, $onStart (array), $onFinish (array)
  4. Copy services.sh content or import it.
  5. Call serviceMenu function
  6. Make your new service script executable: chmod a+x my-service-script
  7. Use it!

Configuration Environment Variables

PID_FILE_PATH

Configure the PID_FILE_PATH variable before import service.sh script, and define the PID file path.

LOG_FILE_PATH

Configure the LOG_FILE_PATH variable before import service.sh script, and define the LOG file path.

LOG_ERROR_FILE_PATH

Configure the LOG_ERROR_FILE_PATH variable before import service.sh script, and define the ERROR file path.

Configuration Variables

Mandatory Configuration Variables

action

This is the action to execute. Please see Actions section below for more information.

If it is an invalid action or emtpy action, you can see the help.

serviceName

This is the user friendly Service Name.

command (array variable)

This is the commands that you must execute to start your service.

Optional Configuration Variables

workDir

The working directory is set, where it must be located to execute the command.

onStart (array variable)

Commands to execute before Service start.

If function exit code is not 0 (zero), the service will not started.

onFinish (array variable)

Commands to execute after Service finish/exit.

servicesMenu function

Just call only this function to make everything work!

Actions

If it is an invalid action or emtpy action, you can see the help.

  • start: Start the service.
  • stop: Stop the service.
  • restart: Restart the service. If the service is running, first call stop then call start.
  • status: Get service status.
  • tail: See all service output.
  • tail-log: See service std output.
  • tail-error: See service err output.
  • run: Execute service command and exit (this action does not stop the service).
  • debug: Stop service (if running) and run service command and exit.

Examples

Telegraf Service

telegraf.sh file:

#!/usr/bin/env bash

appDir=$(cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null && pwd)

export LOG_FILE_PATH="$serviceName.log"
export LOG_ERROR_FILE_PATH="$serviceName.error.log"
export PID_FILE_PATH="$serviceName.pid"

. "$appDir/services.sh"

# Action to execute (mandatoty)
action="$1"  
# Friendly service name (mandatoty)
serviceName= "telegraf"
# Command to run (mandatoty, array variable)
command=(./telegraf --config telegraf.conf)
# Working Directory (optional)
workDir="$appDir"
# On start (optional, array variable)
#onStart=()
# On finish (optional, array variable)
#onFinish=()

serviceMenu

In console:

$ telegraf.sh status
$ telegraf.sh restart

Custom Service

my-service file:

#!/usr/bin/env bash

export PID_FILE_PATH="my-service.pid"
export LOG_FILE_PATH="my-service.log"
export LOG_ERROR_FILE_PATH="my-service.error.log"

. ./services.sh

# Action to execute (mandatoty)
action="$1"  
# Friendly service name (mandatoty)
serviceName="Example Service"
# Command to run (mandatoty, array variable)
command=("ping 1.1.1.1")
# Working Directory (optional)
#workDir=
# On start (optional, array variable)
#onStart=()
# On finish (optional, array variable)
#onFinish=()

serviceMenu

bash-service-manager's People

Contributors

artemiuss avatar reduardo7 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.