0

I already have a service that was written for RHEL6 and there i had some custom service commands that i can execute.Please see below for the extract from the script.

case "$1" in
    'start')
        start
        ;;
    'stop')
        stopit
        ;;
    'restart')
        stopit
        start
        ;;
    'status')
        status
        ;;
    'AppHealthCheck')
        AppHealthCheck
        ;;
    *)
        echo "Usage: $0 {  start | stop | restart | status | AppHealthCheck }"
        exit 1
        ;;
esac 

All the called method have there defination...So previously in RHEL6 if i had to execute the service and see if it is healthy i used to execute service $servicename AppHealthCheck .. and it used to work but now in RHEL7 i am not able to define in service unit file if i want to check say the AppHealth...As far as the research i have done i learnt that can define what will be called for service start/stop/restart but was not able to find if we can call any custom methods in the script..Please see my service unit file below:-

[Unit]
Description=SPIRIT Agent Application

[Service]
Type=forking
ExecStart=scripts/Agent start
ExecStop=scripts/Agent stop
ExecReload=scripts/Agent restart

[Install]

Can you one please help me in resolving this issue.Please let me know if more info is required.

iftekhar khan
  • 178
  • 12
  • do you get any specific error message when you invoke your code as shown? is `AppHealthCheck` defined by the time you call it in that case statement? – matias elgart Nov 21 '16 at 14:12
  • What does `AppHealthCheck` do, exactly? – John Kugelman Nov 21 '16 at 14:16
  • Yes it is defined... – iftekhar khan Nov 21 '16 at 14:17
  • @JohnKugelman - It called a method that is defined in a custom method i have created in the script – iftekhar khan Nov 21 '16 at 14:18
  • @JohnKugelman - This service checks if the pid of the service is present or not or basically if the service is running..but this is not relevant .. this question is for any custom command i want to execute on a service in RHEL7 – iftekhar khan Nov 21 '16 at 14:37
  • I ask because systemd may be able to do everything you're doing itself without any custom scripting. Systemd is capable of so much. For instance, programs don't need to daemonize themselves. Systemd is happy to do that for you if you just run your program in the foreground and write to stdout/stderr. No need for double forking, closing file descriptors, creating a pid file, managing a log file, etc. It can do all of that for you. – John Kugelman Nov 21 '16 at 14:51

2 Answers2

0

The systemd way is to send output to the journal so that systemctl status shows the latest log messages, and tells you if the service is running. If you want more detailed status, you would create a separate command-line command that does AppHealthCheck. It wouldn't be executed via systemctl, it'd be a separate thing.

This is how Pacemaker works, for example. systemctl status pacemaker shows if the service is running.

# systemctl status pacemaker
● pacemaker.service - Pacemaker High Availability Cluster Manager
   Loaded: loaded (/usr/lib/systemd/system/pacemaker.service; enabled; vendor preset: disabled)
   Active: active (running) since Thu 2016-11-10 15:28:11 GMT; 1 weeks 3 days ago

Nov 11 15:54:59 node1 crmd[4422]:   notice: Operation svc1_stop_0: ok (node=node1, call=93, rc=0, cib-update=134, confirmed=true)
Nov 11 15:54:59 node1 crmd[4422]:   notice: Operation svc2_stop_0: ok (node=node1, call=95, rc=0, cib-update=135, confirmed=true)
Nov 11 15:54:59 node1 crmd[4422]:   notice: Operation svc3_stop_0: ok (node=node1, call=97, rc=0, cib-update=136, confirmed=true)

pcs status gives more detailed information about how it's doing.

# pcs status
Cluster name: node
Stack: corosync
Current DC: node2 (version 1.2.3) - partition with quorum
2 nodes and 3 resources configured

Online: [ node1 node2 ]

Full list of resources:

 <snip>

PCSD Status:
  node1: Online
  node2: Online

Daemon Status:
  corosync: active/enabled
  pacemaker: active/enabled
  pcsd: active/enabled
John Kugelman
  • 349,597
  • 67
  • 533
  • 578
  • Even if i execute the custom command the way i used to do previously like service $servicename Appcheck the Appcheck case is getting called and it is working accordingly but if this Appcheck internally starts the service then i am not able to stop the service. – iftekhar khan Nov 22 '16 at 19:26
0

In RHEL7 we cannot define any custom service commands as we used to do or we can do in RHEL6 server. So even if we are calling any custom service command we have to internally call the 'service $servicename start' or 'systemctl start $servicename' so that the RHEL7 server can recognize that the service is running

iftekhar khan
  • 178
  • 12