Sample Header Ad - 728x90

systemctl stop service doesn't work

2 votes
1 answer
8022 views
I wrote this service in/etc/systemd/system called nexusiq.service:
[Unit]
Description=Nexus IQ Service
After=network.target

[Service]
Type=simple
ExecStart=/etc/init.d/nexus-iq-server start
ExecStop=/etc/init.d/nexus-iq-server stop
User=root
Restart=on-abort
TimeoutSec=600

[Install]
WantedBy=multi-user.target
The script nexus-iq-server in /etc/init.d that is invoked in ExecStart and ExecStop, depending on whether I give "start" or "stop" as argument does the following:
NEXUS_IQ_SERVER_HOME=/apps/nexus/nexus-iq-server
VERSION=1.127.0-01
JAVA_OPTIONS="-Xmx4096m -XX:+UseG1GC"
RUN_AS_USER=root

do_start()
{
    cd $NEXUS_IQ_SERVER_HOME
    su -m $RUN_AS_USER --command "java $JAVA_OPTIONS -jar nexus-iq-server-$VERSION.jar server config.yml 2> stderr.log &"
    echo "Started nexus-iq-server"
}

do_console()
{
    cd $NEXUS_IQ_SERVER_HOME
    su -m $RUN_AS_USER --command "java $JAVA_OPTIONS -jar nexus-iq-server-$VERSION.jar server config.yml 2> stderr.log"
}

do_stop()
{
    pid=ps aux | grep nexus-iq-server | grep '.jar server' | grep -vE '(stop|grep)' | awk '{print $2}'
    kill $pid
    echo "Killed nexus-iq-server - PID $pid"
}

do_usage()
{
    echo "Usage: nexus-iq-server [console|start|stop]"
}

case $1 in
    console)
        do_console
        ;;
    start)
        do_start
        ;;
    stop)
        do_stop
        ;;
    *)
        do_usage
        ;;
esac
I have enabled the service. When I run the command: systemctl start nexusiq the command assigned to ExecStart is correctly invoked. But, if i run the command systemctl stop nexusiq, the command assigned to ExecStop is not invoked. Furthermore, if I run the command systemctl status nexusiq, looks like the service is inactive:
● nexusiq.service - Nexus IQ Service
   Loaded: loaded (/etc/systemd/system/nexusiq.service; enabled; vendor preset: disabled)
   Active: inactive (dead) since Wed 2021-11-17 12:56:03 CET; 16s ago
  Process: 14806 ExecStop=/etc/init.d/nexus-iq-server stop (code=exited, status=0/SUCCESS)
  Process: 14800 ExecStart=/etc/init.d/nexus-iq-server start (code=exited, status=0/SUCCESS)
 Main PID: 14800 (code=exited, status=0/SUCCESS)

Nov 17 12:56:03 nexusiq2 systemd: Started Nexus IQ Service.
Nov 17 12:56:03 nexusiq2 su: (to root) root on none
Nov 17 12:56:03 nexusiq2 nexus-iq-server: Started nexus-iq-server
Can anyone explain to me what is causing this, and how to fix it?
Asked by Nicola Auricchio (21 rep)
Nov 17, 2021, 11:58 AM
Last activity: Nov 20, 2021, 10:21 AM