summaryrefslogtreecommitdiffstats
path: root/meta-skeleton
diff options
context:
space:
mode:
authorRobert Yang <liezhi.yang@windriver.com>2011-05-16 21:57:21 -0600
committerRichard Purdie <richard.purdie@linuxfoundation.org>2011-05-18 14:32:45 +0100
commitffef4dad894a6c8401ea0409936f52fe8e333fb2 (patch)
treeed4b3861494446ba42e1a8fafe9c629811c2aa51 /meta-skeleton
parent0424560e5fb00ad5e455af82425143d87a37bcc7 (diff)
downloadpoky-ffef4dad894a6c8401ea0409936f52fe8e333fb2.tar.gz
Add a skeleton for init scripts
Add a skeleton for init scripts, the original structure is from /etc/init.d/skeleton of Ubuntu 10.10, it is in sysvinit_2.87dsf, so add the COPYRIGHT(GPLv2) of sysvinit_2.87dsf. Modified the original skeleton a lot to make it as easy as possible, just use posix shell command, and have tested it with core-image-minimal. * The skeleton implements the following actions: - start, stop, restart, status, try-restart and force-reload. # force-reload is a alias of try-restart. - not implements reload, since only a few programs have it, just leave it as placeholder. * Add /usr/sbin/skeleton-test to test /etc/init.d/skeleton * The /etc/init.d/skeleton can be run and output the example messages: 1) #./skeleton start (test start) Starting skeleton ... 2) #./skeleton start (test start again when running) skeleton already running (1078). 3) #./skeleton status (test status when running) skeleton is running (1078). 4) #./skeleton stop (test stop) Stopped skeleton (1078). 5) #./skeleton stop (test stop again) skeleton is not running; none killed. 6) #./skeleton status (test status when stopped) skeleton is not running. 7) #./skeleton restart (test restart when running) Stopped skeleton (1128). Starting skeleton ... 8) #./skeleton restart (test restart when stopped) skeleton is not running; none killed. Starting skeleton ... 9) try-restart (or force-reload) means restart the service if the service is already running #./skeleton try-restart (test try-restart when stopped) skeleton is not running; none killed. #./skeleton try-restart (test try-restart when running) Stopped skeleton (1181). Starting skeleton ... * Have used syslogd to test it in a real world(with both core-image-minimal and core-image-sato) (From OE-Core rev: c1b6f840ad7c483e905f9a19eb2b5a8eac0b9973) Signed-off-by: Robert Yang <liezhi.yang@windriver.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'meta-skeleton')
-rw-r--r--meta-skeleton/recipes-skeleton/service/service/COPYRIGHT15
-rw-r--r--meta-skeleton/recipes-skeleton/service/service/skeleton193
-rw-r--r--meta-skeleton/recipes-skeleton/service/service/skeleton_test.c12
-rw-r--r--meta-skeleton/recipes-skeleton/service/service_0.1.bb32
4 files changed, 252 insertions, 0 deletions
diff --git a/meta-skeleton/recipes-skeleton/service/service/COPYRIGHT b/meta-skeleton/recipes-skeleton/service/service/COPYRIGHT
new file mode 100644
index 0000000000..ec3e171131
--- /dev/null
+++ b/meta-skeleton/recipes-skeleton/service/service/COPYRIGHT
@@ -0,0 +1,15 @@
1Sysvinit is Copyright (C) 1991-2004 Miquel van Smoorenburg
2
3 This program is free software; you can redistribute it and/or modify
4 it under the terms of the GNU General Public License as published by
5 the Free Software Foundation; either version 2 of the License, or
6 (at your option) any later version.
7
8 This program is distributed in the hope that it will be useful,
9 but WITHOUT ANY WARRANTY; without even the implied warranty of
10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 GNU General Public License for more details.
12
13 You should have received a copy of the GNU General Public License
14 along with this program; if not, write to the Free Software
15 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
diff --git a/meta-skeleton/recipes-skeleton/service/service/skeleton b/meta-skeleton/recipes-skeleton/service/service/skeleton
new file mode 100644
index 0000000000..a3edc9d08d
--- /dev/null
+++ b/meta-skeleton/recipes-skeleton/service/service/skeleton
@@ -0,0 +1,193 @@
1#! /bin/sh
2### BEGIN INIT INFO
3# Provides: skeleton
4# Required-Start: $local_fs
5# Should-Start:
6# Required-Stop: $local_fs
7# Should-Stop:
8# Default-Start: 2 3 4 5
9# Default-Stop: 0 1 6
10# Short-Description: Example initscript
11# Description: This file should be used to construct scripts to be
12# placed in /etc/init.d
13### END INIT INFO
14
15# The definition of actions: (From LSB 3.1.0)
16# start start the service
17# stop stop the service
18# restart stop and restart the service if the service is already running,
19# otherwise start the service
20# try-restart restart the service if the service is already running
21# reload cause the configuration of the service to be reloaded without
22# actually stopping and restarting the service
23# force-reload cause the configuration to be reloaded if the service supports
24# this, otherwise restart the service if it is running
25# status print the current status of the service
26
27# The start, stop, restart, force-reload, and status actions shall be supported
28# by all init scripts; the reload and the try-restart actions are optional
29
30# Common steps to convert this skeleton into a real init script
31# 1) cp skeleton <the_real_name>
32# 2) Set DESC and NAME
33# 3) Check whether the daemon app is /usr/sbin/$NAME, if not, set it.
34# 4) Set DAEMON_ARGS if there is any
35# 5) Remove the useless code
36
37# NOTE: The skeleton doesn't support the daemon which is a script unless the
38# pidof supports "-x" option, please see more comments for pidofproc ()
39# in /etc/init.d/functions
40
41# PATH should only include /usr/* if it runs after the mountnfs.sh script
42PATH=/sbin:/usr/sbin:/bin:/usr/bin
43
44DESC="skeleton"
45NAME="skeleton-test"
46DAEMON=/usr/sbin/$NAME
47DAEMON_ARGS=""
48PIDFILE=/var/run/$NAME.pid
49
50. /etc/init.d/functions || exit 1
51
52# Exit if the package is not installed
53[ -x "$DAEMON" ] || exit 0
54
55# Read configuration variable file if it is present
56[ -r /etc/default/$NAME ] && . /etc/default/$NAME
57
58#
59# Function that starts the daemon/service
60#
61do_start() {
62 local status pid
63
64 status=0
65 pid=`pidofproc $NAME` || status=$?
66 case $status in
67 0)
68 echo "$DESC already running ($pid)."
69 exit 1
70 ;;
71 *)
72 echo "Starting $DESC ..."
73 exec $DAEMON $DAEMON_ARGS >/dev/null 2>&1 || status=$?
74 echo "ERROR: Failed to start $DESC."
75 exit $status
76 ;;
77 esac
78
79 # Add code here, if necessary, that waits for the process to be ready
80 # to handle requests from services started subsequently which depend
81 # on this one. As a last resort, sleep for some time.
82}
83
84#
85# Function that stops the daemon/service
86#
87do_stop() {
88 local pid status
89
90 status=0
91 pid=`pidofproc $NAME` || status=$?
92 case $status in
93 0)
94 # Exit when fail to stop, the kill would complain when fail
95 kill -s 15 $pid >/dev/null && rm -f $PIDFILE && \
96 echo "Stopped $DESC ($pid)." || exit $?
97 ;;
98 *)
99 echo "$DESC is not running; none killed." >&2
100 ;;
101 esac
102
103 # Wait for children to finish too if this is a daemon that forks
104 # and if the daemon is only ever run from this initscript.
105 # If the above conditions are not satisfied then add some other code
106 # that waits for the process to drop all resources that could be
107 # needed by services started subsequently. A last resort is to
108 # sleep for some time.
109 return $status
110}
111
112#
113# Function that sends a SIGHUP to the daemon/service
114#
115do_reload() {
116 local pid status
117
118 status=0
119 # If the daemon can reload its configuration without
120 # restarting (for example, when it is sent a SIGHUP),
121 # then implement that here.
122 pid=`pidofproc $NAME` || status=$?
123 case $status in
124 0)
125 echo "Reloading $DESC ..."
126 kill -s 1 $pid || exit $?
127 ;;
128 *)
129 echo "$DESC is not running; none reloaded." >&2
130 ;;
131 esac
132 exit $status
133}
134
135
136#
137# Function that shows the daemon/service status
138#
139status_of_proc () {
140 local pid status
141
142 status=0
143 # pidof output null when no program is running, so no "2>/dev/null".
144 pid=`pidofproc $NAME` || status=$?
145 case $status in
146 0)
147 echo "$DESC is running ($pid)."
148 exit 0
149 ;;
150 *)
151 echo "$DESC is not running." >&2
152 exit $status
153 ;;
154 esac
155}
156
157case "$1" in
158start)
159 do_start
160 ;;
161stop)
162 do_stop || exit $?
163 ;;
164status)
165 status_of_proc
166 ;;
167restart)
168 # Always start the service regardless the status of do_stop
169 do_stop
170 do_start
171 ;;
172try-restart|force-reload)
173 # force-reload is the same as reload or try-restart according
174 # to its definition, the reload is not implemented here, so
175 # force-reload is the alias of try-restart here, but it should
176 # be the alias of reload if reload is implemented.
177 #
178 # Only start the service when do_stop succeeds
179 do_stop && do_start
180 ;;
181#reload)
182 # If the "reload" action is implemented properly, then let the
183 # force-reload be the alias of reload, and remove it from
184 # try-restart|force-reload)
185 #
186 #do_reload
187 #;;
188*)
189 echo "Usage: $0 {start|stop|status|restart|try-restart|force-reload}" >&2
190 exit 3
191 ;;
192esac
193
diff --git a/meta-skeleton/recipes-skeleton/service/service/skeleton_test.c b/meta-skeleton/recipes-skeleton/service/service/skeleton_test.c
new file mode 100644
index 0000000000..96c67ac118
--- /dev/null
+++ b/meta-skeleton/recipes-skeleton/service/service/skeleton_test.c
@@ -0,0 +1,12 @@
1#include <unistd.h>
2
3/* This demo does nothing except for testing /etc/init.d/skeleton */
4
5int main(int argc, char *argv[])
6{
7 daemon(0, 0);
8 while (1) {
9 sleep(1);
10 }
11 return 0;
12}
diff --git a/meta-skeleton/recipes-skeleton/service/service_0.1.bb b/meta-skeleton/recipes-skeleton/service/service_0.1.bb
new file mode 100644
index 0000000000..22137a5e57
--- /dev/null
+++ b/meta-skeleton/recipes-skeleton/service/service_0.1.bb
@@ -0,0 +1,32 @@
1DESCRIPTION = "The canonical example of init scripts"
2SECTION = "base"
3LICENSE = "GPLv2"
4LIC_FILES_CHKSUM = "file://${WORKDIR}/COPYRIGHT;md5=349c872e0066155e1818b786938876a4"
5RDEPENDS_${PN} = "initscripts"
6PR = "r0"
7
8SRC_URI = "file://skeleton \
9 file://skeleton_test.c \
10 file://COPYRIGHT \
11 "
12
13CONFFILES_${PN} += "${sysconfdir}/init.d/skeleton"
14
15do_compile () {
16 ${CC} ${WORKDIR}/skeleton_test.c -o ${WORKDIR}/skeleton-test
17}
18
19do_install () {
20 install -d ${D}${sysconfdir}/init.d
21 cat ${WORKDIR}/skeleton | \
22 sed -e 's,/etc,${sysconfdir},g' \
23 -e 's,/usr/sbin,${sbindir},g' \
24 -e 's,/var,${localstatedir},g' \
25 -e 's,/usr/bin,${bindir},g' \
26 -e 's,/usr,${prefix},g' > ${D}${sysconfdir}/init.d/skeleton
27 chmod a+x ${D}${sysconfdir}/init.d/skeleton
28
29 install -d ${D}${sbindir}
30 install -m 0755 ${WORKDIR}/skeleton-test ${D}${sbindir}/
31}
32