Look at LSB init scripts for more information.
Modified to work with Chef
template "/etc/init.d/[NAME]" do
source "service.sh.erb"
mode 777
variables(name: NAME, user: USER, command: COMMAND, env: {})
end
directory "/var/log/[NAME]
mode 777
user USER
action :create
end
<NAME>
=$YOUR_SERVICE_NAME
<DESCRIPTION>
= Describe your service here (be concise)- Feel free to modify the LSB header, I've made default choices you may not agree with
<COMMAND>
= Command to start your server (for example/home/myuser/.dropbox-dist/dropboxd
)<USER>
= Login of the system user the script should be run as (for examplemyuser
)
Start and test your service:
service $YOUR_SERVICE_NAME start
service $YOUR_SERVICE_NAME stop
The service can uninstall itself with service $NAME uninstall
. Yes, that's very easy, therefore a bit dangerous. But as it's an auto-generated script, you can bring it back very easily. I use it for tests and often install/uninstall, that's why I've put that here.
Don't want it? Remove lines 56-58 of the service's script.
Your service will log its output to /var/log/$NAME/$NAME.log
. Don't forget to setup a logrotate :)