Skip to content

Instantly share code, notes, and snippets.

@tomkralidis
Last active April 19, 2018 16:39
Show Gist options
  • Save tomkralidis/f2e58b18c84107927b7fc0a1be47095e to your computer and use it in GitHub Desktop.
Save tomkralidis/f2e58b18c84107927b7fc0a1be47095e to your computer and use it in GitHub Desktop.
Generic service controller for init.d
#! /bin/sh
# /etc/init.d/pygeoapi
PROGRAMNAME=pygeoapi
check_service() {
ps cax | grep $PROGRAMNAME > /dev/null
if [ $? -eq 0 ]; then
return 0
else
return 1
fi
}
start_service() {
if check_service 0; then
echo "* $PROGRAMNAME is already running"
return
fi
echo "* Starting $PROGRAMNAME"
$PROGRAMNAME serve &
}
stop_service() {
if check_service; then
echo "* Stopping $PROGRAMNAME"
pkill -f $PROGRAMNAME || errcode=$?
return 0
else
echo "* $PROGRAMNAME is already stopped"
return 1
fi
}
case "$1" in
start)
start_service
;;
stop)
stop_service
;;
restart)
stop_service
start_service
;;
status)
if check_service; then
echo "* $PROGRAMNAME is running"
else
echo "* $PROGRAMNAME is stopped"
fi
;;
*)
echo "Usage: $PROGRAMNAME {start|stop|restart|status}"
exit 1
;;
esac
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment