1

I managed to create a systemd service script, which enables my application to run in the background...
This systemdscript used %i in order to start specific instances of this service.
I'm searching for a way to stop all instances of my script.
sudo service servicename@* stop isn't working...
ExecStart runs a script which runs a java application

Any help is appreciated

2
  • Try sudo systemctl stop nameofservice. It's generally wiser to use systemctl to control systemd services. Feb 19, 2017 at 19:24
  • Unfortunately this isn't working either... I already tried that
    – RoiEX
    Feb 19, 2017 at 19:26

3 Answers 3

1

The command you are looking for is:

sudo killall nameofservice

You can use tab to autocomplete.

7
  • Hmm unfortunately this isn't working for me... I tried servicename@ and servicename
    – RoiEX
    Feb 19, 2017 at 19:25
  • @RoiEX What is the output of the command? Feb 19, 2017 at 19:27
  • Oh wait... I wanted to write that, it's "process not found"... Not sure if this is completely correct, since my xubuntu isn't in english
    – RoiEX
    Feb 19, 2017 at 19:29
  • I want to mention, that my script actually runs a script running a java application... I will edit my question
    – RoiEX
    Feb 19, 2017 at 19:30
  • 1
    @RoiEX What is the name of the script file you created that service uses to start the application? Feb 19, 2017 at 19:31
1

You better use

sudo killall -9 nameofservice

Of course you need to know the name of the service which is not necessarily equal to its init.d script name.

The parameter -9 of the killall command is explained in the manual page

man 7 signal

Just enter it at the command line to get:

First the signals described in the original POSIX.1-1990 standard.

   Signal     Value     Action   Comment
   ──────────────────────────────────────────────────────────────────────
   SIGHUP        1       Term    Hangup detected on controlling terminal
                                 or death of controlling process
   SIGINT        2       Term    Interrupt from keyboard
   SIGQUIT       3       Core    Quit from keyboard
   SIGILL        4       Core    Illegal Instruction
   SIGABRT       6       Core    Abort signal from abort(3)
   SIGFPE        8       Core    Floating point exception
   SIGKILL       9       Term    Kill signal
   SIGSEGV      11       Core    Invalid memory reference
   SIGPIPE      13       Term    Broken pipe: write to pipe with no
                                 readers
   SIGALRM      14       Term    Timer signal from alarm(2)
   SIGTERM      15       Term    Termination signal
   SIGUSR1   30,10,16    Term    User-defined signal 1
   SIGUSR2   31,12,17    Term    User-defined signal 2
   SIGCHLD   20,17,18    Ign     Child stopped or terminated

   SIGCONT   19,18,25    Cont    Continue if stopped
   SIGSTOP   17,19,23    Stop    Stop process
   SIGTSTP   18,20,24    Stop    Stop typed at terminal
   SIGTTIN   21,21,26    Stop    Terminal input for background process
   SIGTTOU   22,22,27    Stop    Terminal output for background process

   The signals SIGKILL and SIGSTOP cannot be caught, blocked, or ignored.
3
  • This seems to work... I just have a smaller problem and a question... What is the -9 doing? And how would I fix the problem, that my service is being restarted (because normally I want it to restart)
    – RoiEX
    Feb 19, 2017 at 19:47
  • I extended my answer. To prevent the service from restarting you have to use another approach: Try service nameofservice stop. This applies if your service is restarted immediately and not at the next reboot. In the latter case you'd have to remove the corresponding /etc/init.d/... script or adjust the /etc/rc.* runlevel links.
    – zx485
    Feb 19, 2017 at 19:58
  • I found a solution myself... Thanks though!
    – RoiEX
    Feb 19, 2017 at 20:04
1

Thanks for all your suggestions, but I found an answer here: https://serverfault.com/a/797926
The problem was, that my asterisk was escaped by bash...
When using sudo service 'servicename@*' stop everything works as expected

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .