1 # Getting Started with Dinit
3 In this guide we will go through the steps required to set up a tiny user-mode
6 We assume that dinit has already been installed; i.e. we only cover
11 Let's start by running dinit with the bare minimum configuration. First we need
12 to choose a place for our service descriptions to live. For this guide we are
13 going to use the default location (for user-mode), which is `~/dinit.d`.
20 Next we need a service description for the `boot` service. This is the service
21 that dinit will bring up upon starting.
23 In a file called `boot` (under the directory we just made) put:
29 The first line tells dinit that this is not a service which will run anything
32 The second line specifies a directory which will be used to keep track of which
33 services should be enabled at dinit start time. Here we've made it a `boot.d`
34 sub-directory under our main dinit directory, but it can be anywhere you like.
36 Now let's make the aforementioned directory and start dinit for the first time.
37 Assuming you are still in `~/dinit.d`:
47 In the long run, you'll want to find a way to invoke dinit at boot time, but
48 that's an exercise for the reader.
50 ## Adding Service Descriptions
52 So we have dinit running, but it currently has no services to supervise. Let's
53 give it something to do.
55 Suppose we want to run mpd under dinit. Put the following in ` ~/dinit.d/mpd`:
58 command = /usr/local/sbin/mpd --no-daemon
62 Now run `dinitctl list`:
68 The mpd service isn't visible yet because dinit lazily loads services. If we
69 start the service, we will see it in the list:
75 [{+} ] mpd (pid: 14823)
78 Now let's simulate mpd crashing and check dinit brings it back up:
83 On the dinit log, we see:
89 And if we query dinit for its status, we see:
93 [{+} ] mpd (pid: 1667)
96 Notice that a new instance of mpd is running; it has a different pid.
98 You can stop a service using `dinitctl stop`:
105 Here the "slider" for the mpd service has been moved to the right to signify
106 that it has been switched off.
108 ## Starting Services at Startup
110 So far we've configured a service which can be brought up and down in an ad-hoc
111 fashion. This would be ideal for (for example) SSH tunnels, but mpd is the kind
112 of daemon you want to *always* run.
114 To that end, to start a service at the time dinit starts, we can use `dinitctl
115 enable`. This will start the service immediately *and* make sure it starts by
120 $ dinitctl enable mpd
123 [{+} ] mpd (pid: 49921)
126 If we now restart dinit:
130 [{+} ] mpd (pid: 17601)
133 mpd was started when dinit started.
135 And if you look in the `waits-for.d` directory we configured earlier you will
136 find a symlink to the mpd service description file. This is how dinit keeps
137 track of what should be started by default.
141 In this guide, we've really only scratched the surface of what dinit can do.
142 For example, we've not even touched on dependencies (where one service depends
143 upon another to function). Next it'd be good to read the `dinit-service(5)` and
144 `dinitctl(8)` manual pages.