summaryrefslogtreecommitdiffstats
path: root/meta-skeleton/recipes-skeleton
diff options
context:
space:
mode:
Diffstat (limited to 'meta-skeleton/recipes-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
-rw-r--r--meta-skeleton/recipes-skeleton/useradd/useradd-example.bb76
-rw-r--r--meta-skeleton/recipes-skeleton/useradd/useradd-example/file10
-rw-r--r--meta-skeleton/recipes-skeleton/useradd/useradd-example/file20
-rw-r--r--meta-skeleton/recipes-skeleton/useradd/useradd-example/file30
-rw-r--r--meta-skeleton/recipes-skeleton/useradd/useradd-example/file40
9 files changed, 328 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..a3ad6ccb2f
--- /dev/null
+++ b/meta-skeleton/recipes-skeleton/service/service_0.1.bb
@@ -0,0 +1,32 @@
1SUMMARY = "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
diff --git a/meta-skeleton/recipes-skeleton/useradd/useradd-example.bb b/meta-skeleton/recipes-skeleton/useradd/useradd-example.bb
new file mode 100644
index 0000000000..d3c02d5d61
--- /dev/null
+++ b/meta-skeleton/recipes-skeleton/useradd/useradd-example.bb
@@ -0,0 +1,76 @@
1SUMMARY = "Example recipe for using inherit useradd"
2DESCRIPTION = "This recipe serves as an example for using features from useradd.bbclass"
3SECTION = "examples"
4PR = "r1"
5LICENSE = "MIT"
6LIC_FILES_CHKSUM = "file://${COREBASE}/LICENSE;md5=4d92cd373abda3937c2bc47fbc49d690 \
7 file://${COREBASE}/meta/COPYING.MIT;md5=3da9cfbcb788c80a0384361b4de20420"
8
9SRC_URI = "file://file1 \
10 file://file2 \
11 file://file3 \
12 file://file4"
13
14S = "${WORKDIR}"
15
16PACKAGES =+ "${PN}-user3"
17
18inherit useradd
19
20# You must set USERADD_PACKAGES when you inherit useradd. This
21# lists which output packages will include the user/group
22# creation code.
23USERADD_PACKAGES = "${PN} ${PN}-user3"
24
25# You must also set USERADD_PARAM and/or GROUPADD_PARAM when
26# you inherit useradd.
27
28# USERADD_PARAM specifies command line options to pass to the
29# useradd command. Multiple users can be created by separating
30# the commands with a semicolon. Here we'll create two users,
31# user1 and user2:
32USERADD_PARAM_${PN} = "-u 1200 -d /home/user1 -r -s /bin/bash user1; -u 1201 -d /home/user2 -r -s /bin/bash user2"
33
34# user3 will be managed in the useradd-example-user3 pacakge:
35# As an example, we use the -P option to set clear text password for user3
36USERADD_PARAM_${PN}-user3 = "-u 1202 -d /home/user3 -r -s /bin/bash -P 'user3' user3"
37
38# GROUPADD_PARAM works the same way, which you set to the options
39# you'd normally pass to the groupadd command. This will create
40# groups group1 and group2:
41GROUPADD_PARAM_${PN} = "-g 880 group1; -g 890 group2"
42
43# Likewise, we'll manage group3 in the useradd-example-user3 package:
44GROUPADD_PARAM_${PN}-user3 = "-g 900 group3"
45
46do_install () {
47 install -d -m 755 ${D}${datadir}/user1
48 install -d -m 755 ${D}${datadir}/user2
49 install -d -m 755 ${D}${datadir}/user3
50
51 install -p -m 644 file1 ${D}${datadir}/user1/
52 install -p -m 644 file2 ${D}${datadir}/user1/
53
54 install -p -m 644 file2 ${D}${datadir}/user2/
55 install -p -m 644 file3 ${D}${datadir}/user2/
56
57 install -p -m 644 file3 ${D}${datadir}/user3/
58 install -p -m 644 file4 ${D}${datadir}/user3/
59
60 # The new users and groups are created before the do_install
61 # step, so you are now free to make use of them:
62 chown -R user1 ${D}${datadir}/user1
63 chown -R user2 ${D}${datadir}/user2
64 chown -R user3 ${D}${datadir}/user3
65
66 chgrp -R group1 ${D}${datadir}/user1
67 chgrp -R group2 ${D}${datadir}/user2
68 chgrp -R group3 ${D}${datadir}/user3
69}
70
71FILES_${PN} = "${datadir}/user1/* ${datadir}/user2/*"
72FILES_${PN}-user3 = "${datadir}/user3/*"
73
74# Prevents do_package failures with:
75# debugsources.list: No such file or directory:
76INHIBIT_PACKAGE_DEBUG_SPLIT = "1"
diff --git a/meta-skeleton/recipes-skeleton/useradd/useradd-example/file1 b/meta-skeleton/recipes-skeleton/useradd/useradd-example/file1
new file mode 100644
index 0000000000..e69de29bb2
--- /dev/null
+++ b/meta-skeleton/recipes-skeleton/useradd/useradd-example/file1
diff --git a/meta-skeleton/recipes-skeleton/useradd/useradd-example/file2 b/meta-skeleton/recipes-skeleton/useradd/useradd-example/file2
new file mode 100644
index 0000000000..e69de29bb2
--- /dev/null
+++ b/meta-skeleton/recipes-skeleton/useradd/useradd-example/file2
diff --git a/meta-skeleton/recipes-skeleton/useradd/useradd-example/file3 b/meta-skeleton/recipes-skeleton/useradd/useradd-example/file3
new file mode 100644
index 0000000000..e69de29bb2
--- /dev/null
+++ b/meta-skeleton/recipes-skeleton/useradd/useradd-example/file3
diff --git a/meta-skeleton/recipes-skeleton/useradd/useradd-example/file4 b/meta-skeleton/recipes-skeleton/useradd/useradd-example/file4
new file mode 100644
index 0000000000..e69de29bb2
--- /dev/null
+++ b/meta-skeleton/recipes-skeleton/useradd/useradd-example/file4