LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Fedora
User Name
Password
Fedora This forum is for the discussion of the Fedora Project.

Notices


Reply
  Search this Thread
Old 02-27-2016, 03:07 PM   #1
gctaylor1
Member
 
Registered: Dec 2006
Distribution: Red Hat
Posts: 45

Rep: Reputation: 0
systemctl start,enable service in one command.


I'm trying to find a way to start and enable a systemd service using one command line.
Something like

Code:
sudo systemctl {start,enable} nfs-secure-server   <----- doesn't work
I do have options. I use vi key bindings so doing one command and then using k to bring it back from history and replace one word is easy. I'm sure the default emacs bindings have a similar shortcut. Just looking for a succinct one liner.

Code:
sudo systemctl start nfs-secure-server
up arrow or using vi key bindings

Code:
sudo systemctl enable nfs-secure-server
or
Code:
^start^enable^
or
Code:
sudo systemctl enable nfs-secure-server && sudo systemctl start nfs-secure-server
Just wondering if someone knows of a better way?

Thanks,
Gary

Last edited by gctaylor1; 02-27-2016 at 08:59 PM.
 
Old 02-28-2016, 09:14 AM   #2
Bapun007
Member
 
Registered: Dec 2010
Location: /home
Distribution: Slackware stable
Posts: 79

Rep: Reputation: 40
Code:
sudo systemctl enable nfs-secure-server && sudo systemctl start nfs-secure-server
this works in normal command line, can you tell us what is your need to run both of those in a single line ?
Is it for some bash script ?

Code:
sudo bash -c "systemctl enable nfs-secure-server; systemctl start nfs-secure-server"
this can also work

Last edited by Bapun007; 02-28-2016 at 09:28 AM.
 
Old 02-29-2016, 02:58 PM   #3
gctaylor1
Member
 
Registered: Dec 2006
Distribution: Red Hat
Posts: 45

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by Bapun007 View Post
Can you tell us what is your need to run both of those in a single line ?
Thanks for looking at my question.
Strictly convenience. For example, I frequently use brace expansion for things like
Code:
# mkdir /{krbnfs,sambaspace}
and
Code:
cp -iv /etc/fstab{,.orig}
and thought it would be handy if I could do something similar systemctl.
 
Old 11-23-2018, 11:01 AM   #4
tld161
LQ Newbie
 
Registered: Nov 2018
Posts: 1

Rep: Reputation: Disabled
necroposting because this is the first result in the search engine I used:

from systemctl --help:

Code:
     --now            Start or stop unit in addition to enabling or disabling it
so you could use something like

Code:
sudo systemctl enable --now nfs-secure-server
 
1 members found this post helpful.
Old 11-23-2018, 12:58 PM   #5
scasey
LQ Veteran
 
Registered: Feb 2013
Location: Tucson, AZ, USA
Distribution: CentOS 7.9.2009
Posts: 5,726

Rep: Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211
Quote:
Originally Posted by tld161 View Post
necroposting because this is the first result in the search engine I used:

from systemctl --help:

Code:
     --now            Start or stop unit in addition to enabling or disabling it
so you could use something like

Code:
sudo systemctl enable --now nfs-secure-server
That's good information.
I feel compelled to point out that enabling only needs to be done once, so am wondering why the OPs question to begin with...although we'll probably never know considering the age of the OP.
 
Old 11-24-2018, 12:20 PM   #6
gctaylor1
Member
 
Registered: Dec 2006
Distribution: Red Hat
Posts: 45

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by scasey View Post
That's good information.
I feel compelled to point out that enabling only needs to be done once, so am wondering why the OPs question to begin with...although we'll probably never know considering the age of the OP.
Hi,

OP here. I was working on a project that had a lot of manual steps. VMs getting created, services added/removed enabled/started, repetition, etc. Was looking for any efficiencies I could find until it was automated.
 
  


Reply



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] What is the purpose of systemctl start named.service? Echopurrs Linux - Newbie 1 07-07-2014 12:43 AM
unable to START MySQL server at BOOT "systemctl enable mysqld.service" does not work cyberdome Linux - Newbie 2 03-11-2014 02:35 AM
[SOLVED] systemctl enable mysqld.service, command not working. cyberdome Fedora 5 03-10-2014 12:36 PM

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

All times are GMT -5. The time now is 08:01 PM.

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