Monday, May 13, 2024
 Popular · Latest · Hot · Upcoming
8
rated 0 times [  8] [ 0]  / answers: 1 / hits: 6667  / 1 Year ago, sun, january 15, 2023, 7:14:23

So I am getting properly confused on how to create a startup script on my Ubuntu 11.10 server. I have read about init-scripts, upstart-jobs and more, but I get even more confused the more I read.



I've tried various guides, but I just haven't found anyone that actually work.



Can someone show me how I create a simple script that will work in 11.10?


More From » 11.10

 Answers
3

Marty Fried's answer contains the one most valuable info: the Cookbook. Reading thru that makes you more than able to write your init scripts.



However, messing with init.d, rc*.d, chkconfig et al, is not what you want to do. On Ubuntu (and other distros), they're just remains of the old sysvinit stuff which many packages still use or just support for legacy reasons. YOU DON'T NEED OR WANT TO GO THERE :-)



Simplest of all Upstart scripts is starting a daemon (put it in /etc/init/mydaemon.conf):



exec /path/to/binary


Thats ALL you need. That makes Upstart run the daemon when you do start mydaemon.



OK, you want it to start automatically? Usually, starting after dbus is a logical choise, so lets do that:



start on started dbus
stop on stopping dbus
exec /path/to/binary


This simple script starts your daemon whenever dbus has started and will stop it just before dbus stops.



You want it to respawn (re-launch) if it crashes? No problem, just add respawn on its own line to the file.



Your daemon forks or daemonizes itself? Well lets catch it nonetheless! Add expect fork in case of single fork, or expect daemon in case of true (double-fork) daemonization.



Lets summarize a simple startup script for your daemon:



author "Your name goes here - optional"
description "What your daemon does shortly - optional"

start on started dbus
stop on stopping dbus

# console output # if you want daemon to spit its output to console... ick
respawn # it will respawn if crashed/killed

exec /path/to/binary


In case you don't wanna run a daemon, but just a series of commands, lets forget the exec line and add a script section:



script
echo "Hello world!"
end script


This makes Upstart run the script instead of the daemon. The script section is just a normal shell script, so you can do pretty much anything you want inside of it.



Hope it helps. Stick to the Upstart configuration files and don't mess with legacy sysv and you'll keep sane :-)


[#40910] Monday, January 16, 2023, 1 Year  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
nerta

Total Points: 414
Total Questions: 103
Total Answers: 97

Location: England
Member since Wed, Apr 19, 2023
1 Year ago
nerta questions
Thu, May 12, 22, 16:04, 2 Years ago
Thu, Dec 2, 21, 09:19, 3 Years ago
Thu, May 27, 21, 00:41, 3 Years ago
Sun, Dec 11, 22, 08:33, 1 Year ago
;