Skip to main content

Run other programs in background

Project description

backrun

Run other (whitelisted) scripts (tasks) in background (and maybe as another userid) and save stdout/stderr in log. You may need this when you want to start other long-running scripts (like sync databases) from web-UI.

Install

# for this user only
pipx install backrun

# for all users
sudo PIPX_HOME=/opt/pipx PIPX_BIN_DIR=/usr/local/bin pipx install backrun

# old fashioned way
pip3 install backrun

Run background tasks

Prepare config file backrun.toml, and run backrun.

When you need to start some background process, do this:

echo script1 > /var/backrun/task/123

This will create task file to run script1 with id 123.

Almost immediately backrun will start to execute script and write stdout/stderr to /var/backrun/tasklog/123.log.

When script will finish, backrun will delete task file.

Details

Script will be executed with uid of backrun script.

script will get environment of backrun. backrun will set two new environment variables for script: TASKID - if of task (e.g. "123"), TASKFILE - path to task file.

Backrun reads only first like of taskfile, so you can put everything (any text, YAML, JSON) starting with 2nd line and script can read it.

Example files

config file

Config file name is either passed as first argument to backrun or first existing file in: ./backrun.toml, ~/backrun.toml, /etc/backrun.toml.

taskdir = "/var/backrun/task"
logdir = "/var/backrun/tasklog"
sleep = 1
logfile = '/var/backrun/backrun.log'

[scripts]
    [scripts.script1]
    path="/usr/local/bin/script1.sh"

script file (script1.sh)

#!/bin/bash

log(){
    echo `date "+%Y-%m-%d %H:%M:%S"` $*
}

log started
sleep 10
>&2 log "error"
log finished

systemd service file

change User and ExecStart

[Unit]
Description=backrun: run whitelisted scripts in background

[Service]
ExecStart=/usr/local/bin/backrun
User=xenon

[Install]
WantedBy=multi-user.target

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

backrun-0.0.2.tar.gz (4.9 kB view details)

Uploaded Source

Built Distribution

backrun-0.0.2-py3-none-any.whl (4.1 kB view details)

Uploaded Python 3

File details

Details for the file backrun-0.0.2.tar.gz.

File metadata

  • Download URL: backrun-0.0.2.tar.gz
  • Upload date:
  • Size: 4.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: python-httpx/0.25.2

File hashes

Hashes for backrun-0.0.2.tar.gz
Algorithm Hash digest
SHA256 d7c274cb3d40e5120b01555f62c16d482cf2f1be332c33c252b7dd13d21b0c5b
MD5 45eef62c2cebb6ddaf6b050be36cf9a7
BLAKE2b-256 3e9ba46cda08bdf015560d884a1c672df582076c1f60b80018f2fd37a0de7dc6

See more details on using hashes here.

File details

Details for the file backrun-0.0.2-py3-none-any.whl.

File metadata

  • Download URL: backrun-0.0.2-py3-none-any.whl
  • Upload date:
  • Size: 4.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: python-httpx/0.25.2

File hashes

Hashes for backrun-0.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 5fb36ef7af102ae3044650f3c22edb0ddd95f1376f595a0414782c5b9137cc6e
MD5 f785706099c5526c417f1793160ec8f2
BLAKE2b-256 86e601fdde8791afd74264d5da8caf8950128aa66c60737c1fec1bd7964eb9b1

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page