LinuxQuestions.org
Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training Bundle
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 11-23-2016, 03:02 PM   #1
cbtshare
Member
 
Registered: Jul 2009
Posts: 610

Rep: Reputation: 42
init script convertion


I have a script that runs on centos 6 and want to try out centos 7 I am trying to convert the script to work with systemd

original script
Code:
start on runlevel [2345]
stop on runlevel [!2345]
 
env NUM_WORKERS=20
 
pre-start script
  for i in `seq 1 $NUM_WORKERS`
  do
    start consumer-localhost N=$i
  done
end script
so far I have

Code:
### BEGIN INIT INFO
 Provides: localqueue
 Default-Start:  2 3 4 5
 Default-Stop: 0 1 6
 Short-Description: start and stop service rabbitmq servers
 Description: worker process to start multiple consumers - q9 mt03 local queue

Environment NUM_WORKERS=20
ExecStartPre
	for i in `seq 1 $NUM_WORKERS`
  		do
    	start consumer-localhost N=$i
  	done
ExecStopPost
### END INIT INFO

### END INIT INFO

Last edited by cbtshare; 11-23-2016 at 03:29 PM.
 
Old 11-23-2016, 03:50 PM   #2
Ratamahatta
Member
 
Registered: Feb 2012
Location: Koblenz, Germany
Distribution: siduction
Posts: 61

Rep: Reputation: 5
Init scripts are about the only things almost every distribution does differently.

I've written init scripts on SuSE/openSUSE and Debian based systems. There were different steps to take and different options to set to create an init script on those unrelated systems. CentOS appears even more different, so I really can't do much more than post this link which I think is quite good:
https://techarena51.com/index.php/ho...t-on-centos-6/
This is for CentOS 6 though, not 7. I have no idea what might have changed.
Good luck and happy hacking!
 
Old 11-23-2016, 10:27 PM   #3
AwesomeMachine
Senior Member
 
Registered: Jan 2005
Location: USA and Italy
Distribution: Debian testing/sid; OpenSuSE; Fedora
Posts: 1,835

Rep: Reputation: 260Reputation: 260Reputation: 260
I usually just look at one of the other scripts and copy it, making the necessary changes. Most distros have a program to convert sysvinit scripts to systemd.
 
Old 11-24-2016, 10:25 AM   #4
cbtshare
Member
 
Registered: Jul 2009
Posts: 610

Original Poster
Rep: Reputation: 42
Quote:
Originally Posted by AwesomeMachine View Post
I usually just look at one of the other scripts and copy it, making the necessary changes. Most distros have a program to convert sysvinit scripts to systemd.
Thank you, but I been trying to find a similar example to the init.d script but cant find any, with the pre script, post script env variable and for loop.
 
Old 11-24-2016, 12:30 PM   #5
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 17,944

Rep: Reputation: 3693Reputation: 3693Reputation: 3693Reputation: 3693Reputation: 3693Reputation: 3693Reputation: 3693Reputation: 3693Reputation: 3693Reputation: 3693Reputation: 3693
Quote:
Originally Posted by cbtshare View Post
Thank you, but I been trying to find a similar example to the init.d script but cant find any, with the pre script, post script env variable and for loop.
Really? Because the documentation is extensive, and examples are plentiful. Putting "systemd init script" into Google pulls up:
https://access.redhat.com/documentat...nit_Files.html

...a fairly comprehensive guide. Pay particular attention to the "ExecStartPre" and "ExecStartPost" directives.
 
  


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] can i write a shell script in /etc/init.d that will run a python script? lapishater276 Debian 1 06-27-2014 04:23 PM
[SOLVED] why init script cannot source init tools unless session root linuxecho Linux - Newbie 8 02-17-2014 06:17 PM
convertion of seconds to date and time in linux shell script naveenese Linux - Newbie 13 08-17-2010 08:14 AM
Init script in /etc/init.d does not start at boot tdnnash25 Linux - Server 4 12-18-2009 05:40 PM
any script for unix2dos convertion? setlec_seta Linux - General 3 10-09-2009 06:42 AM


All times are GMT -5. The time now is 11:05 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration