Nov
13
“Service” Tool Available on Ubuntu 7.10
Filed Under Linux
I spent the day teaching a class on Redhat Enterprise Linux 5 and in doing so got in the habit of using some Redhat specific commands. After class when I got back on my Ubuntu laptop I attempted to restart a service using “service network restart”. Instead of complaining about the service command not being found it instructed me that if I wanted that tool I would need to install the sysvconfig.
If you’re familiar with the Redat tool, service, and would like that functionality on Ubuntu simply do the following:
sudo aptitude install sysvconfig
Once this package is installed you can then start, stop or restart services on your machine using commands like:
sudo service apache2 restart
sudo service ntpd stop
sudo service network restart
As far as I understand this is equivalent to running:
sudo /etc/init.d/apache2 restart
If anyone knows any other differences between ’service’ and ‘/etc/init.d/’ I’d be interested in hearing about them. Enjoy.
If this site has been useful, please consider participating in the Fundraiser.
Other Points of Interest
Comments
13 Responses to ““Service” Tool Available on Ubuntu 7.10”
Leave a Comment
This goes in the mix with “invoke-rc.d”?
I’ve installed it: what’s the command line to show all services?
Use the source!
cat /usr/sbin/service
The two things that stand out to me are:
–status-all
–full-restart
Other then that, looks about the same - as one would expect.
There’s also ‘invoke-rc.d’, installed by default, which can do things like this:
invoke-rc.d –query apache2
On my Ubuntu box:
root@server:~# service –status-all

–status-all does nothing on Debian
“–status-all does nothing on Debian”
And sadly it can’t do anything. Upstart FTW?
The differens between /etc/init.d and service is that service sets all environment variables as they are when calling the init-scripts at boot.
When doing /etc/init.d you may inherit some variables from the shell you call it from
I know that Red Hat’s classes make heavy use of their “service” command. IMNSHO, this is largely because they want people to be used to it and not be comfortable with other systems which don’t have it.
However, the “service” command is really pretty useless. Instead of running “service foo reload” (for example), simply type in “/etc/init.d/foo reload”. Wow, that works just the same, but there are a few advantages:
1. It’s portable. Using “/etc/init.d/foo something” will work on Red Hat, SUSE, Solaris, (Open|Free|Net)BSD, AIX, IRIX, HP-UX, zOS, UNICOS, etc., etc., etc. In other words, every UNIX and UNIX-like OS I’ve ever run into.
2. It’s less typing. You can use TAB (or ESC, ESC, depending on your shell) completion to save keystrokes and to find filenames that differ a little from one system to the next.
3. It doesn’t “lock you in” to a proprietary tool. OK, calling Red Hat’s “service” script proprietary isn’t exactly a fair characterization. For a long time, they’ve been the only ones who had it, but there is a similar implementation now available on SUSE Linux Enterprise Server and now Ubuntu. They’re doing that to help people make the transition from Red Hat a little more easily.
The long and the short of all this is the one really should just learn and use the “portable habit” of typing “/etc/init.d/” instead of “service “. Christer, I would hope that you would do that in your Red Hat classes, too. Trust me when I say that your students will appreciate that approach.
Thanks for a very useful post. I’ve become used to the service command from Mandriva/PCLinuxOS and have wondered what to do here in Ubuntu.
Thanks for this. I always missed the redhat way of restarting service.
As others noted, debian based distributions have invoke-rc.d which has the same role.
As for Lamont’s second point: with shell completion it not much more typing. invo[TAB] po[TAB] r[TAB] and postresql is restarted.
I can see one more point for using service/invoke-rc.d. See, initscripts aren’t guaranted to stay. upstart rules, D-Bus activation, Solaris SMF, daemontools, other init systems, they all do not have initscripts or have them modified. service/invoke-rc.d should be viewed as abstraction layer for them. Use “service somethin start”. Do not choose between “svcadm enable something”, “/etc/init.d/something start”, “/etc/rc.d/rc.something start”, “dbus-send com.ubuntu.upstart.Start something”, “svc -o /service/something” or billion other methods .
Thanks. I got my start with Fedora and got used to using the service command.
I wish I would have known that. I wound up writing a simple script that simply added the /etc/init.d/ in front of what you were wanting to work w/.
example:
service apache2 restart
that would run:
/etc/init.d/apache2 restart
I guess it does the same thing, but I would love to have all the other tools. Thanks for letting us know about this find.