root@ubuntu-server:~# cat /etc/init/job1.conf
# Start when the loading modules have concluded
start on stopped load-modules
# Start when the filesystem is mounted
start on filesystem
# Start when the filesystem is mounted and the network is started
start on filesystem and started network
# Start under the runlevels 2, 3 and 5
start on runlevel [235]
...
The initctl utility allows to pass down a concrete event.
root@ubuntu-server:~# initctl emit myevent
If we take a look at the files dropped off within the /etc/init directory, we will be able to find out many other events. For instance, if we open the mountall.conf file, we can see that this job mounts the filesystems during the boot and emits events as local-filesystems, all-swaps, etc.
All the theory described for "start on", also can be applied when we want to stop a job.
root@ubuntu-server:~# cat /etc/init/job1.conf
stop on starting shutdown
...
This command as well can be used to list the status of all jobs handled by Upstart.
root@ubuntu-server:~# initctl list
mountall-net stop/waiting
rc stop/waiting
rsyslog start/running, process 687
...
Another interesting configuration option is the respawn tag, which is utilized to start automatically a job if it stops abnormally. We can also set that if a job is respawned more that X times in Y seconds, it will be stopped definitely.
root@ubuntu-server:~# cat /etc/init/job1.conf
respawn
respawn limit 10 120
...
What happens if we want to perform some previous task to start a job? For this case, Upstart provides the pre-start directive, which is run before the job reaches the starting state.
root@ubuntu-server:~# cat /etc/init/job1.conf
pre-start script
rm /tmp/job*
end script
...
Instead of a script, we can also execute a binary.
root@ubuntu-server:~# cat /etc/init/job1.conf
pre-start exec /usr/local/sbin/nessusd
...
In addition, we can specify other kinds of pre/post actions.
root@ubuntu-server:~# cat /etc/init/job1.conf
# Before the job is started
post-start exec|script
# Before the job is stopping
pre-stop exec|script
# Before the job is stopped
post-stop exec|script
...
You can get more information as always... by accessing the man.
root@ubuntu-server:~# man 5 init
No comments:
Post a Comment