Create Custom Service in Ubuntu

When developing software application on linux, instead of creating custom scripts it could be easier to invoke them as a service.

Creating a custom service is very easy (for Debian based distro’s).

Create a file in the following folder: /etc/init.d/myService Make it executable:

chmod u+x /etc/init.d/myService*

Edit it:

start() {
        echo "Starting myService"
}

stop() {
        echo "Stopping myService"
}

restart() {
        stop
        start
}

case "$1" in 
start)
        start
;;
stop)
        stop
;;
restart)
        restart
;;

*)

echo $"Usage: $0 {start|stop|restart}"

Now just run the following in your bash:

$ service myService start
comments powered by Disqus