Jump to content
matugm

Upstart manager

Recommended Posts

matugm

If you have been using a recent Ubuntu version for a while you will know how frustrating can be trying to disable a service that starts at boot so I want to share with you this script I wrote to manage upstart jobs since there is still no built-in tool for this task, hope someone will find it useful.

From http://upstart.ubuntu.com

Upstart is an event-based replacement for the /sbin/init daemon which handles starting of tasks and services during boot, stopping them during shutdown and supervising them while the system is running.

It was originally developed for the Ubuntu distribution, but is intended to be suitable for deployment in all Linux distributions as a replacement for the venerable System-V init.

Example usage:

#!/bin/sh


# Upstart manager - Easily disable and re-enable upstart jobs/services, to list enabled services use "initctl list"

# By matugm matugm@gmail.com


if [ -z $1 ];

then

    echo "Usage: $0 enable/disable [service]"

	exit

fi


if [ `id -u` -ne 0 ]; then

   echo "This script must be run as root." 1>&2

   exit 1

fi


if [ ! -d /etc/init-disabled ];

then

	mkdir /etc/init-disabled

fi


if [ $1 = 'disable' ];

then

	if [ $2 != '' ] && [ -e /etc/init/$2.conf ];

	then

		mv /etc/init/$2.conf /etc/init-disabled

		echo "Service $2 has been disabled."

	else

		echo "Service does not exist or it's already disabled."

	fi

fi


if [ $1 = 'enable' ];

then

if [ $2 != '' ] && [ -e /etc/init-disabled/$2.conf ];

    then

        mv /etc/init-disabled/$2.conf /etc/init

        echo "Service $2 has been enabled."

    else

        echo "Service does not exist or is not disabled."

    fi

fi

#!/bin/sh


# Upstart manager - Easily disable and re-enable upstart jobs/services, to list enabled services use "initctl list"

# By matugm matugm@gmail.com


if [ -z $1 ];

then

    echo "Usage: $0 enable/disable [service]"

	exit

fi


if [ `id -u` -ne 0 ]; then

   echo "This script must be run as root." 1>&2

   exit 1

fi


if [ ! -d /etc/init-disabled ];

then

	mkdir /etc/init-disabled

fi


if [ $1 = 'disable' ];

then

	if [ $2 != '' ] && [ -e /etc/init/$2.conf ];

	then

		mv /etc/init/$2.conf /etc/init-disabled

		echo "Service $2 has been disabled."

	else

		echo "Service does not exist or it's already disabled."

	fi

fi


if [ $1 = 'enable' ];

then

if [ $2 != '' ] && [ -e /etc/init-disabled/$2.conf ];

    then

        mv /etc/init-disabled/$2.conf /etc/init

        echo "Service $2 has been enabled."

    else

        echo "Service does not exist or is not disabled."

    fi

fi

Share this post


Link to post
r00tm4n

h3ll0!

Myself i have always used the update-rc.d to manage startup services in ubuntu

only by doing this:

1. Disable a service during startup

#update-rc.d -f [service] remove

2. Enable a service with defaults

#update-rc.d [service] defaults

I hope it helps.

Edited by r00tm4n

Share this post


Link to post
matugm

This script is not intended to do the same as these commands, that only works for SysV-style services which is based on runlevels.

More info : http://en.wikipedia.org/wiki/Init#SysV-style

However most services have been converted to the new system: Upstart (at least on 10.10), please read my first post for more info on upstart, anyway the problem is that even if you remove the service like that, if it is a upstart job it will still run at startup.

Just installed vsftpd for you to prove this:

matu@ubuntu:~$ ls /etc/rc* | grep ftp

matu@ubuntu:~$ /* Nothing, so there isn't a normal start script for vsftpd */

matu@ubuntu:~$ ls -lh /etc/init.d

lrwxrwxrwx 1 root root 21 2011-07-15 02:20 vsftpd -> /lib/init/upstart-job /* Standard script for services that have been converted to upstart */

matu@ubuntu:~$ initctl list | grep vsftpd /* list upstart jobs */

vsftpd start/running, process 18068

matu@ubuntu:~$ sudo update-rc.d -f vsftpd remove

Removing any system startup links for /etc/init.d/vsftpd ...

matu@ubuntu:~$ initctl list | grep vsftp

vsftpd stop/waiting // Still there, so it will run at startup

From the man page

update-rc.d - install and remove System-V style init script links.

After rebooting, surprise!

tcp 0 0 0.0.0.0:21 0.0.0.0:* LISTEN 1533/vsftpd

It's running.

@r00tm4n

Welcome to our forums, please don't feel discouraged to keep posting, but try to understand what you are answering to first.

Share this post


Link to post
t3rm1t

Hi, Matugm.

What do you think about kernel patches such as Zen kernel or GRsecurity?

Share this post


Link to post

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
×