Um script básico para iniciar um serviço pode ser assim:
#!/bin/sh
# This is for the 'update-rc.d', so it knows when to start your service.
### BEGIN INIT INFO
# Provides: your-script
# Required-Start: $all
# Required-Stop:
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: a short description
# Description: a long description
### END INIT INFO
COMMAND="echo -n 'I am: '; whoami"
log () {
echo "$@"
logger -p user.info -t "ClueReleaseManager [$$]" "$@"
}
main () {
case "$1" in
stop)
# stop your service
echo "Stopping"
;;
start)
# run your service as user pypi
# doesn't need password as root
echo "Starting"
# you probably want to start it in background
# (don't block the other services)
(su - pypi -c "$COMMAND") &
;;
restart|force-reload)
# restart your service
echo "Restarting"
;;
*)
# wrong command
echo "Unknown command: '$1'"
;;
esac
}
# If you want, you can even log the whole.
# Unless you changed it it should go to /var/log/syslog
main "$1" 2>&1 | log
# Better exit with success, not sure if this can screw up Ubuntus boot process.
exit 0
update-rc.d como fazer: em /etc/init.d/your-script (ou link para ele). Torne executável e adicione aos serviços de inicialização:
$ sudo chmod +x /etc/init.d/your-script
$ sudo update-rc.d your-script defaults
Agora você pode iniciar e interromper seu serviço:
$ sudo your-script start
$ sudo your-script stop