서비스를 시작하는 기본 스크립트는 다음과 같습니다.
#!/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 방법 : /etc/init.d/your-script (또는 링크)에 넣으십시오. 실행 파일을 만들고 init 서비스에 추가하십시오.
$ sudo chmod +x /etc/init.d/your-script
$ sudo update-rc.d your-script defaults
이제 서비스를 시작하고 중지 할 수 있습니다.
$ sudo your-script start
$ sudo your-script stop