Failed to start <myapp>.service: Unit <myapp>.service not found

I created a super basic init.d script for my python bot:

#!/bin/bash
# chkconfig: 2345 20 80
# description: Description comes here....

# Source function library.
. /etc/init.d/functions

start() {
    echo "starting torbot"
    python /home/ctote/dev/slackbots/torbot/torbot.py
    # example: daemon program_name &
}

stop() {
    # code to stop app comes here
    # example: killproc program_name
}

case "$1" in
    start)
       start
       ;;
    stop)
       stop
       ;;
    restart)
       stop
       start
       ;;
    status)
       # code to check status of app comes here
       # example: status program_name
       ;;
    *)
       echo "Usage: $0 {start|stop|status|restart}"
esac

And have set torbot.py to be +x and #!/usr/local/bin/python at the top. When I try to actually start it though, I get:

:/var/lock/subsys$ sudo service torbot start Failed to start torbot.service: Unit torbot.service not found.

Am I missing something?


Solution 1:

If you are using ubuntu 16.04 or newer you may want to review the doc of systemd about creating service files

The script is for the old init system and is managed by a legacy compatibility layer.

Solution 2:

For me, I'm using Ubuntu 16.04.

Firstly change the init function

. /etc/init.d/functions

to

. /lib/lsb/init-functions

Then in shell, create symbolic links from /etc/rc* to my script:

sudo update-rc.d <myapp> defaults 95