Slashdot stories can be listened to in audio form via an RSS feed, as read by our own robotic overlord.

 



Forgot your password?
typodupeerror

Slashdot videos: Now with more Slashdot!

  • View

  • Discuss

  • Share

We've improved Slashdot's video section; now you can view our video interviews, product close-ups and site visits with all the usual Slashdot options to comment, share, etc. No more walled garden! It's a work in progress -- we hope you'll check it out (Learn more about the recent updates).

×
User Journal

Journal: Systemd's solution to large init scripts 1

Journal by phantomfive

(Note: When you write code, you're making a UI for programmers. Learn to do it well.)

Below you can see a traditional unix init script. It's long, but if you're familiar with shell-script you can figure out what is going on. There is a lot of redundancy here, most init scripts have a switch that runs an option based on the first command-line parameter, for example. One solution is to put common code in a function, but Poettering decided to use config files.

Let's examine the general tradeoff between putting code in a function, and using config files (a form of declarative programming). Config files are fine as long as there aren't too many special cases. If there are too many special cases, you end up with so many options and keywords that it would have been easier to just use a scripting language.

The good side is systemd saves a lot of typing. Way down at the bottom, is a unit file for the same init script. It's clearly shorter, and easier to type.

The bad side is it has arcane keywords which are are not discoverable merely by looking at the file. This is a pattern that repeats itself over and over in systemd, things are easier if you know how to do them, but the system itself is inscrutable without arcane knowledge.

Ideal systems fulfill the requirements while making it easy for those who want to dig deeper. The system opens like the petals of a rose.

#!/bin/bash
# Starts the abrt daemon
#
# chkconfig: 35 82 16
# description: Daemon to detect crashing apps
# processname: abrtd
### BEGIN INIT INFO
# Provides: abrt
# Required-Start: $syslog $local_fs
# Required-Stop: $syslog $local_fs
# Default-Stop: 0 1 2 6
# Default-Start: 3 5
# Short-Description: start and stop abrt daemon
# Description: Listen to and dispatch crash events
### END INIT INFO
 
# Source function library.
. /etc/rc.d/init.d/functions
ABRT_BIN="/usr/sbin/abrtd"
LOCK="/var/lock/subsys/abrtd"
OLD_LOCK="/var/lock/subsys/abrt"
RETVAL=0
 
#
# Set these variables if you are behind proxy
#
#export http_proxy=
#export https_proxy=
 
#
# See how we were called.
#
 
check() {
    # Check that we're a privileged user
    [ "`id -u`" = 0 ] || exit 4
 
    # Check if abrt is executable
    test -x $ABRT_BIN || exit 5
}
 
start() {
 
    check
 
    # Check if it is already running
    if [ ! -f $LOCK ] && [ ! -f $OLD_LOCK ]; then
        echo -n $"Starting abrt daemon: "
        daemon $ABRT_BIN
        RETVAL=$?
        [ $RETVAL -eq 0 ] && touch $LOCK
        echo
    fi
    return $RETVAL
}
 
stop() {
 
    check
 
    echo -n $"Stopping abrt daemon: "
    killproc $ABRT_BIN
    RETVAL=$?
    [ $RETVAL -eq 0 ] && rm -f $LOCK
    [ $RETVAL -eq 0 ] && rm -f $OLD_LOCK
    echo
    return $RETVAL
}
 
restart() {
    stop
    start
}
 
reload() {
    restart
}
 
case "$1" in
start)
    start
;;
stop)
    stop
;;
reload)
    reload
;;
force-reload)
    echo "$0: Unimplemented feature."
    RETVAL=3
;;
restart)
    restart
;;
condrestart)
    if [ -f $LOCK ]; then
        restart
    fi
    # update from older version
    if [ -f $OLD_LOCK ]; then
        restart
    fi
;;
status)
    status abrtd
    RETVAL=$?
;;
*)
    echo $"Usage: $0 {start|stop|status|restart|condrestart|reload|force-reload}"
    RETVAL=2
esac
 
exit $RETVAL

-----------------------------------------------------------------------------------------

[Unit]
Description=Daemon to detect crashing apps
After=syslog.target
 
