Quantcast
Channel: Active questions tagged ubuntu - Stack Overflow
Viewing all articles
Browse latest Browse all 6025

Check if service exists in bash (CentOS and Ubuntu)

$
0
0

What is the best way in bash to check if a service is installed? It should work across both Red Hat (CentOS) and Ubuntu?

Thinking:

service="mysqld"if [ -f "/etc/init.d/$service" ]; then    # mysqld service existsfi

Could also use the service command and check the return code.

service mysqld statusif [ $? = 0 ]; then    # mysqld service existsfi

What is the best solution?


Viewing all articles
Browse latest Browse all 6025

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>