4k3or3et
Posts: 126
Joined: Sat Nov 17, 2018 5:47 pm

Process as a service...

Sat Jun 06, 2020 9:29 am

Hi all.

I am trying to run process as a service. Lets say i want to run mousepad as a service (it is just an example for trainings purposes).

I found that i have have to create a script in '/etc/init.d' like this:

Code: Select all

#!/bin/bash
. /etc/init.d/functions
start() {
        initlog -c "echo -n Starting... "
        mousepad
        success $"abc123 server startup"
        echo
}
stop() {
        initlog -c "echo -n Stopping... "
        pkill -f mousepad
        echo
}
case "$1" in
  start)
        start
        ;;
  stop)
        stop
        ;;
  status)
        status abc123
        ;;
  restart|reload|condrestart)
        stop
        start
        ;;
  *)
        echo $"Usage: $0 {start|stop|restart|reload|status}"
        exit 1
esac
exit 0
The service is called 'abc123'.

When i try to start it by 'service abc123 start' i get:

Code: Select all

Failed to start abc123.service: Unit abc123.service not found.
Anyone can point me what i am doing wrong here?

Thank you.

User avatar
DougieLawson
Posts: 38863
Joined: Sun Jun 16, 2013 11:19 pm
Location: A small cave in deepest darkest Basingstoke, UK
Contact: Website Twitter

Re: Process as a service...

Sat Jun 06, 2020 9:35 am

You've built an old SYSV script. Don't do that. Build a systemd service, they're easier and have better options for what user a process runs as.

viewtopic.php?t=197513
Note: Any requirement to use a crystal ball or mind reading will result in me ignoring your question.

Criticising any questions is banned on this forum.

Any DMs sent on Twitter will be answered next month.
All non-medical doctors are on my foes list.

4k3or3et
Posts: 126
Joined: Sat Nov 17, 2018 5:47 pm

Re: Process as a service...

Sat Jun 06, 2020 11:40 am

Thanks man. Managed to sort it out.

Return to “Advanced users”