[Service]
ExecStart=/usr/sbin/abrtd
Type=forking
 
[Install]
WantedBy=multi-user.target

Reference to the examples.

User Journal

Journal: systemd - Why did Debian Adopt it? 8

Journal by phantomfive

There's a Debian debate page, but it's disappointing and everything systemd does is listed with equal value. Thanks to Russ Albery for making a much more balanced assessment, explaining what he likes. The short answer to the question is: SystemD makes things much easier for people writing init scripts. It wasn't about cgroups, or speed, or login managers, it was about writing easy init scripts.

Here are the major complaints he has with the traditional startup system:

* Lack of integration with kernel-level events to properly order startup.
* No mechanism for process monitoring and restarting beyond inittab.
* Heavy reliance on shell scripting rather than declarative syntax.
* A fork and exit with PID file model for daemon startup.

He furthermore points out these problems with startup scripts:

The model of fork and exit without clear synchronization points is inherently racy, the boot model encoded into sysvinit doesn't reflect a modern system boot, and maintaining large and complex init scripts as conffiles has been painful for years. Nearly every init script, including the ones in my own packages, have various edge-case bugs or problems because it's very hard to write robust service startup in shell, even with the excellent helper programs and shell libraries that Debian has available.

Those are the main things that systemd fixes for a distro builder, and probably why so many distros have switched to systemd, because it was built for them.

User Journal

Journal: systemd - A descendent of Apple's LaunchD 1

Journal by phantomfive

Systemd is a descendent of Apple's launchd, Lennart suggested the world watch this movie to learn about it, so why? What is good about launchd?

OSX has an excellent inter-processing message system, part of the mach kernel (which they got from CMU). Because of this, many times processes talk to each other through the standard messaging queues. If you use a library to launch a browser window, or query wifi strength, it will communicate through a message queue (although the library takes care of the details).

The interesting thing is that launchd can open a message queue before the recipient is running. So launchd doesn't launch services until they are needed, and if they aren't needed, they never get launched. The benefit is that resources are preserved, things don't get launched until someone sends a message.

The benefit here is dependency resolution. Instead of forcing a deep calculation of what depends on what, or forcing the server script to declare everything it depends on, you can say "manage all these thousand services!" and only the few that are needed will be used, when they are needed.

Another thing I think Lennart copied from launchd is the declarative config files. You don't need to write a shell script, you merely need to indicate what should be launched, and maybe give it configuration options like "relaunch on failure" or "launch completely before receiving message." Of course, some people like config files, others prefer scripts.....that's not an argument I want to get into here, I'm merely pointing out things that seem to have come from launchd. (

What is bad:

Launchd is utterly undiscoverable. It would have been nice of them to put a README in /etc/rc/ or something saying, "hey, all your startup scripts are gone, look elsewhere."

Launchd has a complex hierarchy of directories that it searches for startup scripts. They have justifications for why, and a reason behind each one.......but justifications and reasons are not the same as good design. Every bad design decision ever made had a justification and a reason.

User Journal

Journal: Systemd - Efficiency and Pike's Rules of Programming 4

Journal by phantomfive

(DISCLAIMER: These are my notes and might be wrong.)

Lennart Poettering has never heard of Rob Pike's rules of programming. Let's examine why:

He said, "On my system the scripts in /etc/init.d call grep at least 77 times.... that has to be incredibly slow...., and should be rewritten in C."

You can time it yourself, with this command:

time for i in {1..77}; do grep user /etc/passwd > /dev/null; done

On my machine it takes 0.229 seconds.

Lennart didn't get the speed increase he wanted. From his benchmark report, "booting up with Upstart takes 27s, with systemd we reach 24s." This result isn't too bad: when I've made a similar mistake of writing code before timing anything, ignoring Pike's rules for programming, once I actually slowed the system down.

If you don't measure, you can't optimize.

For entertainment and enlightenment, here is a quote by Ken Thompson talking vaguely about Pike's rules for programming:

