Skip to content
David Kittell
David Kittell

Application & System: Development / Integration / Orchestration

  • Services
    • Application Development
    • Online Application Integration
  • Code
  • Online Tools
  • Tech Support
David Kittell

Application & System: Development / Integration / Orchestration

UNIX – Start Service If Not Running

Posted on February 2, 2018June 18, 2019 By David Kittell

Currently this script is developed for my Raspberry Pi (Debian, Raspbian) but in time I will have it working for RHEL (Red Hat, CentOS, Fedora).

service=openvpn
running=$(ps -ef | grep -v grep | grep $service | wc -l)
#echo $running
if [ "$running" = 1 ]; then
  echo "$service is running!!!";
else
  echo "Starting $service!!!";
  sudo /etc/init.d/$service start
fi

sudo netstat -uapn | grep openvpn

In the example above I’m checking if OpenVPN is running, if it is not running it will start the service.

I set this script up as CheckOpenVPN.sh in my /opt directory so I can simply run the below.

sudo sh /opt/CheckOpenVPN.sh
Originally Posted on February 2, 2018
Last Updated on June 18, 2019
All information on this site is shared with the intention to help. Before any source code or program is ran on a production (non-development) system it is suggested you test it and fully understand what it is doing not just what it appears it is doing. I accept no responsibility for any damage you may do with this code.

Related

Code Raspberry Pi Raspbian (Raspberry Pi OS) UNIX UNIX Shell Scripts

Post navigation

Previous post
Next post

Related Posts

Drop Table If Exists

Posted on March 19, 2013October 26, 2015

IF OBJECT_ID(‘HLM_holdkey’, ‘U’) IS NOT NULL DROP TABLE HLM_holdkey Originally Posted on March 19, 2013Last Updated on October 26, 2015 All information on this site is shared with the intention to help. Before any source code or program is ran on a production (non-development) system it is suggested you test…

Read More

JSON – Pull #FIRSTInspires data from @thebluealliance API

Posted on April 16, 2018March 9, 2020

Working on a couple tasks that need team information so I registered a read-only API key and started pulling down data for an offline app. Initially populating data using bash and jq. This may be cleaned up in time but it works for my purpose for now. Currently I’m just…

Read More

File Extension

Posted on October 17, 2013October 26, 2015

If you are working in a database that has asset/file storage and need to get just the extension of the column this query will help save time. SELECT CASE WHEN filepath LIKE ‘%.%’ THEN RIGHT(filepath, Len(filepath) – Charindex(‘.’, filepath)) ELSE filepath END FilePath FROM tbl1 Originally Posted on October 17,…

Read More

Code

Top Posts & Pages

  • PowerShell - Rename Pictures to Image Taken
  • Front Page
  • C# - Start/Stop/Restart Services
  • MacPorts / HomeBrew - Rip CD tracks from terminal
  • PowerShell - Show File Extensions

Recent Posts

  • Javascript – Digital Clock with Style
  • BASH – Web Ping Log
  • BASH – Picture / Video File Name Manipulation
  • Mac OSX Terminal – Create SSH Key
  • Bash – Rename Picture

Top Posts

  • PowerShell - Rename Pictures to Image Taken
  • C# - Start/Stop/Restart Services
  • MacPorts / HomeBrew - Rip CD tracks from terminal
  • PowerShell - Show File Extensions
  • Open On Screen Keyboard (OSK)
  • SQLite - Auto-Increment / Auto Generate GUID
©2025 David Kittell | WordPress Theme by SuperbThemes