Slackware init script for cfengine3

#!/bin/sh
# Start/stop/restart cfengine3.

# Set cfengine3 working directory
CFDIR="/usr/local/var/cfengine"

# Start cfengine3 daemons:
cfengine_start() {
  CFMONITORD="$CFDIR/bin/cf-monitord"
  CFEXECD="$CFDIR/bin/cf-execd"
  CFSERVERD="$CFDIR/bin/cf-serverd"

pgrep cf-monitord | grep -v $$ | grep -q -v $PPID
if [ $? -eq 0 ]; then
    echo "cf-monitord is running."
  else
    echo "Starting cf-monitord:  $CFMONITORD"
    $CFMONITORD
  fi

pgrep cf-execd | grep -v $$ | grep -q -v $PPID
if [ $? -eq 0 ]; then
    echo "cf-execd is running."
  else
    echo "Starting cf-execd:  $CFEXECD"
    $CFEXECD
  fi

pgrep cf-serverd | grep -v $$ | grep -q -v $PPID
if [ $? -eq 0 ]; then
    echo "cf-serverd is running."
  else
    echo "Starting cf-serverd:  $CFSERVERD"
    $CFSERVERD
  fi
}

# Stop cfengine3 daemons:
cfengine_stop() {
echo "Stopping cf-execd..."
  if [ -r $CFDIR/cf-execd.pid ]; then
    kill -9 $(cat $CFDIR/cf-execd.pid)
    rm -f $CFDIR/cf-execd.pid
  else
    killall cf-execd
  fi
echo "Stopping cf-monitord..."
  if [ -r $CFDIR/cf-monitord.pid ]; then
    kill -9 $(cat $CFDIR/cf-monitord.pid)
    rm -f $CFDIR/cf-monitord.pid
  else
    killall cf-monitord
  fi
echo "Stopping cf-serverd..."
  if [ -r $CFDIR/cf-serverd.pid ]; then
    kill -9 $(cat $CFDIR/cf-serverd.pid)
    rm -f $CFDIR/cf-serverd.pid
  else
    killall cf-serverd
  fi
}

# Restart cfengine3 daemons:
cfengine_restart() {
  cfengine_stop
  sleep 1
  cfengine_start
}

# Check if cfengine3 daemons are running
cfengine_status() {
pgrep cf-serverd | grep -v $$ | grep -q -v $PPID
if [ $? -eq 0 ]; then
    echo "cf-serverd is running."
  else
    echo "cf-serverd is stopped."
  fi

pgrep cf-monitord | grep -v $$ | grep -q -v $PPID
if [ $? -eq 0 ]; then
    echo "cf-monitord is running."
  else
    echo "cf-monitord is stopped."
  fi

pgrep cf-execd | grep -v $$ | grep -q -v $PPID
if [ $? -eq 0 ]; then
    echo "cf-execd is running."
  else
    echo "cf-execd is stopped."
  fi
exit 1
}

case "$1" in
'start')
  cfengine_start
  ;;
'stop')
  cfengine_stop
  ;;
'restart')
  cfengine_restart
  ;;
'status')
  cfengine_status
  ;;
*)
  echo "usage $0 start|stop|restart|status"
esac

HOWTO: Installing Slackware [armedslack slackwarearm] on the Raspberry Pi

David Spencer over at The Daves Collective has graciously provided an installer image for running armedslack slackwarearm on the Raspberry Pi.

Extrapolated from his instructions, here is a quick install guide:

1. Get the latest installer image here.

(As of this update, I am experiencing a hanging rainbow video output with the latest installer image [raspi-slack-installer_01Aug12.img.xz]. I’m betting that it’s a firmware issue on my end (when I wrote this originally I was running an out-of-the-box Model B,) but haven’t had the time to test.

Fortunately the previous release from July works. If you are having the same problem, try upgrading your firmware first if possible. If not, I’m keeping a copy of the installer hosted for posterity, as it no longer exists at The Daves Collective.)

2. Get armedslack slackwarearm. I like to keep a -current copy (~2.9G) in /usr/local/src with rsync:

$
rsync --exclude '*/source/*' --delete -Pavv ftp.armedslack.org::slackwarearm/slackwarearm-current /usr/local/src/

3. Write the installer image to your SD card where [device] is your SD card writer.
(Take a look at dmesg if you are not sure. You may also run `tail -f /var/log/messages` and then plug in your SD writer.)

$
xz -dc raspi-slack-installer_01Aug12.img.xz | dd of=[device] bs=65536

4. Boot your Pi with the SD card and set the date with ntpdate. You’ll need to run ‘network’ or dhcpcd first.
*Failure to do so will result in all file modification dates being set to the unix epoch, as the Pi has no onboard RTC.

$
ntpdate 0.pool.ntp.org

Alternately, if you don’t have an internet connection you may also use date:

$
date MMDDhhmmYYYY

5. Re-partition the card with cfdisk or fdisk. If your SD card is larger than default 2gb, you’ll want to delete and recreate the root partition:

$
fdisk /dev/mmcblk0
root@pi:/# fdisk /dev/mmcblk0
Welcome to fdisk (util-linux 2.21.2).

Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.

Command (m for help): p

Disk /dev/mmcblk0: 15.9 GB, 15931539456 bytes
4 heads, 32 sectors/track, 243096 cylinders, total 31116288 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00007091

Device Boot Start End Blocks Id System
/dev/mmcblk0p1 32 97663 48816 c W95 FAT32 (LBA)
/dev/mmcblk0p2 97664 878847 390592 82 Linux swap
/dev/mmcblk0p3 878848 3839999 1480576 83 Linux

Command (m for help): d
Partition number (1-4): 3

Command (m for help): n
Command action
e extended
p primary partition (1-4)
p
Partition number (1-4, default 3): 3
First sector (878848-31116287, default 880640):
Using default value 880640
Last sector, +sectors or +size{K,M,G} (880640-31116287, default 31116287):
Using default value 31116287
Partition 3 of type Linux and of size 14.4 GiB is set

Command (m for help): w
The partition table has been altered!

Syncing disks.

6. Run setup and install Slackware as usual. Do not reboot when done.

$
setup

7. If you have done a full install, as per Dave’s suggestion, remove the other kernels with:

$
ROOT=/mnt removepkg \
kernel_kirkwood kernel-modules-kirkwood \
kernel_tegra kernel-modules-tegra \
kernel_versatile kernel-modules-versatile

8. Install the kernel and other packages by running:

$
mount -t vfat /dev/mmcblk0p1 /mnt/boot
ROOT=/mnt installpkg /raspi-extra/kernel* /raspi-extra/raspi*

9. Get rpi-update and upgrade your firmware, if you haven’t already.

$
cd /mnt/usr/local/src
git clone https://github.com/Hexxeh/rpi-update ./rpi-update
touch /boot/start.elf
cd rpi-update
sh ./rpi-update
reboot

10. Optionally, upgrade your kernel. You’ll need to mount /dev/mmcblk0p1 to /boot first. Detailed instructions are here.

$
mount /dev/mmcblk0p1 /boot -t vfat
cd /usr/local/src/
mkdir raspberrypi
cd raspberrypi
git clone --depth 1 git://github.com/raspberrypi/linux.git
cd linux
zcat /proc/config.gz > .config
make menuconfig # optional
time make
time make modules
# 5-11 hours later..
cp arch/arm/boot/Image /boot/kernel.img
make ARCH=arm modules_install INSTALL_MOD_PATH=/
reboot