Early Unix programmers became good at modularity because they had to be. An OS is one of the most complicated pieces of code around. If it is not well structured, it will fall apart. There were a couple of early failures at building Unix that were scrapped. One can blame the early (structureless) C for this, but basically it was because the OS was too complicated to write. We needed both refinements in tools (like C structures) and good practice in using them (like Rob Pike's rules for programming) before we could tame that complexity.

User Journal

Journal: SystemD: The Beginning 7

Journal by phantomfive

DISCLAIMER: THIS CODE REVIEW IS A LONG WORK IN PROGRESS, I COULD BE COMPLETELY WRONG IN ANYTHING I SAY.

To do a proper code review, you need to understand the purpose of the code, what all the stakeholders want. From my own perspective, init scripts work fine, but since Unix companies keep trying to create new init systems, they must have different needs than I do.

Here's a list of the stakeholders. I need to figure out what their goals are.
1) System admins.
2) Desktop users.
3) Distro builders.
5) Android (if systemd turns out to be good enough).
4) Programmers

My suspicion is that systemd has taken over because it makes things easier for 3.

At its core, Unix is a system for programmers. What other system comes with a compiler and multiple interpreters by default? Bash is so much more useable than DOS, or even powershell (yeah, go ahead and flame me but I'm right, Powershell doesn't even have < working). Unix was designed by programmers and for programmers.

The reason I'm talking about it is the traditional init process is incredibly discoverable. All you have to do is look in the /etc/rc directories, and you can figure out how your system boots. You can see it all. For a programmer it's easy. Poking around in the system to understand it is one thing that makes Unix great (and what I like about Slackware: the whole thing is lovingly crafted).

So that describes the approach I am taking to code review, and to the init process. Hopefully Systemd is an improvement.

User Journal

Journal: success!

Journal by retchdog

after ages of playing it low-key, i've managed to take my first karma hit ever by punching my abrasive style to the maxxxx! awesome. i hate this fucking place. too bad you guys can't kick me out. :) :) :) :)

User Journal

Journal: Economics in Brief (Internet Flotsam)

Journal by lgw

Here's some internet flotsam attributed to a graduation speech by Thomas Sargent (without digging into whether this speech really happened: the content is interesting).

Economics is organized common sense. Here is a short list of valuable lessons that our beautiful subject teaches.

1. Many things that are desirable are not feasible.

2. Individuals and communities face trade-offs.

3. Other people have more information about their abilities, their efforts,
and their preferences than you do.

4. Everyone responds to incentives, including people you want to help. That
is why social safety nets don't always end up working as intended.

5. There are tradeoffs between equality and efficiency.

6. In an equilibrium of a game or an economy, people are satisfied with their
choices. That is why it is difficult for well meaning outsiders to change
things for better or worse.

7. In the future, you too will respond to incentives. That is why there are
some promises that you'd like to make but can't. No one will believe those
promises because they know that later it will not be in your interest to
deliver. The lesson here is this: before you make a promise, think about
whether you will want to keep it if and when your circumstances change.
This is how you earn a reputation.

8. Governments and voters respond to incentives too. That is why governments sometimes default on loans and other promises that they have made.

9. It is feasible for one generation to shift costs to subsequent ones. That is
what national government debts and the U.S. social security system do
(but not the social security system of Singapore).

10. When a government spends, its citizens eventually pay, either today or
tomorrow, either through explicit taxes or implicit ones like inflation.

11. Most people want other people to pay for public goods and government
transfers (especially transfers to themselves).

12. Because market prices aggregate traders' information, it is difficult to forecast stock prices and interest rates and exchange rates.

User Journal

Journal: overrated again. 1

Journal by sumdumass

Wow.. took a break from slashdot for a while and already the mass down mods are happening again. Its no wonder why almost every story has posts with people crying about how slashdot has turned to shit. I guess it is a sign of how desperate someone's position is when they have to downmod with overrated just to stop an opinion they disagree with from being seen.

What's that saying about reality is everything that remains when you close you eyes and stop choosing to believe in something? I guess the same is true with the downmods. Just because they attempt to hide the comment doesn't mean the statement stops being true, it only means it stops being seen as easily. I can imagine a group of idiots sitting around plotting and planning thier down mod adventures in a comic book esq setting with them laughing about how they will win the war of whatever they deemed important at the minute, by not letting others speak or letting their speech be seen/heard. Then they stop to pop their zits and return to the plotting while declaring that if they are the only ones heard, they would always win,.

Of course the reality is probably much simpler and less sinister. It is more likely someone got but hurt by a comment made and while sitting in their mom's basement reassessing the pathetic life they live, decide to take their anger and frustrations out by mass downmodding someone they disagree with. They might pause for a minute to wipe the tears from their eyes, but are set to teach someone a lesson about having opinions contrary to their own.

User Journal

Journal: good evening sodless godomites! 1

Journal by retchdog

maximizing the experiential entropy, in the limit of large N, characterizes the geom(1/2) distribution.

rape my cat. rape my cat. rape my cat. rape my cat. rape my cat. rape my cat. rape my cat. rape my cat. rape my cat. rape my cat. rape my cat. rape my cat. rape my cat. rape my cat. rape my cat. rape my cat. rape my cat. rape my cat. rape my cat. rape my cat. rape my cat. rape my cat. rape my cat. rape my cat. rape my cat. rape my cat. rape my cat. rape my cat. rape my cat. rape my cat. rape my cat. rape my cat. rape my cat. rape my cat. rape my cat. rape my cat. rape my cat. rape my cat. rape my cat. rape my cat. rape my cat. rape my cat. rape my cat. rape my cat. rape my cat. rape my cat. rape my cat. rape my cat. rape my cat. rape my cat. rape my cat. rape my cat. rape my cat. rape my cat. rape my cat. rape my cat. rape my cat. rape my cat. rape my cat. rape my cat. rape my cat. rape my cat. rape my cat. rape my cat. rape my cat. rape my cat. rape my cat. rape my cat. rape my cat. rape my cat. rape my cat. rape my cat. rape my cat. rape my cat. rape my cat. rape my cat. rape my cat. rape my cat. rape my cat. rape my cat. rape my cat. rape my cat. rape my cat. rape my cat. rape my cat. rape my cat. rape my cat. rape my cat. rape my cat. rape my cat. rape my cat. rape my cat. rape my cat. rape my cat. rape my cat. rape my cat. rape my cat. rape my cat. rape my cat. rape my cat. rape my cat.

User Journal

Journal: Geothermal vs Solar Power 1

Journal by lgw

Here are the basic numbers on aailable geothermal vs solar power (since this has come up in discussion more than once).

The surface area of the Earth is about 5.1 x 10^14 m^2. The cross sectional area is about 1.3 x 10^14 m^2 (one quarter of the surface area, of course).

Per this paper found as a cite on wikipedia, the total heat flow out from the Earth's interior is 4.42 x 10^13 W, or 0.0867 W/m^2. Of course, the available power is much less because it's only the subsurface-surface temperature difference that's available.

Total solar irradience is 1361 W/m^2 by NASA's latest estimate (so about 1.7 x 10^17 W across the entire cross section), or about 1000 W/m^2 on the surface at noon on a cloudless day. Averaged over the day-night cycle (surface area vs cross-section, so 250 W/m^2), and taking clouds into account that's about 180 W/m^2 (I can't find a solid source on that yet, but it looks close).

So, total solar power flow is about 4000 times as large as total geothermal flow. I'm not quite sure how to estimate the (ideal) available power as a percentage of the total geothermal power flow, but if we use a WAG of 50%, then the available power from solar is also about 4000 times per square meter more than geothermal - significantly more if we average solar power only across populated latitudes.

User Journal

Journal: wtf 2

Journal by retchdog

here i am, modding up trolls; aspiring gadflys; inarticulate racists; and even the occasional goatse link... and i'm still getting an average of 15 mod points a week!

User Journal

Journal: Slashdot suggestions

Journal by 7-Vodka

There really need to be two new buttons on the story's title bars. One to allow bookmarking for later reading and one to allow bookmarking for later reference; creating two lists. Later, one can read stories they pre-selected when they didn't have the time to fully explore and one can also pull up stories as references easily.

The sooner you make your first 5000 mistakes, the sooner you will be able to correct them. -- Nicolaides

Working...