home.


Tagged: debian


Unix: Systemv init system (Debian) tutorial

The systemv init system is used in Debian and many other distributions, although will be replaced by systemd in Jessie or later I believe.

System scripts live in /etc/init.d and these are simple executable shell scripts that take a paramter and perform actions. Systemv init demands they take in a ‘start’ and ‘stop’ parameter and start their service.

Systemv init has various run levels. A run level is simply a state in which your system has certain services running.

Level 1 is sinle user mode where there are few services running. Level 0 is when the system is getting ready to be shutdown, i.e. the services are being stopped. Level 6 is similar to level 0 except the system is getting ready for a reboot. Level 2-5 are multi-user levels and are generally the same in most distributions. There’s special level ‘S’ which is run when the system is starting.

Each runlevel defines its services in /etc/rc[RUNLEVELHERE].d/ as symlinks to the services located in /etc/init.d/. If the syslink is of the form S01servicename then the service is started in that level. If it’s of the form K01servicename then the service is stopped. The numbers in the names define the order in which the services are started.

Services on debain are managed by the update-rc.d program.

  • To add a service symlinks to the default run levels, ie. K01tomcat7 in /etc/rc[0,1,6].d/ and S01tomcat7 in the other, /etc/rc[2-5] directories, run

    update-rc.d tomcat7 defaults
    
  • To remove the service symlinks from the runlevel directories, run

    update-rc.d -f tomcat7 remove
    

Note that on updating the package, it will re-run update-rc.d to reinsert the links if they’re not in the runlevels, so you’re better of disabling instead.

  • To disable a service from the runlevels, run

    update-rc.d -f tomcat7 disable
    

This will turn all the S16tomcat7 links in the runlevels to K01tomcat7 links, thereby disabling the service.

You’ll get a warning about the service being disabled, when the LSB headers in the init.d/ file says it should be enabled.

  • To enable a service, run

    update-rc.d -f tomcat7 enable
    

This will ensure all the links in the rc[2-5].d/ are in the form S14tomcat7, thereby starting the service in those levels. If the service itself tells you what runlevels to start and stop in its script, update-rc.d will use that.

unix debian systemvinit

Installing Docker in Debian (testing/Jessie)

You need to be running a 3.8 kernel or above, hence the need for Jessie and the installation of that kernel.

You need to install golang, and specially 1.2 or above else you’ll get ipv6 errors, too. Get it from golang.org

You also need to have lxc and aufs-tools

apt-get install lxc aufs-tools

Then you need to setup your GOPATH environmental variable, create the docker directory in the src directory and clone docker into that.

export GOPATH=/your/go/directory
cd $GOPAth
mkdir -p src/github.com/dotcloud/
cd src/github.com/dotcloud
git clone https://github.com/dotcloud/docker

Then cd into the docker directory to use golang to pull all the dependencies and install docker into your GOPATH’s bin directory

cd docker
go get -v github.com/dotcloud/docker/...
go install -v github.com/dotcloud/docker/...

(The three dots mean do this for all the packages under said directory)

You should be able to run docker via

$GOPATH/bin/docker

Before you can run a docker image you need to mount cgroups. Put this in your /etc/fstab

none        /cgroup        cgroup        defaults    0    0

And then run

mkdir /cgroup && mount -a

You also need to enable ipv4 forwarding else your container won’t be able to talk to the outside world.

sysctl -w net.ipv4.ip_forward=1

Finally you need to run docker as a daemon, and as root, too.

$GOPATH/bin/docker -d &
2013/10/19 23:15:48 WARNING: cgroup mountpoint not found for memory
2013/10/19 23:15:48 Listening for HTTP on /var/run/docker.sock (unix)

Now you can issue a pull request to get the base 120MB ubuntu container from the internet.

$GOPATH/bin/docker pull ubuntu

After it’s downloaded it all, you can now use that container.

$GOPATH/bin/docker run ubuntu echo 'omg'

This should product something like

2013/10/19 23:22:55 POST /v1.6/containers/create
2013/10/19 23:22:55 POST /v1.6/containers/3fe0676d7e00/attach?stderr=1&stdout=1&stream=1
2013/10/19 23:22:55 POST /v1.6/containers/3fe0676d7e00/start
omg
2013/10/19 23:22:55 GET /v1.6/containers/3fe0676d7e00/json
unix unix-debian docker

Debian: Setting up Postgresql 9.1 on Debian Squeeze

First add the squeeze backports to /etc/apt/sources.list:

    deb http://backports.debian.org/debian-backports squeeze-backports main

Then issue:

    apt-get update
    apt-get -t squeeze-backports install postgresql-9.1

Then login as the postgres user and start up psql:

    su - postgres
    psql

Now create a new user with a new password and create a database as that user:

    create user myuser password 'mypassword'
    create database mydatabase owner myuser;
    \q

Now you’ve exited psql, log out of the postgres unix user, and attach the the postgres program remotely:

    <ctrl-d>
    psql -h localhost -U myuser -d mydatabase

Now it’ll ask you to enter in the password ‘myuser’. You can now start issuing sql commands. Or \? to see help for psql commands.

unix unix-debian postgresql

Debian: Stopping a service from starting at startup

To remove a service, apache2 in this case, from running at all runlevels:

 update-rc.d -f apache2 remove

This will remove the apache2 file (located in /etc/init.d/) symlink from all the /etc/rcX.d/ directories.

To simply stop a service:

 service apache2 stop

You can replace stop with start to start it.

unix unix-debian unix-debian-services

Installing the 32bit multiarch compatibility

To use a program compiled for 32 bit, the Android development tools for example, you need the ia32 compatibility package if you’re using 64 bit.

First add i386 to your list of architectures, update apt-get then install ia32

 dpkg --add-architecture i386
 apt-get update
 apt-get install ia32-libs

If you need to install a 32 bit version of something, issue the command as normal but with :i386 appended:

 apt-get install libncurses5:i386
unix unix-debian-ia32 unix-debian

Page 1 of 1