* [PATCH 0/2] Add meta-skeleton and a skeleton for init scripts
@ 2011-05-11 13:41 Robert Yang
2011-05-11 13:41 ` [PATCH 1/2] Add the layer meta-skeleton Robert Yang
2011-05-11 13:41 ` [PATCH 2/2] Add a skeleton for init scripts Robert Yang
0 siblings, 2 replies; 10+ messages in thread
From: Robert Yang @ 2011-05-11 13:41 UTC (permalink / raw)
To: dvhart, sgw, dvhart, sgw; +Cc: poky
* Add the layer meta-skeleton, it will be used to place the various
canonical examples.
* Add a skeleton for init scripts.
Pull URL: git://git.pokylinux.org/poky-contrib.git
Branch: robert/init_scripts
Browse: http://git.pokylinux.org/cgit.cgi/poky-contrib/log/?h=robert/init_scripts
Thanks,
Robert Yang <liezhi.yang@windriver.com>
---
Robert Yang (2):
Add the layer meta-skeleton
Add a skeleton for init scripts
meta-skeleton/conf/layer.conf | 10 +
.../recipes-skeleton/service/service/COPYRIGHT | 19 ++
.../recipes-skeleton/service/service/skeleton | 188 ++++++++++++++++++++
.../recipes-skeleton/service/service_0.1.bb | 20 ++
4 files changed, 237 insertions(+), 0 deletions(-)
create mode 100644 meta-skeleton/conf/layer.conf
create mode 100644 meta-skeleton/recipes-skeleton/service/service/COPYRIGHT
create mode 100644 meta-skeleton/recipes-skeleton/service/service/skeleton
create mode 100644 meta-skeleton/recipes-skeleton/service/service_0.1.bb
^ permalink raw reply [flat|nested] 10+ messages in thread
* [PATCH 1/2] Add the layer meta-skeleton
2011-05-11 13:41 [PATCH 0/2] Add meta-skeleton and a skeleton for init scripts Robert Yang
@ 2011-05-11 13:41 ` Robert Yang
2011-05-11 16:27 ` Darren Hart
2011-05-11 13:41 ` [PATCH 2/2] Add a skeleton for init scripts Robert Yang
1 sibling, 1 reply; 10+ messages in thread
From: Robert Yang @ 2011-05-11 13:41 UTC (permalink / raw)
To: dvhart, sgw; +Cc: poky
Add the layer meta-skeleton, it will be used to place the various
canonical examples.
Signed-off-by: Robert Yang <liezhi.yang@windriver.com>
---
meta-skeleton/conf/layer.conf | 10 ++++++++++
1 files changed, 10 insertions(+), 0 deletions(-)
create mode 100644 meta-skeleton/conf/layer.conf
diff --git a/meta-skeleton/conf/layer.conf b/meta-skeleton/conf/layer.conf
new file mode 100644
index 0000000..67be3bc
--- /dev/null
+++ b/meta-skeleton/conf/layer.conf
@@ -0,0 +1,10 @@
+# We have a conf and classes directory, add to BBPATH
+BBPATH := "${BBPATH}:${LAYERDIR}"
+
+# We have a packages directory, add to BBFILES
+BBFILES := "${BBFILES} ${LAYERDIR}/recipes-*/*/*.bb"
+
+BBFILE_COLLECTIONS += "skeleton"
+BBFILE_PATTERN_skeleton := "^${LAYERDIR}/"
+BBFILE_PRIORITY_skeleton = "6"
+
--
1.7.1
^ permalink raw reply related [flat|nested] 10+ messages in thread
* [PATCH 2/2] Add a skeleton for init scripts
2011-05-11 13:41 [PATCH 0/2] Add meta-skeleton and a skeleton for init scripts Robert Yang
2011-05-11 13:41 ` [PATCH 1/2] Add the layer meta-skeleton Robert Yang
@ 2011-05-11 13:41 ` Robert Yang
2011-05-11 17:56 ` Darren Hart
1 sibling, 1 reply; 10+ messages in thread
From: Robert Yang @ 2011-05-11 13:41 UTC (permalink / raw)
To: dvhart, sgw; +Cc: poky
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 of sysvinit_2.87dsf, it is GPLv2. I have
modified the original skeleton a lot to make it as easy as possible,
just use posix shell command, and have tested it in core-image-minimal.
* The skeleton implements the following items:
- start, stop, restart, status and force-reload.
And the force-reload is a alias of restart.
- not implements reload and try-restart, since only a few programs
have such functions, so just leave them as placeholders.
* Use start-stop-daemon to start and stop the program, it is useful to
deal with the pidfile, check whether there is already a running
program or not, and print relevant messages.
* The skeleton will run by default, and output the *simulation* message,
here is the testing result:
1) #./skeleton start (test start)
Starting skeleton ...
2) #./skeleton start (test start the already running program)
Starting skeleton ...
/usr/sbin/skeleton already running.
20426
It outputs two lines when start again, one line would be better, this
is because of the start-stop-daemon, but I'm not sure whether this is
worth.
3) #./skeleton status (test status when running)
skeleton is running.
4) #./skeleton stop (test stop)
Stopped skeleton (pid 20426).
5) #./skeleton stop (test stop again)
No skeleton found running; none killed.
6) #./skeleton status (test status when stopped)
skeleton is not running.
7) #./skeleton start (test restart when running)
Starting skeleton ...
#./skeleton restart
Stopped skeleton (pid 20444).
Starting skeleton ...
8) #./skeleton stop (test restart when stopped)
Stopped skeleton (pid 20444).
#./skeleton restart
No skeleton found running; none killed.
Starting skeleton ...
* Have used syslogd to test it in a real world(With both
core-image-minimal and core-image-sato)
* TODO:
- Move the function status_of_proc to /etc/init.d/functions ?
- Fix start-stop-daemon to get an one line output when start a
already runing program?
Signed-off-by: Robert Yang <liezhi.yang@windriver.com>
---
.../recipes-skeleton/service/service/COPYRIGHT | 19 ++
.../recipes-skeleton/service/service/skeleton | 188 ++++++++++++++++++++
.../recipes-skeleton/service/service_0.1.bb | 20 ++
3 files changed, 227 insertions(+), 0 deletions(-)
create mode 100644 meta-skeleton/recipes-skeleton/service/service/COPYRIGHT
create mode 100644 meta-skeleton/recipes-skeleton/service/service/skeleton
create mode 100644 meta-skeleton/recipes-skeleton/service/service_0.1.bb
diff --git a/meta-skeleton/recipes-skeleton/service/service/COPYRIGHT b/meta-skeleton/recipes-skeleton/service/service/COPYRIGHT
new file mode 100644
index 0000000..36703d9
--- /dev/null
+++ b/meta-skeleton/recipes-skeleton/service/service/COPYRIGHT
@@ -0,0 +1,19 @@
+Sysvinit is Copyright (C) 1991-2004 Miquel van Smoorenburg
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+
+On Debian GNU/Linux systems, the complete text of the GNU General
+Public License can be found in `/usr/share/common-licenses/GPL'.
+
diff --git a/meta-skeleton/recipes-skeleton/service/service/skeleton b/meta-skeleton/recipes-skeleton/service/service/skeleton
new file mode 100644
index 0000000..58804e4
--- /dev/null
+++ b/meta-skeleton/recipes-skeleton/service/service/skeleton
@@ -0,0 +1,188 @@
+#! /bin/sh
+### BEGIN INIT INFO
+# Provides: skeleton
+# Required-Start: $local_fs
+# Should-Start:
+# Required-Stop: $local_fs
+# Should-Stop:
+# Default-Start: 2 3 4 5
+# Default-Stop: 0 1 6
+# Short-Description: Example initscript
+# Description: This file should be used to construct scripts to be
+# placed in /etc/init.d.
+### END INIT INFO
+
+# Common steps to convert this skeleton into a real init script
+# 1) cp skeleton <the_real_name>
+# 2) Set DESC and NAME
+# 3) Check whether the daemon app is /usr/sbin/$NAME, if not, set it.
+# 4) Set DAEMON_ARGS if there is any
+# 5) Remove the useless code
+
+# PATH should only include /usr/* if it runs after the mountnfs.sh script
+PATH=/sbin:/usr/sbin:/bin:/usr/bin
+
+DESC="skeleton"
+NAME="skeleton"
+DAEMON=/usr/sbin/$NAME
+DAEMON_ARGS=""
+PIDFILE=/var/run/$NAME.pid
+SCRIPTNAME=/etc/init.d/$NAME
+
+#### Simulation begin
+# Simulate the script running, this is only used for printing the
+# information by default, it does nothing and should be removed from
+# the real init script
+fake_do_stop () {
+ if [ -f $PIDFILE ]; then
+ echo "Stopped $NAME (pid `cat $PIDFILE`)."
+ rm -f $PIDFILE
+ else
+ echo "No $NAME found running; none killed."
+ fi
+}
+
+if [ "$NAME" = "skeleton" ]; then
+ case $1 in
+ start)
+ echo "Starting $DESC ..."
+ if [ -f $PIDFILE ]; then
+ echo "$DAEMON already running."
+ cat $PIDFILE
+ else
+ echo $$ >$PIDFILE
+ fi
+ ;;
+ stop)
+ fake_do_stop
+ ;;
+ status)
+ if [ -f $PIDFILE ]; then
+ echo "$NAME is running."
+ else
+ echo "$NAME is not running."
+ fi
+ ;;
+ restart|force-reload)
+ fake_do_stop
+ echo "Starting $DESC ..."
+ echo $$ >$PIDFILE
+ ;;
+ *)
+ echo "Usage: $SCRIPTNAME {start|stop|status|restart|force-reload}" >&2
+ exit 3
+ ;;
+ esac
+exit 0
+fi
+#### Simulation end
+
+# Exit if the package is not installed
+[ -x "$DAEMON" ] || exit 0
+
+# Read configuration variable file if it is present
+[ -r /etc/default/$NAME ] && . /etc/default/$NAME
+
+#
+# Function that starts the daemon/service
+#
+do_start()
+{
+ start-stop-daemon -S --pidfile $PIDFILE --exec $DAEMON -- $DAEMON_ARGS
+ # Add code here, if necessary, that waits for the process to be ready
+ # to handle requests from services started subsequently which depend
+ # on this one. As a last resort, sleep for some time.
+}
+
+#
+# Function that stops the daemon/service
+#
+do_stop()
+{
+ start-stop-daemon -K -v --pidfile $PIDFILE --name $NAME
+ # Wait for children to finish too if this is a daemon that forks
+ # and if the daemon is only ever run from this initscript.
+ # If the above conditions are not satisfied then add some other code
+ # that waits for the process to drop all resources that could be
+ # needed by services started subsequently. A last resort is to
+ # sleep for some time.
+ #
+ #start-stop-daemon -K --oknodo --exec $DAEMON
+
+ # Many daemons don't delete their pidfiles when they exit.
+ rm -f $PIDFILE
+}
+
+#
+# Function that sends a SIGHUP to the daemon/service
+#
+#do_reload() {
+ #
+ # If the daemon can reload its configuration without
+ # restarting (for example, when it is sent a SIGHUP),
+ # then implement that here.
+ #
+ #start-stop-daemon -K --signal 1 --pidfile $PIDFILE --name $NAME
+#}
+
+#
+# Function that shows the daemon/service status
+#
+status_of_proc () {
+ pidof $NAME >/dev/null 2>&1
+ case $? in
+ 0)
+ echo "$NAME is running."
+ return 0
+ ;;
+ 127)
+ echo "Can't get the status of $NAME (no pidof found)"
+ ;;
+ *)
+ echo "$NAME is not running." >&2
+ return 1
+ ;;
+ esac
+}
+
+case "$1" in
+ start)
+ echo "Starting $DESC ..."
+ # Don't need check the return value, start-stop-daemon would
+ # print the failed reason automatically.
+ do_start
+ ;;
+ stop)
+ do_stop
+ ;;
+ status)
+ status_of_proc && exit 0 || exit $?
+ ;;
+ #reload|force-reload)
+ #
+ # If do_reload() is not implemented then leave this commented out
+ # and leave 'force-reload' as an alias for 'restart'.
+ #
+ #echo "Reloading $DESC ..."
+ #do_reload
+ #;;
+ restart|force-reload)
+ #
+ # If the "reload" option is implemented then remove the
+ # 'force-reload' alias.
+ #
+ do_stop
+ echo "Starting $DESC ..."
+ do_start
+ ;;
+ #try-restart)
+ # If do_try_restart() is not implemented then leave this commented out
+ #echo "Trying to restart $DESC ..."
+ #do_try_restart()
+ #;;
+ *)
+ echo "Usage: $SCRIPTNAME {start|stop|status|restart|force-reload}" >&2
+ exit 3
+ ;;
+esac
+
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 0000000..88a7a59
--- /dev/null
+++ b/meta-skeleton/recipes-skeleton/service/service_0.1.bb
@@ -0,0 +1,20 @@
+DESCRIPTION = "The canonical example of init scripts"
+SECTION = "base"
+LICENSE = "GPLv2"
+LIC_FILES_CHKSUM = "file://${WORKDIR}/COPYRIGHT;md5=3900421dc55b9e70428bc522557a66d4"
+RDEPENDS_${PN} = "initscripts"
+PR = "r0"
+
+SRC_URI = "file://skeleton \
+ file://COPYRIGHT \
+ "
+
+CONFFILES_${PN} += "${sysconfdir}/init.d/skeleton"
+
+PACKAGE_ARCH = "all"
+
+do_install () {
+ install -d ${D}/${sysconfdir}/init.d
+ install -m 0755 ${WORKDIR}/skeleton ${D}/${sysconfdir}/init.d/
+}
+
--
1.7.1
^ permalink raw reply related [flat|nested] 10+ messages in thread
* Re: [PATCH 1/2] Add the layer meta-skeleton
2011-05-11 13:41 ` [PATCH 1/2] Add the layer meta-skeleton Robert Yang
@ 2011-05-11 16:27 ` Darren Hart
0 siblings, 0 replies; 10+ messages in thread
From: Darren Hart @ 2011-05-11 16:27 UTC (permalink / raw)
To: Robert Yang; +Cc: poky
On 05/11/2011 06:41 AM, Robert Yang wrote:
> Add the layer meta-skeleton, it will be used to place the various
> canonical examples.
>
> Signed-off-by: Robert Yang <liezhi.yang@windriver.com>
> ---
> meta-skeleton/conf/layer.conf | 10 ++++++++++
> 1 files changed, 10 insertions(+), 0 deletions(-)
> create mode 100644 meta-skeleton/conf/layer.conf
>
> diff --git a/meta-skeleton/conf/layer.conf b/meta-skeleton/conf/layer.conf
> new file mode 100644
> index 0000000..67be3bc
> --- /dev/null
> +++ b/meta-skeleton/conf/layer.conf
> @@ -0,0 +1,10 @@
> +# We have a conf and classes directory, add to BBPATH
> +BBPATH := "${BBPATH}:${LAYERDIR}"
> +
> +# We have a packages directory, add to BBFILES
> +BBFILES := "${BBFILES} ${LAYERDIR}/recipes-*/*/*.bb"
> +
> +BBFILE_COLLECTIONS += "skeleton"
> +BBFILE_PATTERN_skeleton := "^${LAYERDIR}/"
> +BBFILE_PRIORITY_skeleton = "6"
This should probably be very last priority?
--
Darren Hart
Intel Open Source Technology Center
Yocto Project - Linux Kernel
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH 2/2] Add a skeleton for init scripts
2011-05-11 13:41 ` [PATCH 2/2] Add a skeleton for init scripts Robert Yang
@ 2011-05-11 17:56 ` Darren Hart
2011-05-12 0:47 ` Robert Yang
` (2 more replies)
0 siblings, 3 replies; 10+ messages in thread
From: Darren Hart @ 2011-05-11 17:56 UTC (permalink / raw)
To: Robert Yang; +Cc: poky
Hi Robert,
Thank you for doing this. This is a great start. As a preface to my
comments below, I am going to be incredibly particular about formatting
and such as this skeleton will be used by literally thousands of recipes
in the future and now is the time to ensure consistent formatting and to
eliminate any issues we don't want to see propagated.
On 05/11/2011 06:41 AM, Robert Yang wrote:
> 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 of sysvinit_2.87dsf, it is GPLv2. I have
> modified the original skeleton a lot to make it as easy as possible,
> just use posix shell command, and have tested it in core-image-minimal.
>
> * The skeleton implements the following items:
> - start, stop, restart, status and force-reload.
> And the force-reload is a alias of restart.
> - not implements reload and try-restart, since only a few programs
> have such functions, so just leave them as placeholders.
>
> * Use start-stop-daemon to start and stop the program, it is useful to
> deal with the pidfile, check whether there is already a running
> program or not, and print relevant messages.
>
> * The skeleton will run by default, and output the *simulation* message,
> here is the testing result:
> 1) #./skeleton start (test start)
> Starting skeleton ...
>
> 2) #./skeleton start (test start the already running program)
> Starting skeleton ...
> /usr/sbin/skeleton already running.
> 20426
>
> It outputs two lines when start again, one line would be better, this
> is because of the start-stop-daemon, but I'm not sure whether this is
> worth.
>
> 3) #./skeleton status (test status when running)
> skeleton is running.
We should use a consistent string for the daemon. You use the full path
in #2 above and only the basename here in #3.
>
> 4) #./skeleton stop (test stop)
> Stopped skeleton (pid 20426).
I prefer this format (with the pid listed on the same line) to that in
#2. #3 should also list the pid. For example, my dovecot initscript reports:
$ status dovecot
dovecot start/running, process 18529
It our case something like the following seems adequate.
$ ./skeleton status
skeleton is running (18529)
>
> 5) #./skeleton stop (test stop again)
> No skeleton found running; none killed.
I'd prefer:
skeleton is not running; none killed.
>
> 6) #./skeleton status (test status when stopped)
> skeleton is not running.
>
> 7) #./skeleton start (test restart when running)
> Starting skeleton ...
>
> #./skeleton restart
> Stopped skeleton (pid 20444).
> Starting skeleton ...
>
> 8) #./skeleton stop (test restart when stopped)
> Stopped skeleton (pid 20444).
>
> #./skeleton restart
> No skeleton found running; none killed.
skeleton is not running; none killed.
> Starting skeleton ...
>
> * Have used syslogd to test it in a real world(With both
> core-image-minimal and core-image-sato)
>
> * TODO:
> - Move the function status_of_proc to /etc/init.d/functions ?
It's not a bad idea. If so, that has to be part of the base images, not
the skeleton.
> - Fix start-stop-daemon to get an one line output when start a
> already runing program?
I wouldn't bother. I don't see anything wrong with two lines.
>
> Signed-off-by: Robert Yang <liezhi.yang@windriver.com>
> ---
> .../recipes-skeleton/service/service/COPYRIGHT | 19 ++
> .../recipes-skeleton/service/service/skeleton | 188 ++++++++++++++++++++
> .../recipes-skeleton/service/service_0.1.bb | 20 ++
> 3 files changed, 227 insertions(+), 0 deletions(-)
> create mode 100644 meta-skeleton/recipes-skeleton/service/service/COPYRIGHT
> create mode 100644 meta-skeleton/recipes-skeleton/service/service/skeleton
> create mode 100644 meta-skeleton/recipes-skeleton/service/service_0.1.bb
>
> diff --git a/meta-skeleton/recipes-skeleton/service/service/COPYRIGHT b/meta-skeleton/recipes-skeleton/service/service/COPYRIGHT
> new file mode 100644
> index 0000000..36703d9
> --- /dev/null
> +++ b/meta-skeleton/recipes-skeleton/service/service/COPYRIGHT
> @@ -0,0 +1,19 @@
> +Sysvinit is Copyright (C) 1991-2004 Miquel van Smoorenburg
> +
> + This program is free software; you can redistribute it and/or modify
> + it under the terms of the GNU General Public License as published by
> + the Free Software Foundation; either version 2 of the License, or
> + (at your option) any later version.
> +
> + This program is distributed in the hope that it will be useful,
> + but WITHOUT ANY WARRANTY; without even the implied warranty of
> + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
> + GNU General Public License for more details.
> +
> + You should have received a copy of the GNU General Public License
> + along with this program; if not, write to the Free Software
> + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
> +
> +On Debian GNU/Linux systems, the complete text of the GNU General
> +Public License can be found in `/usr/share/common-licenses/GPL'.
You don't need to keep this last bit of where to find it on Debian
systems - we aren't a Debian system.
> +
> diff --git a/meta-skeleton/recipes-skeleton/service/service/skeleton b/meta-skeleton/recipes-skeleton/service/service/skeleton
> new file mode 100644
> index 0000000..58804e4
> --- /dev/null
> +++ b/meta-skeleton/recipes-skeleton/service/service/skeleton
> @@ -0,0 +1,188 @@
> +#! /bin/sh
> +### BEGIN INIT INFO
> +# Provides: skeleton
> +# Required-Start: $local_fs
> +# Should-Start:
> +# Required-Stop: $local_fs
> +# Should-Stop:
> +# Default-Start: 2 3 4 5
> +# Default-Stop: 0 1 6
> +# Short-Description: Example initscript
> +# Description: This file should be used to construct scripts to be
> +# placed in /etc/init.d.
> +### END INIT INFO
> +
> +# Common steps to convert this skeleton into a real init script
> +# 1) cp skeleton <the_real_name>
> +# 2) Set DESC and NAME
> +# 3) Check whether the daemon app is /usr/sbin/$NAME, if not, set it.
> +# 4) Set DAEMON_ARGS if there is any
> +# 5) Remove the useless code
> +
> +# PATH should only include /usr/* if it runs after the mountnfs.sh script
> +PATH=/sbin:/usr/sbin:/bin:/usr/bin
Paths like usr and etc need to be rewritten at install. I wonder if
there might not be a better way to represent them in the skeleton.
> +
> +DESC="skeleton"
> +NAME="skeleton"
> +DAEMON=/usr/sbin/$NAME
> +DAEMON_ARGS=""
> +PIDFILE=/var/run/$NAME.pid
> +SCRIPTNAME=/etc/init.d/$NAME
> +
> +#### Simulation begin
> +# Simulate the script running, this is only used for printing the
> +# information by default, it does nothing and should be removed from
> +# the real init script
It should be removed from the skeleton as well. I suggest writing a test
script which calls "skeleton start; skeleton stop" etc. Especially since
you're not testing the actual script by running this, and you duplicate
code. So if you update it in only one spot, this testing will not catch it.
> +fake_do_stop () {
> + if [ -f $PIDFILE ]; then
> + echo "Stopped $NAME (pid `cat $PIDFILE`)."
> + rm -f $PIDFILE
> + else
> + echo "No $NAME found running; none killed."
> + fi
> +}
> +
> +if [ "$NAME" = "skeleton" ]; then
> + case $1 in
> + start)
> + echo "Starting $DESC ..."
> + if [ -f $PIDFILE ]; then
> + echo "$DAEMON already running."
> + cat $PIDFILE
> + else
> + echo $$ >$PIDFILE
> + fi
> + ;;
> + stop)
> + fake_do_stop
> + ;;
> + status)
> + if [ -f $PIDFILE ]; then
> + echo "$NAME is running."
> + else
> + echo "$NAME is not running."
> + fi
> + ;;
> + restart|force-reload)
> + fake_do_stop
> + echo "Starting $DESC ..."
> + echo $$ >$PIDFILE
> + ;;
> + *)
> + echo "Usage: $SCRIPTNAME {start|stop|status|restart|force-reload}" >&2
> + exit 3
> + ;;
> + esac
> +exit 0
> +fi
> +#### Simulation end
> +
> +# Exit if the package is not installed
> +[ -x "$DAEMON" ] || exit 0
> +
> +# Read configuration variable file if it is present
> +[ -r /etc/default/$NAME ] && . /etc/default/$NAME
> +
> +#
> +# Function that starts the daemon/service
> +#
> +do_start()
> +{
> + start-stop-daemon -S --pidfile $PIDFILE --exec $DAEMON -- $DAEMON_ARGS
> + # Add code here, if necessary, that waits for the process to be ready
> + # to handle requests from services started subsequently which depend
> + # on this one. As a last resort, sleep for some time.
> +}
> +
> +#
> +# Function that stops the daemon/service
> +#
> +do_stop()
> +{
> + start-stop-daemon -K -v --pidfile $PIDFILE --name $NAME
> + # Wait for children to finish too if this is a daemon that forks
> + # and if the daemon is only ever run from this initscript.
> + # If the above conditions are not satisfied then add some other code
> + # that waits for the process to drop all resources that could be
> + # needed by services started subsequently. A last resort is to
> + # sleep for some time.
> + #
> + #start-stop-daemon -K --oknodo --exec $DAEMON
What does this command do?
> +
> + # Many daemons don't delete their pidfiles when they exit.
> + rm -f $PIDFILE
Should STDERR be redirected to /dev/null in case the file does not exist?
> +}
> +
> +#
> +# Function that sends a SIGHUP to the daemon/service
> +#
> +#do_reload() {
> + #
> + # If the daemon can reload its configuration without
> + # restarting (for example, when it is sent a SIGHUP),
> + # then implement that here.
> + #
> + #start-stop-daemon -K --signal 1 --pidfile $PIDFILE --name $NAME
> +#}
> +
> +#
> +# Function that shows the daemon/service status
> +#
> +status_of_proc () {
> + pidof $NAME >/dev/null 2>&1
> + case $? in
> + 0)
> + echo "$NAME is running."
> + return 0
> + ;;
> + 127)
> + echo "Can't get the status of $NAME (no pidof found)"
> + ;;
> + *)
> + echo "$NAME is not running." >&2
> + return 1
> + ;;
> + esac
> +}
> +
> +case "$1" in
> + start)
> + echo "Starting $DESC ..."
> + # Don't need check the return value, start-stop-daemon would
> + # print the failed reason automatically.
> + do_start
> + ;;
> + stop)
> + do_stop
> + ;;
> + status)
> + status_of_proc && exit 0 || exit $?
> + ;;
> + #reload|force-reload)
We don't want to have force-reload in two locations, even commented out.
Going to lead to confusion.
> + #
> + # If do_reload() is not implemented then leave this commented out
> + # and leave 'force-reload' as an alias for 'restart'.
> + #
> + #echo "Reloading $DESC ..."
> + #do_reload
> + #;;
> + restart|force-reload)
> + #
> + # If the "reload" option is implemented then remove the
> + # 'force-reload' alias.
> + #
> + do_stop
> + echo "Starting $DESC ..."
> + do_start
> + ;;
> + #try-restart)
> + # If do_try_restart() is not implemented then leave this commented out
> + #echo "Trying to restart $DESC ..."
This needs a description of how it should be implemented. i.e. how is
this different from restart?
> + #do_try_restart()
> + #;;
> + *)
> + echo "Usage: $SCRIPTNAME {start|stop|status|restart|force-reload}" >&2
> + exit 3
> + ;;
> +esac
> +
> 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 0000000..88a7a59
> --- /dev/null
> +++ b/meta-skeleton/recipes-skeleton/service/service_0.1.bb
> @@ -0,0 +1,20 @@
> +DESCRIPTION = "The canonical example of init scripts"
> +SECTION = "base"
> +LICENSE = "GPLv2"
> +LIC_FILES_CHKSUM = "file://${WORKDIR}/COPYRIGHT;md5=3900421dc55b9e70428bc522557a66d4"
> +RDEPENDS_${PN} = "initscripts"
> +PR = "r0"
> +
> +SRC_URI = "file://skeleton \
> + file://COPYRIGHT \
> + "
> +
> +CONFFILES_${PN} += "${sysconfdir}/init.d/skeleton"
> +
> +PACKAGE_ARCH = "all"
> +
> +do_install () {
> + install -d ${D}/${sysconfdir}/init.d
> + install -m 0755 ${WORKDIR}/skeleton ${D}/${sysconfdir}/init.d/
> +}
> +
This installs a file that uses directories like /usr which should be
replaced with the appropriate setting. For example, in mediatomb (and
others) we do this like this:
cat ${WORKDIR}/config.xml | \
sed -e 's,/etc,${sysconfdir},g' \
-e 's,/usr/sbin,${sbindir},g' \
-e 's,/var,${localstatedir},g' \
-e 's,/usr/bin,${bindir},g' \
-e 's,/usr,${prefix},g' > ${D}${sysconfdir}/mediatomb/config.xml
--
Darren Hart
Intel Open Source Technology Center
Yocto Project - Linux Kernel
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH 2/2] Add a skeleton for init scripts
2011-05-11 17:56 ` Darren Hart
@ 2011-05-12 0:47 ` Robert Yang
2011-05-12 15:41 ` Robert Yang
2011-05-12 17:22 ` Saul Wold
2 siblings, 0 replies; 10+ messages in thread
From: Robert Yang @ 2011-05-12 0:47 UTC (permalink / raw)
To: Darren Hart; +Cc: poky
Hi Darren,
Thank you very much for you detailed review, I think that I'd better
not use the start-stop-daemon(or patch it) to get the output message
that we need. because the inconsistent output is from
And please see the comments below.
On 05/12/2011 01:56 AM, Darren Hart wrote:
> Hi Robert,
>
> Thank you for doing this. This is a great start. As a preface to my
> comments below, I am going to be incredibly particular about formatting
> and such as this skeleton will be used by literally thousands of recipes
> in the future and now is the time to ensure consistent formatting and to
> eliminate any issues we don't want to see propagated.
>
>
> On 05/11/2011 06:41 AM, Robert Yang wrote:
>> + #
>> + #start-stop-daemon -K --oknodo --exec $DAEMON
>
>
> What does this command do?
>
if the $DAEMON is not running, exit with 0.
>
>> +
>> + # Many daemons don't delete their pidfiles when they exit.
>> + rm -f $PIDFILE
>
>
> Should STDERR be redirected to /dev/null in case the file does not exist?
>
I think rm -f would output nothing when there is no $PIDFILE.
//Robert
>
>> +}
>> +
>> +#
>> +# Function that sends a SIGHUP to the daemon/service
>> +#
>> +#do_reload() {
>> + #
>> + # If the daemon can reload its configuration without
>> + # restarting (for example, when it is sent a SIGHUP),
>> + # then implement that here.
>> + #
>> + #start-stop-daemon -K --signal 1 --pidfile $PIDFILE --name $NAME
>> +#}
>> +
>> +#
>> +# Function that shows the daemon/service status
>> +#
>> +status_of_proc () {
>> + pidof $NAME>/dev/null 2>&1
>> + case $? in
>> + 0)
>> + echo "$NAME is running."
>> + return 0
>> + ;;
>> + 127)
>> + echo "Can't get the status of $NAME (no pidof found)"
>> + ;;
>> + *)
>> + echo "$NAME is not running.">&2
>> + return 1
>> + ;;
>> + esac
>> +}
>> +
>> +case "$1" in
>> + start)
>> + echo "Starting $DESC ..."
>> + # Don't need check the return value, start-stop-daemon would
>> + # print the failed reason automatically.
>> + do_start
>> + ;;
>> + stop)
>> + do_stop
>> + ;;
>> + status)
>> + status_of_proc&& exit 0 || exit $?
>> + ;;
>> + #reload|force-reload)
>
>
> We don't want to have force-reload in two locations, even commented out.
> Going to lead to confusion.
>
>
>> + #
>> + # If do_reload() is not implemented then leave this commented out
>> + # and leave 'force-reload' as an alias for 'restart'.
>> + #
>> + #echo "Reloading $DESC ..."
>> + #do_reload
>> + #;;
>> + restart|force-reload)
>> + #
>> + # If the "reload" option is implemented then remove the
>> + # 'force-reload' alias.
>> + #
>> + do_stop
>> + echo "Starting $DESC ..."
>> + do_start
>> + ;;
>> + #try-restart)
>> + # If do_try_restart() is not implemented then leave this commented out
>> + #echo "Trying to restart $DESC ..."
>
>
> This needs a description of how it should be implemented. i.e. how is
> this different from restart?
>
>
>> + #do_try_restart()
>> + #;;
>> + *)
>> + echo "Usage: $SCRIPTNAME {start|stop|status|restart|force-reload}">&2
>> + exit 3
>> + ;;
>> +esac
>> +
>> 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 0000000..88a7a59
>> --- /dev/null
>> +++ b/meta-skeleton/recipes-skeleton/service/service_0.1.bb
>> @@ -0,0 +1,20 @@
>> +DESCRIPTION = "The canonical example of init scripts"
>> +SECTION = "base"
>> +LICENSE = "GPLv2"
>> +LIC_FILES_CHKSUM = "file://${WORKDIR}/COPYRIGHT;md5=3900421dc55b9e70428bc522557a66d4"
>> +RDEPENDS_${PN} = "initscripts"
>> +PR = "r0"
>> +
>> +SRC_URI = "file://skeleton \
>> + file://COPYRIGHT \
>> + "
>> +
>> +CONFFILES_${PN} += "${sysconfdir}/init.d/skeleton"
>> +
>> +PACKAGE_ARCH = "all"
>> +
>> +do_install () {
>> + install -d ${D}/${sysconfdir}/init.d
>> + install -m 0755 ${WORKDIR}/skeleton ${D}/${sysconfdir}/init.d/
>> +}
>> +
>
> This installs a file that uses directories like /usr which should be
> replaced with the appropriate setting. For example, in mediatomb (and
> others) we do this like this:
>
> cat ${WORKDIR}/config.xml | \
> sed -e 's,/etc,${sysconfdir},g' \
> -e 's,/usr/sbin,${sbindir},g' \
> -e 's,/var,${localstatedir},g' \
> -e 's,/usr/bin,${bindir},g' \
> -e 's,/usr,${prefix},g'> ${D}${sysconfdir}/mediatomb/config.xml
>
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH 2/2] Add a skeleton for init scripts
2011-05-11 17:56 ` Darren Hart
2011-05-12 0:47 ` Robert Yang
@ 2011-05-12 15:41 ` Robert Yang
2011-05-16 1:34 ` Robert Yang
2011-05-12 17:22 ` Saul Wold
2 siblings, 1 reply; 10+ messages in thread
From: Robert Yang @ 2011-05-12 15:41 UTC (permalink / raw)
To: Darren Hart; +Cc: poky
Hi Darren,
I find that the busybox's pidof can't get the pid of the "shell script"
(opposite to the binary) currently, it doesn't support the "-x" option,
so it seems that we should patch the busybox's pidof.c, is this acceptable
or not?
Thank you very much
Robert
On 05/12/2011 01:56 AM, Darren Hart wrote:
> Hi Robert,
>
> Thank you for doing this. This is a great start. As a preface to my
> comments below, I am going to be incredibly particular about formatting
> and such as this skeleton will be used by literally thousands of recipes
> in the future and now is the time to ensure consistent formatting and to
> eliminate any issues we don't want to see propagated.
>
>
> On 05/11/2011 06:41 AM, Robert Yang wrote:
>> 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 of sysvinit_2.87dsf, it is GPLv2. I have
>> modified the original skeleton a lot to make it as easy as possible,
>> just use posix shell command, and have tested it in core-image-minimal.
>>
>> * The skeleton implements the following items:
>> - start, stop, restart, status and force-reload.
>> And the force-reload is a alias of restart.
>> - not implements reload and try-restart, since only a few programs
>> have such functions, so just leave them as placeholders.
>>
>> * Use start-stop-daemon to start and stop the program, it is useful to
>> deal with the pidfile, check whether there is already a running
>> program or not, and print relevant messages.
>>
>> * The skeleton will run by default, and output the *simulation* message,
>> here is the testing result:
>> 1) #./skeleton start (test start)
>> Starting skeleton ...
>>
>> 2) #./skeleton start (test start the already running program)
>> Starting skeleton ...
>> /usr/sbin/skeleton already running.
>> 20426
>>
>> It outputs two lines when start again, one line would be better, this
>> is because of the start-stop-daemon, but I'm not sure whether this is
>> worth.
>>
>> 3) #./skeleton status (test status when running)
>> skeleton is running.
>
> We should use a consistent string for the daemon. You use the full path
> in #2 above and only the basename here in #3.
>
>>
>> 4) #./skeleton stop (test stop)
>> Stopped skeleton (pid 20426).
>
> I prefer this format (with the pid listed on the same line) to that in
> #2. #3 should also list the pid. For example, my dovecot initscript reports:
>
> $ status dovecot
> dovecot start/running, process 18529
>
> It our case something like the following seems adequate.
>
> $ ./skeleton status
> skeleton is running (18529)
>
>>
>> 5) #./skeleton stop (test stop again)
>> No skeleton found running; none killed.
>
> I'd prefer:
>
> skeleton is not running; none killed.
>
>>
>> 6) #./skeleton status (test status when stopped)
>> skeleton is not running.
>>
>> 7) #./skeleton start (test restart when running)
>> Starting skeleton ...
>>
>> #./skeleton restart
>> Stopped skeleton (pid 20444).
>> Starting skeleton ...
>>
>> 8) #./skeleton stop (test restart when stopped)
>> Stopped skeleton (pid 20444).
>>
>> #./skeleton restart
>> No skeleton found running; none killed.
>
> skeleton is not running; none killed.
>
>> Starting skeleton ...
>>
>> * Have used syslogd to test it in a real world(With both
>> core-image-minimal and core-image-sato)
>>
>> * TODO:
>> - Move the function status_of_proc to /etc/init.d/functions ?
>
>
> It's not a bad idea. If so, that has to be part of the base images, not
> the skeleton.
>
>
>> - Fix start-stop-daemon to get an one line output when start a
>> already runing program?
>
>
> I wouldn't bother. I don't see anything wrong with two lines.
>
>
>>
>> Signed-off-by: Robert Yang<liezhi.yang@windriver.com>
>> ---
>> .../recipes-skeleton/service/service/COPYRIGHT | 19 ++
>> .../recipes-skeleton/service/service/skeleton | 188 ++++++++++++++++++++
>> .../recipes-skeleton/service/service_0.1.bb | 20 ++
>> 3 files changed, 227 insertions(+), 0 deletions(-)
>> create mode 100644 meta-skeleton/recipes-skeleton/service/service/COPYRIGHT
>> create mode 100644 meta-skeleton/recipes-skeleton/service/service/skeleton
>> create mode 100644 meta-skeleton/recipes-skeleton/service/service_0.1.bb
>>
>> diff --git a/meta-skeleton/recipes-skeleton/service/service/COPYRIGHT b/meta-skeleton/recipes-skeleton/service/service/COPYRIGHT
>> new file mode 100644
>> index 0000000..36703d9
>> --- /dev/null
>> +++ b/meta-skeleton/recipes-skeleton/service/service/COPYRIGHT
>> @@ -0,0 +1,19 @@
>> +Sysvinit is Copyright (C) 1991-2004 Miquel van Smoorenburg
>> +
>> + This program is free software; you can redistribute it and/or modify
>> + it under the terms of the GNU General Public License as published by
>> + the Free Software Foundation; either version 2 of the License, or
>> + (at your option) any later version.
>> +
>> + This program is distributed in the hope that it will be useful,
>> + but WITHOUT ANY WARRANTY; without even the implied warranty of
>> + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
>> + GNU General Public License for more details.
>> +
>> + You should have received a copy of the GNU General Public License
>> + along with this program; if not, write to the Free Software
>> + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
>> +
>> +On Debian GNU/Linux systems, the complete text of the GNU General
>> +Public License can be found in `/usr/share/common-licenses/GPL'.
>
>
> You don't need to keep this last bit of where to find it on Debian
> systems - we aren't a Debian system.
>
>
>> +
>> diff --git a/meta-skeleton/recipes-skeleton/service/service/skeleton b/meta-skeleton/recipes-skeleton/service/service/skeleton
>> new file mode 100644
>> index 0000000..58804e4
>> --- /dev/null
>> +++ b/meta-skeleton/recipes-skeleton/service/service/skeleton
>> @@ -0,0 +1,188 @@
>> +#! /bin/sh
>> +### BEGIN INIT INFO
>> +# Provides: skeleton
>> +# Required-Start: $local_fs
>> +# Should-Start:
>> +# Required-Stop: $local_fs
>> +# Should-Stop:
>> +# Default-Start: 2 3 4 5
>> +# Default-Stop: 0 1 6
>> +# Short-Description: Example initscript
>> +# Description: This file should be used to construct scripts to be
>> +# placed in /etc/init.d.
>> +### END INIT INFO
>> +
>> +# Common steps to convert this skeleton into a real init script
>> +# 1) cp skeleton<the_real_name>
>> +# 2) Set DESC and NAME
>> +# 3) Check whether the daemon app is /usr/sbin/$NAME, if not, set it.
>> +# 4) Set DAEMON_ARGS if there is any
>> +# 5) Remove the useless code
>> +
>> +# PATH should only include /usr/* if it runs after the mountnfs.sh script
>> +PATH=/sbin:/usr/sbin:/bin:/usr/bin
>
>
> Paths like usr and etc need to be rewritten at install. I wonder if
> there might not be a better way to represent them in the skeleton.
>
>
>> +
>> +DESC="skeleton"
>> +NAME="skeleton"
>> +DAEMON=/usr/sbin/$NAME
>> +DAEMON_ARGS=""
>> +PIDFILE=/var/run/$NAME.pid
>> +SCRIPTNAME=/etc/init.d/$NAME
>> +
>> +#### Simulation begin
>> +# Simulate the script running, this is only used for printing the
>> +# information by default, it does nothing and should be removed from
>> +# the real init script
>
>
> It should be removed from the skeleton as well. I suggest writing a test
> script which calls "skeleton start; skeleton stop" etc. Especially since
> you're not testing the actual script by running this, and you duplicate
> code. So if you update it in only one spot, this testing will not catch it.
>
>
>> +fake_do_stop () {
>> + if [ -f $PIDFILE ]; then
>> + echo "Stopped $NAME (pid `cat $PIDFILE`)."
>> + rm -f $PIDFILE
>> + else
>> + echo "No $NAME found running; none killed."
>> + fi
>> +}
>> +
>> +if [ "$NAME" = "skeleton" ]; then
>> + case $1 in
>> + start)
>> + echo "Starting $DESC ..."
>> + if [ -f $PIDFILE ]; then
>> + echo "$DAEMON already running."
>> + cat $PIDFILE
>> + else
>> + echo $$>$PIDFILE
>> + fi
>> + ;;
>> + stop)
>> + fake_do_stop
>> + ;;
>> + status)
>> + if [ -f $PIDFILE ]; then
>> + echo "$NAME is running."
>> + else
>> + echo "$NAME is not running."
>> + fi
>> + ;;
>> + restart|force-reload)
>> + fake_do_stop
>> + echo "Starting $DESC ..."
>> + echo $$>$PIDFILE
>> + ;;
>> + *)
>> + echo "Usage: $SCRIPTNAME {start|stop|status|restart|force-reload}">&2
>> + exit 3
>> + ;;
>> + esac
>> +exit 0
>> +fi
>> +#### Simulation end
>> +
>> +# Exit if the package is not installed
>> +[ -x "$DAEMON" ] || exit 0
>> +
>> +# Read configuration variable file if it is present
>> +[ -r /etc/default/$NAME ]&& . /etc/default/$NAME
>> +
>> +#
>> +# Function that starts the daemon/service
>> +#
>> +do_start()
>> +{
>> + start-stop-daemon -S --pidfile $PIDFILE --exec $DAEMON -- $DAEMON_ARGS
>> + # Add code here, if necessary, that waits for the process to be ready
>> + # to handle requests from services started subsequently which depend
>> + # on this one. As a last resort, sleep for some time.
>> +}
>> +
>> +#
>> +# Function that stops the daemon/service
>> +#
>> +do_stop()
>> +{
>> + start-stop-daemon -K -v --pidfile $PIDFILE --name $NAME
>> + # Wait for children to finish too if this is a daemon that forks
>> + # and if the daemon is only ever run from this initscript.
>> + # If the above conditions are not satisfied then add some other code
>> + # that waits for the process to drop all resources that could be
>> + # needed by services started subsequently. A last resort is to
>> + # sleep for some time.
>> + #
>> + #start-stop-daemon -K --oknodo --exec $DAEMON
>
>
> What does this command do?
>
>
>> +
>> + # Many daemons don't delete their pidfiles when they exit.
>> + rm -f $PIDFILE
>
>
> Should STDERR be redirected to /dev/null in case the file does not exist?
>
>
>> +}
>> +
>> +#
>> +# Function that sends a SIGHUP to the daemon/service
>> +#
>> +#do_reload() {
>> + #
>> + # If the daemon can reload its configuration without
>> + # restarting (for example, when it is sent a SIGHUP),
>> + # then implement that here.
>> + #
>> + #start-stop-daemon -K --signal 1 --pidfile $PIDFILE --name $NAME
>> +#}
>> +
>> +#
>> +# Function that shows the daemon/service status
>> +#
>> +status_of_proc () {
>> + pidof $NAME>/dev/null 2>&1
>> + case $? in
>> + 0)
>> + echo "$NAME is running."
>> + return 0
>> + ;;
>> + 127)
>> + echo "Can't get the status of $NAME (no pidof found)"
>> + ;;
>> + *)
>> + echo "$NAME is not running.">&2
>> + return 1
>> + ;;
>> + esac
>> +}
>> +
>> +case "$1" in
>> + start)
>> + echo "Starting $DESC ..."
>> + # Don't need check the return value, start-stop-daemon would
>> + # print the failed reason automatically.
>> + do_start
>> + ;;
>> + stop)
>> + do_stop
>> + ;;
>> + status)
>> + status_of_proc&& exit 0 || exit $?
>> + ;;
>> + #reload|force-reload)
>
>
> We don't want to have force-reload in two locations, even commented out.
> Going to lead to confusion.
>
>
>> + #
>> + # If do_reload() is not implemented then leave this commented out
>> + # and leave 'force-reload' as an alias for 'restart'.
>> + #
>> + #echo "Reloading $DESC ..."
>> + #do_reload
>> + #;;
>> + restart|force-reload)
>> + #
>> + # If the "reload" option is implemented then remove the
>> + # 'force-reload' alias.
>> + #
>> + do_stop
>> + echo "Starting $DESC ..."
>> + do_start
>> + ;;
>> + #try-restart)
>> + # If do_try_restart() is not implemented then leave this commented out
>> + #echo "Trying to restart $DESC ..."
>
>
> This needs a description of how it should be implemented. i.e. how is
> this different from restart?
>
>
>> + #do_try_restart()
>> + #;;
>> + *)
>> + echo "Usage: $SCRIPTNAME {start|stop|status|restart|force-reload}">&2
>> + exit 3
>> + ;;
>> +esac
>> +
>> 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 0000000..88a7a59
>> --- /dev/null
>> +++ b/meta-skeleton/recipes-skeleton/service/service_0.1.bb
>> @@ -0,0 +1,20 @@
>> +DESCRIPTION = "The canonical example of init scripts"
>> +SECTION = "base"
>> +LICENSE = "GPLv2"
>> +LIC_FILES_CHKSUM = "file://${WORKDIR}/COPYRIGHT;md5=3900421dc55b9e70428bc522557a66d4"
>> +RDEPENDS_${PN} = "initscripts"
>> +PR = "r0"
>> +
>> +SRC_URI = "file://skeleton \
>> + file://COPYRIGHT \
>> + "
>> +
>> +CONFFILES_${PN} += "${sysconfdir}/init.d/skeleton"
>> +
>> +PACKAGE_ARCH = "all"
>> +
>> +do_install () {
>> + install -d ${D}/${sysconfdir}/init.d
>> + install -m 0755 ${WORKDIR}/skeleton ${D}/${sysconfdir}/init.d/
>> +}
>> +
>
> This installs a file that uses directories like /usr which should be
> replaced with the appropriate setting. For example, in mediatomb (and
> others) we do this like this:
>
> cat ${WORKDIR}/config.xml | \
> sed -e 's,/etc,${sysconfdir},g' \
> -e 's,/usr/sbin,${sbindir},g' \
> -e 's,/var,${localstatedir},g' \
> -e 's,/usr/bin,${bindir},g' \
> -e 's,/usr,${prefix},g'> ${D}${sysconfdir}/mediatomb/config.xml
>
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH 2/2] Add a skeleton for init scripts
2011-05-11 17:56 ` Darren Hart
2011-05-12 0:47 ` Robert Yang
2011-05-12 15:41 ` Robert Yang
@ 2011-05-12 17:22 ` Saul Wold
2011-05-12 20:31 ` Darren Hart
2 siblings, 1 reply; 10+ messages in thread
From: Saul Wold @ 2011-05-12 17:22 UTC (permalink / raw)
To: Darren Hart; +Cc: poky
Robert,
A couple of additional comments below.
Sorry for not getting back to you sooner.
Sau!
On 05/11/2011 10:56 AM, Darren Hart wrote:
> Hi Robert,
>
> Thank you for doing this. This is a great start. As a preface to my
> comments below, I am going to be incredibly particular about formatting
> and such as this skeleton will be used by literally thousands of recipes
> in the future and now is the time to ensure consistent formatting and to
> eliminate any issues we don't want to see propagated.
>
>
> On 05/11/2011 06:41 AM, Robert Yang wrote:
>> 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 of sysvinit_2.87dsf, it is GPLv2. I have
>> modified the original skeleton a lot to make it as easy as possible,
>> just use posix shell command, and have tested it in core-image-minimal.
>>
>> * The skeleton implements the following items:
>> - start, stop, restart, status and force-reload.
>> And the force-reload is a alias of restart.
>> - not implements reload and try-restart, since only a few programs
>> have such functions, so just leave them as placeholders.
>>
>> * Use start-stop-daemon to start and stop the program, it is useful to
>> deal with the pidfile, check whether there is already a running
>> program or not, and print relevant messages.
>>
>> * The skeleton will run by default, and output the *simulation* message,
>> here is the testing result:
>> 1) #./skeleton start (test start)
>> Starting skeleton ...
>>
>> 2) #./skeleton start (test start the already running program)
>> Starting skeleton ...
>> /usr/sbin/skeleton already running.
>> 20426
>>
>> It outputs two lines when start again, one line would be better, this
>> is because of the start-stop-daemon, but I'm not sure whether this is
>> worth.
>>
>> 3) #./skeleton status (test status when running)
>> skeleton is running.
>
> We should use a consistent string for the daemon. You use the full path
> in #2 above and only the basename here in #3.
>
>>
>> 4) #./skeleton stop (test stop)
>> Stopped skeleton (pid 20426).
>
> I prefer this format (with the pid listed on the same line) to that in
> #2. #3 should also list the pid. For example, my dovecot initscript reports:
>
> $ status dovecot
> dovecot start/running, process 18529
>
> It our case something like the following seems adequate.
>
> $ ./skeleton status
> skeleton is running (18529)
>
>>
>> 5) #./skeleton stop (test stop again)
>> No skeleton found running; none killed.
>
> I'd prefer:
>
> skeleton is not running; none killed.
>
>>
>> 6) #./skeleton status (test status when stopped)
>> skeleton is not running.
>>
>> 7) #./skeleton start (test restart when running)
>> Starting skeleton ...
>>
>> #./skeleton restart
>> Stopped skeleton (pid 20444).
>> Starting skeleton ...
>>
>> 8) #./skeleton stop (test restart when stopped)
>> Stopped skeleton (pid 20444).
>>
>> #./skeleton restart
>> No skeleton found running; none killed.
>
> skeleton is not running; none killed.
>
>> Starting skeleton ...
>>
>> * Have used syslogd to test it in a real world(With both
>> core-image-minimal and core-image-sato)
>>
>> * TODO:
>> - Move the function status_of_proc to /etc/init.d/functions ?
>
>
> It's not a bad idea. If so, that has to be part of the base images, not
> the skeleton.
>
I will accept a patch for this!
>
>> - Fix start-stop-daemon to get an one line output when start a
>> already runing program?
>
>
> I wouldn't bother. I don't see anything wrong with two lines.
>
Darren are you being consistent here? I thought you wanted it on 1 line?
>
>>
>> Signed-off-by: Robert Yang<liezhi.yang@windriver.com>
>> ---
>> .../recipes-skeleton/service/service/COPYRIGHT | 19 ++
>> .../recipes-skeleton/service/service/skeleton | 188 ++++++++++++++++++++
>> .../recipes-skeleton/service/service_0.1.bb | 20 ++
>> 3 files changed, 227 insertions(+), 0 deletions(-)
>> create mode 100644 meta-skeleton/recipes-skeleton/service/service/COPYRIGHT
>> create mode 100644 meta-skeleton/recipes-skeleton/service/service/skeleton
>> create mode 100644 meta-skeleton/recipes-skeleton/service/service_0.1.bb
>>
>> diff --git a/meta-skeleton/recipes-skeleton/service/service/COPYRIGHT b/meta-skeleton/recipes-skeleton/service/service/COPYRIGHT
>> new file mode 100644
>> index 0000000..36703d9
>> --- /dev/null
>> +++ b/meta-skeleton/recipes-skeleton/service/service/COPYRIGHT
>> @@ -0,0 +1,19 @@
>> +Sysvinit is Copyright (C) 1991-2004 Miquel van Smoorenburg
>> +
>> + This program is free software; you can redistribute it and/or modify
>> + it under the terms of the GNU General Public License as published by
>> + the Free Software Foundation; either version 2 of the License, or
>> + (at your option) any later version.
>> +
>> + This program is distributed in the hope that it will be useful,
>> + but WITHOUT ANY WARRANTY; without even the implied warranty of
>> + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
>> + GNU General Public License for more details.
>> +
>> + You should have received a copy of the GNU General Public License
>> + along with this program; if not, write to the Free Software
>> + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
>> +
>> +On Debian GNU/Linux systems, the complete text of the GNU General
>> +Public License can be found in `/usr/share/common-licenses/GPL'.
>
>
> You don't need to keep this last bit of where to find it on Debian
> systems - we aren't a Debian system.
>
>
>> +
>> diff --git a/meta-skeleton/recipes-skeleton/service/service/skeleton b/meta-skeleton/recipes-skeleton/service/service/skeleton
>> new file mode 100644
>> index 0000000..58804e4
>> --- /dev/null
>> +++ b/meta-skeleton/recipes-skeleton/service/service/skeleton
>> @@ -0,0 +1,188 @@
>> +#! /bin/sh
>> +### BEGIN INIT INFO
>> +# Provides: skeleton
>> +# Required-Start: $local_fs
>> +# Should-Start:
>> +# Required-Stop: $local_fs
>> +# Should-Stop:
>> +# Default-Start: 2 3 4 5
>> +# Default-Stop: 0 1 6
>> +# Short-Description: Example initscript
>> +# Description: This file should be used to construct scripts to be
>> +# placed in /etc/init.d.
>> +### END INIT INFO
>> +
>> +# Common steps to convert this skeleton into a real init script
>> +# 1) cp skeleton<the_real_name>
>> +# 2) Set DESC and NAME
>> +# 3) Check whether the daemon app is /usr/sbin/$NAME, if not, set it.
>> +# 4) Set DAEMON_ARGS if there is any
>> +# 5) Remove the useless code
>> +
>> +# PATH should only include /usr/* if it runs after the mountnfs.sh script
>> +PATH=/sbin:/usr/sbin:/bin:/usr/bin
>
>
> Paths like usr and etc need to be rewritten at install. I wonder if
> there might not be a better way to represent them in the skeleton.
>
>
>> +
>> +DESC="skeleton"
>> +NAME="skeleton"
>> +DAEMON=/usr/sbin/$NAME
>> +DAEMON_ARGS=""
>> +PIDFILE=/var/run/$NAME.pid
>> +SCRIPTNAME=/etc/init.d/$NAME
>> +
>> +#### Simulation begin
>> +# Simulate the script running, this is only used for printing the
>> +# information by default, it does nothing and should be removed from
>> +# the real init script
>
>
> It should be removed from the skeleton as well. I suggest writing a test
> script which calls "skeleton start; skeleton stop" etc. Especially since
> you're not testing the actual script by running this, and you duplicate
> code. So if you update it in only one spot, this testing will not catch it.
>
>
>> +fake_do_stop () {
>> + if [ -f $PIDFILE ]; then
>> + echo "Stopped $NAME (pid `cat $PIDFILE`)."
>> + rm -f $PIDFILE
>> + else
>> + echo "No $NAME found running; none killed."
>> + fi
>> +}
>> +
>> +if [ "$NAME" = "skeleton" ]; then
>> + case $1 in
>> + start)
>> + echo "Starting $DESC ..."
>> + if [ -f $PIDFILE ]; then
>> + echo "$DAEMON already running."
>> + cat $PIDFILE
>> + else
>> + echo $$>$PIDFILE
>> + fi
>> + ;;
>> + stop)
>> + fake_do_stop
>> + ;;
>> + status)
>> + if [ -f $PIDFILE ]; then
>> + echo "$NAME is running."
>> + else
>> + echo "$NAME is not running."
>> + fi
>> + ;;
>> + restart|force-reload)
>> + fake_do_stop
>> + echo "Starting $DESC ..."
>> + echo $$>$PIDFILE
>> + ;;
>> + *)
>> + echo "Usage: $SCRIPTNAME {start|stop|status|restart|force-reload}">&2
>> + exit 3
>> + ;;
>> + esac
>> +exit 0
>> +fi
>> +#### Simulation end
>> +
>> +# Exit if the package is not installed
>> +[ -x "$DAEMON" ] || exit 0
>> +
>> +# Read configuration variable file if it is present
>> +[ -r /etc/default/$NAME ]&& . /etc/default/$NAME
>> +
>> +#
>> +# Function that starts the daemon/service
>> +#
>> +do_start()
>> +{
>> + start-stop-daemon -S --pidfile $PIDFILE --exec $DAEMON -- $DAEMON_ARGS
>> + # Add code here, if necessary, that waits for the process to be ready
>> + # to handle requests from services started subsequently which depend
>> + # on this one. As a last resort, sleep for some time.
>> +}
>> +
>> +#
>> +# Function that stops the daemon/service
>> +#
>> +do_stop()
>> +{
>> + start-stop-daemon -K -v --pidfile $PIDFILE --name $NAME
>> + # Wait for children to finish too if this is a daemon that forks
>> + # and if the daemon is only ever run from this initscript.
>> + # If the above conditions are not satisfied then add some other code
>> + # that waits for the process to drop all resources that could be
>> + # needed by services started subsequently. A last resort is to
>> + # sleep for some time.
>> + #
>> + #start-stop-daemon -K --oknodo --exec $DAEMON
>
>
> What does this command do?
>
>
>> +
>> + # Many daemons don't delete their pidfiles when they exit.
>> + rm -f $PIDFILE
>
>
> Should STDERR be redirected to /dev/null in case the file does not exist?
>
>
>> +}
>> +
>> +#
>> +# Function that sends a SIGHUP to the daemon/service
>> +#
>> +#do_reload() {
>> + #
>> + # If the daemon can reload its configuration without
>> + # restarting (for example, when it is sent a SIGHUP),
>> + # then implement that here.
>> + #
>> + #start-stop-daemon -K --signal 1 --pidfile $PIDFILE --name $NAME
>> +#}
>> +
>> +#
>> +# Function that shows the daemon/service status
>> +#
>> +status_of_proc () {
>> + pidof $NAME>/dev/null 2>&1
>> + case $? in
>> + 0)
>> + echo "$NAME is running."
>> + return 0
>> + ;;
>> + 127)
>> + echo "Can't get the status of $NAME (no pidof found)"
>> + ;;
>> + *)
>> + echo "$NAME is not running.">&2
>> + return 1
>> + ;;
>> + esac
>> +}
>> +
>> +case "$1" in
>> + start)
>> + echo "Starting $DESC ..."
>> + # Don't need check the return value, start-stop-daemon would
>> + # print the failed reason automatically.
>> + do_start
>> + ;;
>> + stop)
>> + do_stop
>> + ;;
>> + status)
>> + status_of_proc&& exit 0 || exit $?
>> + ;;
>> + #reload|force-reload)
>
>
> We don't want to have force-reload in two locations, even commented out.
> Going to lead to confusion.
>
>
>> + #
>> + # If do_reload() is not implemented then leave this commented out
>> + # and leave 'force-reload' as an alias for 'restart'.
>> + #
>> + #echo "Reloading $DESC ..."
>> + #do_reload
>> + #;;
>> + restart|force-reload)
>> + #
>> + # If the "reload" option is implemented then remove the
>> + # 'force-reload' alias.
>> + #
>> + do_stop
>> + echo "Starting $DESC ..."
>> + do_start
>> + ;;
>> + #try-restart)
>> + # If do_try_restart() is not implemented then leave this commented out
>> + #echo "Trying to restart $DESC ..."
>
>
> This needs a description of how it should be implemented. i.e. how is
> this different from restart?
>
>
>> + #do_try_restart()
>> + #;;
>> + *)
>> + echo "Usage: $SCRIPTNAME {start|stop|status|restart|force-reload}">&2
>> + exit 3
>> + ;;
>> +esac
>> +
>> 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 0000000..88a7a59
>> --- /dev/null
>> +++ b/meta-skeleton/recipes-skeleton/service/service_0.1.bb
>> @@ -0,0 +1,20 @@
>> +DESCRIPTION = "The canonical example of init scripts"
>> +SECTION = "base"
>> +LICENSE = "GPLv2"
>> +LIC_FILES_CHKSUM = "file://${WORKDIR}/COPYRIGHT;md5=3900421dc55b9e70428bc522557a66d4"
>> +RDEPENDS_${PN} = "initscripts"
>> +PR = "r0"
>> +
>> +SRC_URI = "file://skeleton \
>> + file://COPYRIGHT \
>> + "
>> +
>> +CONFFILES_${PN} += "${sysconfdir}/init.d/skeleton"
>> +
>> +PACKAGE_ARCH = "all"
>> +
>> +do_install () {
>> + install -d ${D}/${sysconfdir}/init.d
>> + install -m 0755 ${WORKDIR}/skeleton ${D}/${sysconfdir}/init.d/
>> +}
>> +
>
> This installs a file that uses directories like /usr which should be
> replaced with the appropriate setting. For example, in mediatomb (and
> others) we do this like this:
>
> cat ${WORKDIR}/config.xml | \
> sed -e 's,/etc,${sysconfdir},g' \
> -e 's,/usr/sbin,${sbindir},g' \
> -e 's,/var,${localstatedir},g' \
> -e 's,/usr/bin,${bindir},g' \
> -e 's,/usr,${prefix},g'> ${D}${sysconfdir}/mediatomb/config.xml
>
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH 2/2] Add a skeleton for init scripts
2011-05-12 17:22 ` Saul Wold
@ 2011-05-12 20:31 ` Darren Hart
0 siblings, 0 replies; 10+ messages in thread
From: Darren Hart @ 2011-05-12 20:31 UTC (permalink / raw)
To: Saul Wold; +Cc: poky
On 05/12/2011 10:22 AM, Saul Wold wrote:
>>> - Fix start-stop-daemon to get an one line output when start a
>>> already runing program?
>>
>>
>> I wouldn't bother. I don't see anything wrong with two lines.
>>
> Darren are you being consistent here? I thought you wanted it on 1 line?
Always take the last statement as the current one ;-) After reading
through I understand why it's two lines and don't feel it is worth the
complexity of changing it to one. It also accurately represents that
this is a two step process.
--
Darren Hart
Intel Open Source Technology Center
Yocto Project - Linux Kernel
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH 2/2] Add a skeleton for init scripts
2011-05-12 15:41 ` Robert Yang
@ 2011-05-16 1:34 ` Robert Yang
0 siblings, 0 replies; 10+ messages in thread
From: Robert Yang @ 2011-05-16 1:34 UTC (permalink / raw)
Cc: Darren Hart, poky
Saul suggested that if can't config busybox to make the pidof support the
"-x" option, then we would declare that it doesn't support the "shell script"
as a daemon with this skeleton unless the pidof supports "-x"(Then the user
should write the init script himself). This may be fine, there are only 3
shell scripts in core-image-minimal(In /bin/, /usr/bin/, /sbin/, /usr/sbin/).
// Robert
On 05/12/2011 11:41 PM, Robert Yang wrote:
> Hi Darren,
>
> I find that the busybox's pidof can't get the pid of the "shell script"
> (opposite to the binary) currently, it doesn't support the "-x" option,
> so it seems that we should patch the busybox's pidof.c, is this acceptable
> or not?
>
> Thank you very much
>
> Robert
>
> On 05/12/2011 01:56 AM, Darren Hart wrote:
>> Hi Robert,
>>
>> Thank you for doing this. This is a great start. As a preface to my
>> comments below, I am going to be incredibly particular about formatting
>> and such as this skeleton will be used by literally thousands of recipes
>> in the future and now is the time to ensure consistent formatting and to
>> eliminate any issues we don't want to see propagated.
>>
>>
>> On 05/11/2011 06:41 AM, Robert Yang wrote:
>>> 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 of sysvinit_2.87dsf, it is GPLv2. I have
>>> modified the original skeleton a lot to make it as easy as possible,
>>> just use posix shell command, and have tested it in core-image-minimal.
>>>
>>> * The skeleton implements the following items:
>>> - start, stop, restart, status and force-reload.
>>> And the force-reload is a alias of restart.
>>> - not implements reload and try-restart, since only a few programs
>>> have such functions, so just leave them as placeholders.
>>>
>>> * Use start-stop-daemon to start and stop the program, it is useful to
>>> deal with the pidfile, check whether there is already a running
>>> program or not, and print relevant messages.
>>>
>>> * The skeleton will run by default, and output the *simulation* message,
>>> here is the testing result:
>>> 1) #./skeleton start (test start)
>>> Starting skeleton ...
>>>
>>> 2) #./skeleton start (test start the already running program)
>>> Starting skeleton ...
>>> /usr/sbin/skeleton already running.
>>> 20426
>>>
>>> It outputs two lines when start again, one line would be better, this
>>> is because of the start-stop-daemon, but I'm not sure whether this is
>>> worth.
>>>
>>> 3) #./skeleton status (test status when running)
>>> skeleton is running.
>>
>> We should use a consistent string for the daemon. You use the full path
>> in #2 above and only the basename here in #3.
>>
>>>
>>> 4) #./skeleton stop (test stop)
>>> Stopped skeleton (pid 20426).
>>
>> I prefer this format (with the pid listed on the same line) to that in
>> #2. #3 should also list the pid. For example, my dovecot initscript reports:
>>
>> $ status dovecot
>> dovecot start/running, process 18529
>>
>> It our case something like the following seems adequate.
>>
>> $ ./skeleton status
>> skeleton is running (18529)
>>
>>>
>>> 5) #./skeleton stop (test stop again)
>>> No skeleton found running; none killed.
>>
>> I'd prefer:
>>
>> skeleton is not running; none killed.
>>
>>>
>>> 6) #./skeleton status (test status when stopped)
>>> skeleton is not running.
>>>
>>> 7) #./skeleton start (test restart when running)
>>> Starting skeleton ...
>>>
>>> #./skeleton restart
>>> Stopped skeleton (pid 20444).
>>> Starting skeleton ...
>>>
>>> 8) #./skeleton stop (test restart when stopped)
>>> Stopped skeleton (pid 20444).
>>>
>>> #./skeleton restart
>>> No skeleton found running; none killed.
>>
>> skeleton is not running; none killed.
>>
>>> Starting skeleton ...
>>>
>>> * Have used syslogd to test it in a real world(With both
>>> core-image-minimal and core-image-sato)
>>>
>>> * TODO:
>>> - Move the function status_of_proc to /etc/init.d/functions ?
>>
>>
>> It's not a bad idea. If so, that has to be part of the base images, not
>> the skeleton.
>>
>>
>>> - Fix start-stop-daemon to get an one line output when start a
>>> already runing program?
>>
>>
>> I wouldn't bother. I don't see anything wrong with two lines.
>>
>>
>>>
>>> Signed-off-by: Robert Yang<liezhi.yang@windriver.com>
>>> ---
>>> .../recipes-skeleton/service/service/COPYRIGHT | 19 ++
>>> .../recipes-skeleton/service/service/skeleton | 188 ++++++++++++++++++++
>>> .../recipes-skeleton/service/service_0.1.bb | 20 ++
>>> 3 files changed, 227 insertions(+), 0 deletions(-)
>>> create mode 100644 meta-skeleton/recipes-skeleton/service/service/COPYRIGHT
>>> create mode 100644 meta-skeleton/recipes-skeleton/service/service/skeleton
>>> create mode 100644 meta-skeleton/recipes-skeleton/service/service_0.1.bb
>>>
>>> diff --git a/meta-skeleton/recipes-skeleton/service/service/COPYRIGHT
>>> b/meta-skeleton/recipes-skeleton/service/service/COPYRIGHT
>>> new file mode 100644
>>> index 0000000..36703d9
>>> --- /dev/null
>>> +++ b/meta-skeleton/recipes-skeleton/service/service/COPYRIGHT
>>> @@ -0,0 +1,19 @@
>>> +Sysvinit is Copyright (C) 1991-2004 Miquel van Smoorenburg
>>> +
>>> + This program is free software; you can redistribute it and/or modify
>>> + it under the terms of the GNU General Public License as published by
>>> + the Free Software Foundation; either version 2 of the License, or
>>> + (at your option) any later version.
>>> +
>>> + This program is distributed in the hope that it will be useful,
>>> + but WITHOUT ANY WARRANTY; without even the implied warranty of
>>> + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
>>> + GNU General Public License for more details.
>>> +
>>> + You should have received a copy of the GNU General Public License
>>> + along with this program; if not, write to the Free Software
>>> + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
>>> +
>>> +On Debian GNU/Linux systems, the complete text of the GNU General
>>> +Public License can be found in `/usr/share/common-licenses/GPL'.
>>
>>
>> You don't need to keep this last bit of where to find it on Debian
>> systems - we aren't a Debian system.
>>
>>
>>> +
>>> diff --git a/meta-skeleton/recipes-skeleton/service/service/skeleton
>>> b/meta-skeleton/recipes-skeleton/service/service/skeleton
>>> new file mode 100644
>>> index 0000000..58804e4
>>> --- /dev/null
>>> +++ b/meta-skeleton/recipes-skeleton/service/service/skeleton
>>> @@ -0,0 +1,188 @@
>>> +#! /bin/sh
>>> +### BEGIN INIT INFO
>>> +# Provides: skeleton
>>> +# Required-Start: $local_fs
>>> +# Should-Start:
>>> +# Required-Stop: $local_fs
>>> +# Should-Stop:
>>> +# Default-Start: 2 3 4 5
>>> +# Default-Stop: 0 1 6
>>> +# Short-Description: Example initscript
>>> +# Description: This file should be used to construct scripts to be
>>> +# placed in /etc/init.d.
>>> +### END INIT INFO
>>> +
>>> +# Common steps to convert this skeleton into a real init script
>>> +# 1) cp skeleton<the_real_name>
>>> +# 2) Set DESC and NAME
>>> +# 3) Check whether the daemon app is /usr/sbin/$NAME, if not, set it.
>>> +# 4) Set DAEMON_ARGS if there is any
>>> +# 5) Remove the useless code
>>> +
>>> +# PATH should only include /usr/* if it runs after the mountnfs.sh script
>>> +PATH=/sbin:/usr/sbin:/bin:/usr/bin
>>
>>
>> Paths like usr and etc need to be rewritten at install. I wonder if
>> there might not be a better way to represent them in the skeleton.
>>
>>
>>> +
>>> +DESC="skeleton"
>>> +NAME="skeleton"
>>> +DAEMON=/usr/sbin/$NAME
>>> +DAEMON_ARGS=""
>>> +PIDFILE=/var/run/$NAME.pid
>>> +SCRIPTNAME=/etc/init.d/$NAME
>>> +
>>> +#### Simulation begin
>>> +# Simulate the script running, this is only used for printing the
>>> +# information by default, it does nothing and should be removed from
>>> +# the real init script
>>
>>
>> It should be removed from the skeleton as well. I suggest writing a test
>> script which calls "skeleton start; skeleton stop" etc. Especially since
>> you're not testing the actual script by running this, and you duplicate
>> code. So if you update it in only one spot, this testing will not catch it.
>>
>>
>>> +fake_do_stop () {
>>> + if [ -f $PIDFILE ]; then
>>> + echo "Stopped $NAME (pid `cat $PIDFILE`)."
>>> + rm -f $PIDFILE
>>> + else
>>> + echo "No $NAME found running; none killed."
>>> + fi
>>> +}
>>> +
>>> +if [ "$NAME" = "skeleton" ]; then
>>> + case $1 in
>>> + start)
>>> + echo "Starting $DESC ..."
>>> + if [ -f $PIDFILE ]; then
>>> + echo "$DAEMON already running."
>>> + cat $PIDFILE
>>> + else
>>> + echo $$>$PIDFILE
>>> + fi
>>> + ;;
>>> + stop)
>>> + fake_do_stop
>>> + ;;
>>> + status)
>>> + if [ -f $PIDFILE ]; then
>>> + echo "$NAME is running."
>>> + else
>>> + echo "$NAME is not running."
>>> + fi
>>> + ;;
>>> + restart|force-reload)
>>> + fake_do_stop
>>> + echo "Starting $DESC ..."
>>> + echo $$>$PIDFILE
>>> + ;;
>>> + *)
>>> + echo "Usage: $SCRIPTNAME {start|stop|status|restart|force-reload}">&2
>>> + exit 3
>>> + ;;
>>> + esac
>>> +exit 0
>>> +fi
>>> +#### Simulation end
>>> +
>>> +# Exit if the package is not installed
>>> +[ -x "$DAEMON" ] || exit 0
>>> +
>>> +# Read configuration variable file if it is present
>>> +[ -r /etc/default/$NAME ]&& . /etc/default/$NAME
>>> +
>>> +#
>>> +# Function that starts the daemon/service
>>> +#
>>> +do_start()
>>> +{
>>> + start-stop-daemon -S --pidfile $PIDFILE --exec $DAEMON -- $DAEMON_ARGS
>>> + # Add code here, if necessary, that waits for the process to be ready
>>> + # to handle requests from services started subsequently which depend
>>> + # on this one. As a last resort, sleep for some time.
>>> +}
>>> +
>>> +#
>>> +# Function that stops the daemon/service
>>> +#
>>> +do_stop()
>>> +{
>>> + start-stop-daemon -K -v --pidfile $PIDFILE --name $NAME
>>> + # Wait for children to finish too if this is a daemon that forks
>>> + # and if the daemon is only ever run from this initscript.
>>> + # If the above conditions are not satisfied then add some other code
>>> + # that waits for the process to drop all resources that could be
>>> + # needed by services started subsequently. A last resort is to
>>> + # sleep for some time.
>>> + #
>>> + #start-stop-daemon -K --oknodo --exec $DAEMON
>>
>>
>> What does this command do?
>>
>>
>>> +
>>> + # Many daemons don't delete their pidfiles when they exit.
>>> + rm -f $PIDFILE
>>
>>
>> Should STDERR be redirected to /dev/null in case the file does not exist?
>>
>>
>>> +}
>>> +
>>> +#
>>> +# Function that sends a SIGHUP to the daemon/service
>>> +#
>>> +#do_reload() {
>>> + #
>>> + # If the daemon can reload its configuration without
>>> + # restarting (for example, when it is sent a SIGHUP),
>>> + # then implement that here.
>>> + #
>>> + #start-stop-daemon -K --signal 1 --pidfile $PIDFILE --name $NAME
>>> +#}
>>> +
>>> +#
>>> +# Function that shows the daemon/service status
>>> +#
>>> +status_of_proc () {
>>> + pidof $NAME>/dev/null 2>&1
>>> + case $? in
>>> + 0)
>>> + echo "$NAME is running."
>>> + return 0
>>> + ;;
>>> + 127)
>>> + echo "Can't get the status of $NAME (no pidof found)"
>>> + ;;
>>> + *)
>>> + echo "$NAME is not running.">&2
>>> + return 1
>>> + ;;
>>> + esac
>>> +}
>>> +
>>> +case "$1" in
>>> + start)
>>> + echo "Starting $DESC ..."
>>> + # Don't need check the return value, start-stop-daemon would
>>> + # print the failed reason automatically.
>>> + do_start
>>> + ;;
>>> + stop)
>>> + do_stop
>>> + ;;
>>> + status)
>>> + status_of_proc&& exit 0 || exit $?
>>> + ;;
>>> + #reload|force-reload)
>>
>>
>> We don't want to have force-reload in two locations, even commented out.
>> Going to lead to confusion.
>>
>>
>>> + #
>>> + # If do_reload() is not implemented then leave this commented out
>>> + # and leave 'force-reload' as an alias for 'restart'.
>>> + #
>>> + #echo "Reloading $DESC ..."
>>> + #do_reload
>>> + #;;
>>> + restart|force-reload)
>>> + #
>>> + # If the "reload" option is implemented then remove the
>>> + # 'force-reload' alias.
>>> + #
>>> + do_stop
>>> + echo "Starting $DESC ..."
>>> + do_start
>>> + ;;
>>> + #try-restart)
>>> + # If do_try_restart() is not implemented then leave this commented out
>>> + #echo "Trying to restart $DESC ..."
>>
>>
>> This needs a description of how it should be implemented. i.e. how is
>> this different from restart?
>>
>>
>>> + #do_try_restart()
>>> + #;;
>>> + *)
>>> + echo "Usage: $SCRIPTNAME {start|stop|status|restart|force-reload}">&2
>>> + exit 3
>>> + ;;
>>> +esac
>>> +
>>> 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 0000000..88a7a59
>>> --- /dev/null
>>> +++ b/meta-skeleton/recipes-skeleton/service/service_0.1.bb
>>> @@ -0,0 +1,20 @@
>>> +DESCRIPTION = "The canonical example of init scripts"
>>> +SECTION = "base"
>>> +LICENSE = "GPLv2"
>>> +LIC_FILES_CHKSUM =
>>> "file://${WORKDIR}/COPYRIGHT;md5=3900421dc55b9e70428bc522557a66d4"
>>> +RDEPENDS_${PN} = "initscripts"
>>> +PR = "r0"
>>> +
>>> +SRC_URI = "file://skeleton \
>>> + file://COPYRIGHT \
>>> + "
>>> +
>>> +CONFFILES_${PN} += "${sysconfdir}/init.d/skeleton"
>>> +
>>> +PACKAGE_ARCH = "all"
>>> +
>>> +do_install () {
>>> + install -d ${D}/${sysconfdir}/init.d
>>> + install -m 0755 ${WORKDIR}/skeleton ${D}/${sysconfdir}/init.d/
>>> +}
>>> +
>>
>> This installs a file that uses directories like /usr which should be
>> replaced with the appropriate setting. For example, in mediatomb (and
>> others) we do this like this:
>>
>> cat ${WORKDIR}/config.xml | \
>> sed -e 's,/etc,${sysconfdir},g' \
>> -e 's,/usr/sbin,${sbindir},g' \
>> -e 's,/var,${localstatedir},g' \
>> -e 's,/usr/bin,${bindir},g' \
>> -e 's,/usr,${prefix},g'> ${D}${sysconfdir}/mediatomb/config.xml
>>
^ permalink raw reply [flat|nested] 10+ messages in thread
end of thread, other threads:[~2011-05-16 1:34 UTC | newest]
Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-05-11 13:41 [PATCH 0/2] Add meta-skeleton and a skeleton for init scripts Robert Yang
2011-05-11 13:41 ` [PATCH 1/2] Add the layer meta-skeleton Robert Yang
2011-05-11 16:27 ` Darren Hart
2011-05-11 13:41 ` [PATCH 2/2] Add a skeleton for init scripts Robert Yang
2011-05-11 17:56 ` Darren Hart
2011-05-12 0:47 ` Robert Yang
2011-05-12 15:41 ` Robert Yang
2011-05-16 1:34 ` Robert Yang
2011-05-12 17:22 ` Saul Wold
2011-05-12 20:31 ` Darren Hart
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.