LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Slackware
User Name
Password
Slackware This Forum is for the discussion of Slackware Linux.

Notices


Reply
  Search this Thread
Old 12-02-2012, 04:59 AM   #1
mlpa
Member
 
Registered: May 2008
Location: Aveiro
Distribution: Slackware
Posts: 542

Rep: Reputation: 50
Script similar to service command in Debian


Hi, I used some Debian servers in my University and one of the commands that I like is the service command.

I just write service the name of the script and the arguments. It is useful since I have a lot of deployment scripts that use SSH.

Now I want to change my server to Slackware
But I wanted to preserve the deployment script.

So here is my script that tries to emulate the service command in Debian.

Any suggestion is welcome, and feel free to use it.

Quote:
#!/bin/bash

PRG=`basename $0`
SERVICE_PATH="/etc/rc.d/"
PREFIX="rc."
N_ARGS=1

### Error codes based on linux error codes
ERROR_BAD_ARGS=22
ERROR_SERVICE_NOT_FOUND=2
ERROR_SERVICE_NOT_EXECUTABLE=1

if [[ $# < $N_ARGS ]]; then
echo "Usage: $PRG \"service name\" \"service args\""
exit $ERROR_BAD_ARGS
fi

ARRAY=("$@")
ARGS=""

for (( i=1; i<$#; ++i))
do
ARGS="$ARGS ${ARRAY[$i]}"
done

if [ -e "$SERVICE_PATH$1" ]; then
SERVICE="$SERVICE_PATH$1"
elif [ -e "$SERVICE_PATH$PREFIX$1" ]; then
SERVICE="$SERVICE_PATH$PREFIX$1"
else
echo "Service not found"
exit $ERROR_SERVICE_NOT_FOUND
fi

if [ -x $SERVICE ]; then
SERVICE="$SERVICE $ARGS"
else
echo "Service not executable"
exit $ERROR_SERVICE_NOT_EXECUTABLE
fi

exec $SERVICE
Another command that I am planning to emulate is insserv.
Giving a service script it copies to rc.d and add a line to rc.local.
Something like this.
Attached Files
File Type: txt service.txt (765 Bytes, 29 views)
 
Old 12-03-2012, 04:39 PM   #2
rouvas
Member
 
Registered: Aug 2006
Location: Greece
Distribution: Slackware.12.2
Posts: 104
Blog Entries: 3

Rep: Reputation: 21
Your deployment (of what?) depends on starting services on machines?
What are you deploying?

It seems pointless to me.
 
Old 12-04-2012, 03:42 AM   #3
wildwizard
Member
 
Registered: Apr 2009
Location: Oz
Distribution: slackware64-14.0
Posts: 875

Rep: Reputation: 282Reputation: 282Reputation: 282
Correct me if I'm wrong but isn't the service command a RedHat derivative?

Any way you'll be happy to know that Slackware has the ability to start and stop scripts that use the sysvinit style used by other distros, you'll just need to write a script that sets them up in the right directories and they will run automatically.

See /etc/rc.d and its sub-directories.
 
Old 12-05-2012, 09:55 AM   #4
mlpa
Member
 
Registered: May 2008
Location: Aveiro
Distribution: Slackware
Posts: 542

Original Poster
Rep: Reputation: 50
Quote:
Originally Posted by rouvas View Post
Your deployment (of what?) depends on starting services on machines?
What are you deploying?

It seems pointless to me.
By deploying I meant, compile code, pack a jar or a binary rsync with the server machine added the new service script and restart the service.
I have scripts that do all of this.
Until now the server machines were always Debian or Ubuntu distros, so my scripts have a line similar to service "service" start.
Since I want portability I am emulating this command.

Apart for portability there is another issue: Slackware is not that widely used (as sad as it is)
So I can not rewrite my deploy scripts because there are other persons involved that do not have contact with Slackware.

In summary portability and a common interface for my lab.

Quote:
Correct me if I'm wrong but isn't the service command a RedHat derivative?

Any way you'll be happy to know that Slackware has the ability to start and stop scripts that use the sysvinit style used by other distros, you'll just need to write a script that sets them up in the right directories and they will run automatically.

See /etc/rc.d and its sub-directories.
Maybe service command is from RedHat.
I can only say it is available in Debian.
The issue is not running the script, the issue is to have a deploy script that deploys in Slackware and (at least) Debian distros.

I am not saying it is useful for everyone.
If you like the idea use it, if you have fixes to the script please tell me.
If you do not need this emulation do not use it.

We have a choice now
 
Old 12-05-2012, 05:12 PM   #5
FeyFre
Member
 
Registered: Jun 2010
Location: Ukraine, Vinnitsa
Distribution: Slackware
Posts: 351

Rep: Reputation: 30
And again we have here Yet-Another-Implememntation-Of-service-Command-For-Slackware.


PS: Yes, service is RedHat's(and derivatives) command.
 
Old 12-06-2012, 03:13 AM   #6
rouvas
Member
 
Registered: Aug 2006
Location: Greece
Distribution: Slackware.12.2
Posts: 104
Blog Entries: 3

Rep: Reputation: 21
I still don't get it.
Why do you want to be distro-specific?

Why don't you follow the SysV way of placing your startup/shutdown scripts in /etc/rc.d/rc3.d (example for runlevel 3) and you have to follow somebody else's bright idea? Or you can follow the BSDish way (that Slackware does) and place them at the /etc/rc.d. Be a little creative and combine the two methods (a symbolic link or two is not that hard).

Is it inevitable that in Linux we should repeat the follies of the Unix-wars?
 
Old 12-06-2012, 03:26 AM   #7
mlpa
Member
 
Registered: May 2008
Location: Aveiro
Distribution: Slackware
Posts: 542

Original Poster
Rep: Reputation: 50
Quote:
Originally Posted by rouvas View Post
I still don't get it.
Why do you want to be distro-specific?

Why don't you follow the SysV way of placing your startup/shutdown scripts in /etc/rc.d/rc3.d (example for runlevel 3) and you have to follow somebody else's bright idea? Or you can follow the BSDish way (that Slackware does) and place them at the /etc/rc.d. Be a little creative and combine the two methods (a symbolic link or two is not that hard).

Is it inevitable that in Linux we should repeat the follies of the Unix-wars?
I personally agree with what you say. But the point is, in this department the winning distro is Debian/Ubuntu.
I can do whatever I want with my server, by the code, scripts and services have to compatible with the majority.

I cannot force the other people in the lab to adopt other schemes when they are happy with Debian/Ubuntu.

BTW I an using the Slackware way, but instead of having to write all the time the same command in bach I made a script. Like I said in the beginning service command is just to start stop a command from command line without change to /etc/rc.d/... and I am writing a insserv that will add a place the script in /etc/rc.d/ and start the script in rc.local and stop it in rc.local_shutdown.

It is still the Slackware way, but packed in two commands with the same name as present in Debian so the deployment is the same for every member of the lab.

Last edited by mlpa; 12-06-2012 at 03:34 AM.
 
Old 12-07-2012, 01:37 AM   #8
rouvas
Member
 
Registered: Aug 2006
Location: Greece
Distribution: Slackware.12.2
Posts: 104
Blog Entries: 3

Rep: Reputation: 21
Well, if it scratches your itch...

BTW, I don't think that the "Slackware way" its the absolutely best method that we should engrave in stone and never deviate, I would be happy with almost any method provided it is standardised.

Anyway, thanks for sharing. Never a bad thing.
 
Old 12-07-2012, 04:28 AM   #9
commandlinegamer
Member
 
Registered: Dec 2007
Posts: 163

Rep: Reputation: 51
Personally I like djb's way of doing things with daemontools, though that may be a bit tangential to the OP's requirements.
 
Old 12-07-2012, 10:41 AM   #10
mlpa
Member
 
Registered: May 2008
Location: Aveiro
Distribution: Slackware
Posts: 542

Original Poster
Rep: Reputation: 50
I created a git repository if anyone is interested, link.
I also created a insserv that adds a service to rc.local and rc.local_shutdown.

Like I said in the beginning this is not a fix for Slackware nor a solution for everyone but if someone like my is surrounded bey Debian people can be a way to normalize scripts.

I known that this can be a inglorious effort
 
Old 12-07-2012, 10:49 AM   #11
jpollard
Senior Member
 
Registered: Dec 2012
Location: Washington DC area
Distribution: Fedora, CentOS, Slackware
Posts: 4,912

Rep: Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513
"service" is just a shell script... You can easily copy it.
 
Old 12-07-2012, 12:00 PM   #12
mlpa
Member
 
Registered: May 2008
Location: Aveiro
Distribution: Slackware
Posts: 542

Original Poster
Rep: Reputation: 50
Quote:
Originally Posted by jpollard View Post
"service" is just a shell script... You can easily copy it.
I actually made one. In mine the script search for the normal service name (openfire) and with rc. prefix (rc.openfire).
But I could check the "service" script to compare and improve mine.

Thanks
 
Old 12-07-2012, 02:59 PM   #13
jpollard
Senior Member
 
Registered: Dec 2012
Location: Washington DC area
Distribution: Fedora, CentOS, Slackware
Posts: 4,912

Rep: Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513
The only reason the "service" script exists is to ensure the proper environment to run the startup script.

On Fedora it got to be a hassle as so much of the root user gets corrupted by gnome setups, that it needed something to clean out the cruft to get to the environment used during boot.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] I need to create a service on Red Hat similar to a Solaris. Please assist. xenner Linux - Newbie 1 02-21-2010 05:03 PM
a little bash help with the 'for' command (or similar) checkmate3001 Linux - General 5 02-18-2009 12:52 PM
Help with grep (or similar command) tejama Linux - Newbie 12 02-22-2008 06:32 AM
script/service/command executes during shutdown shipon_97 Linux - Newbie 1 08-30-2007 03:19 AM
Trying to work out how to run a script with a start command or something similar helptonewbie Programming 6 05-31-2007 04:27 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Slackware

All times are GMT -5. The time now is 11:10 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration