Want to read Slashdot from your mobile device? Point it at m.slashdot.org and keep reading!

 



Forgot your password?
typodupeerror
×
User Journal

Journal Journal: Systemd's solution to large init scripts 1

(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 Journal: systemd - Why did Debian Adopt it? 8

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 Journal: *spoiler* winter dragon The wheel of time review 1

i saw the pilot for a potential wheel of time tv series. if you've read the books, it's nothing new but for any diehard fan it is a must see. it takes place in the age of legends just after the taint. the actors did a decent job, the scenes were ok and the special effects were laughable. but this is a pilot and it was based on perhaps 1 or 2 pages from the book. apparently the company that holds the rights to WoT was obligated to make something WoT to not lose the tv/movie rights. it was filmed in a single day by a crew that makes a lot of pilot episodes, it's overall quality is very poor but i don't blame the actors it simply is a pilot and they are making it to not lose rights to something they think more people will pay for it if they wait for the big networks to buy the rights to air the program. that being said i would geek out if i got the actual file(DVR quality) for the pilot. they have made series that are worse than the WoT pilot before. i remember how bad SG1 was in it's early seasons, but i still loved it. a WoT series would be awesome but i would prefer it to be on a channel i get... or on netflix or amazon prime. getting fxx is out of the question and getting a dvr would require me paying my dad the cost for switching to the satelite to dvr model instead of the regular service we have now... needless to say this is not something i can't live without. i already have more entertainment than i have time to watch (unless i went off line and only watched my physical discs) or if i quit social media and went to streaming/buying discs but i am a news and social media junkie and it took me a long time to quit gaming, so i wouldn't really expect me to have an easy time quitting social media...

User Journal

Journal Journal: Keep burning those modpoints, punk 4

http://slashdot.org/comments.pl?sid=6928647&cid=49008431
http://slashdot.org/comments.pl?sid=6921395&cid=49008481
http://slashdot.org/comments.pl?sid=6928395&cid=49008511
http://slashdot.org/comments.pl?sid=6928647&cid=49008549
http://slashdot.org/comments.pl?sid=6921395&cid=49008565

User Journal

Journal Journal: You can all blame me 39

I'm really past caring. Somewhere around the thousandth iteration, the trash talk just got tedious. It's my fault. I'll take the hit, like an RPG striking a helicopter carrying Brian Williams. I just can't muster the interest any more.

User Journal

Journal Journal: bought a color laser printer from newegg

it's a Brother brand printer and supports linux, but it's wifi enabled too, and the wifi and lan printing are exclusive of each other. the linux machines are only postscript over lan supported but since i rarely print and my dad needs to be able to print wirelessly i am using it's wireless drivers. i can see why they don't recommend color laser printers for home users. anyways it's an awesome setup and well worth the money, in my oplinion

User Journal

Journal Journal: Yay, I made an idiot angry! 8

Then they modded down five of my comments in a row. Why doesn't the system catch this kind of obviously abusive moderation? Oh right, because this is slashdot, not someplace with competent employees.

http://slashdot.org/comments.pl?sid=6897301&cid=48979217
http://slashdot.org/comments.pl?sid=6897699&cid=48979955
http://slashdot.org/comments.pl?sid=6898589&cid=48984949
http://slashdot.org/comments.pl?sid=6904433&cid=48985865
http://slashdot.org/comments.pl?sid=6904445&cid=48986419

If moderation on slashdot were intelligently designed, this person's abusive moderation would have been autodetected and they would have been banned from moderation permanently.

User Journal

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

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 Journal: Worth it for the howls on here alone 51

What's changed is that Walker has, in the last week, gone national. His speech at the Iowa Freedom Summit earned rave reviews, and was followed with what appears to be the first pro-Walker presidential ad. And everyone seems to have noticed what Walker's opponents in Wisconsin have learned the hard way, repeatedly: he's a formidable politician. This should worry his GOP rivals not only because of Walker's win streak, but also because Walker is doing something many of them aren't: he's setting the terms of the debate instead of following the terms the Democrats have set.

Walker has the same virtue as Sarah Palin: making the Left wet itself. Unlike Palin, Walker has a substantially better record of standing in the breach and surviving. Stipulate that fustakrakich is correct, and it's all rigged. Fine. Let's go for max Lefty head 'splosions, then.

User Journal

Journal Journal: Round Three 10

I'm growing to despise the word "entitled", preferring "earned" or "merited":

I think it's a real opportunity for federalism to allow states and local school boards to figure out what works for them. There isn't a thing wrong with the Department of Education that we can't fix by just reducing to some light oversight. In particular, federal financial interactions with non-employees should just stop.

Previously:
1. All forms of racial segregation and discrimination are wrong. 2. Everyone is entitled to his own opinion.

Slashdot Top Deals

Never ask two questions in a business letter. The reply will discuss the one you are least interested, and say nothing about the other.

Working...