[arch-general] manage starting and stopping processes with less typing
Guys, One thing I miss with Arch are init-script shortcuts for starting and stopping processes. rc-commands really help cut down on typing. For example, all suse did was to create links to the files in /etc/rc.d/... with a naming convention of rc<init script name>. So, for example, instead of having to type: /etc/rc.d/postfix the shortcut was simply rcpostfix I have normally seen the sym-link shortcuts placed in /usr/sbin, but /usr/local/sbin works fine as well. The convenience is addictive. If you manage your box from the command line or want to, then you can give this setup a testdrive. You can create the sym-links very easily with the following cut and pasted to the command line (as root - all on one line): for i in $(ls /etc/rc.d); do [[ -e /etc/rc.d/$i ]] && [[ ! -h /usr/local/sbin/$i ]] && ln -sv /etc/rc.d/$i /usr/local/sbin/rc${i}; done You need to make sure /usr/local/sbin is in root's path to use the rc-commands without having to type the full path each time (that would defeat any convenience). You can quickly check to see if /usr/local/sbin is in root's path by logging in, or su'ing, to the root account and pasting the next line into the command line: set | grep \/usr\/local\/sbin If you get an answer, your fine, if you get nothing, then, as root, add /usr/local/sbin to the path with: PATH=$PATH:/usr/local/sbin EXPORT PATH you can make the path permanent by adding to, or creating /root/.bashrc with the following: export PATH=$PATH:/usr/local/sbin I know most of you know all this, but this was written with additional detail to help those who may not make much use of the command line now, but may be interested in learning more about the control it offers. Remember, you can do some things some of the time from within various guis, but you can do ALL things ALL OF THE TIME, from the command line. -- David C. Rankin, J.D.,P.E. Rankin Law Firm, PLLC 510 Ochiltree Street Nacogdoches, Texas 75961 Telephone: (936) 715-9333 Facsimile: (936) 715-9339 www.rankinlawfirm.com
On Wednesday 14 Apr 2010 12:52:43 am David C. Rankin wrote:
Guys,
One thing I miss with Arch are init-script shortcuts for starting and stopping processes. rc-commands really help cut down on typing. For example, all suse did was to create links to the files in /etc/rc.d/... with a naming convention of rc<init script name>. So, for example, instead of having to type:
I wrote a similar bash function, which I placed my ~/.bashrc. Sharing it here: start() { for arg in $*; do sudo /etc/rc.d/$arg start done } restart() { for arg in $*; do sudo /etc/rc.d/$arg restart done } stop() { for arg in $*; do sudo /etc/rc.d/$arg stop done } status() { for arg in $*; do sudo /etc/rc.d/$arg status done } log() { for arg in $*; do sudo less /var/log/$arg done } It works as $ start <insert service name> $ restart <insert service name> $ status <insert service name> Hope it helps -- Regards, Gaurish Sharma www.gaurishsharma.com
On 04/13/2010 02:34 PM, Gaurish Sharma wrote:
On Wednesday 14 Apr 2010 12:52:43 am David C. Rankin wrote:
<snip>
I wrote a similar bash function, which I placed my ~/.bashrc. Sharing it here:
start() { for arg in $*; do sudo /etc/rc.d/$arg start done } <snip> It works as $ start <insert service name> $ restart <insert service name> $ status <insert service name>
Hope it helps
Gaurish, Thanks. That's cool and has given me a couple of more ideas. Here a couple more of my favorites for .bashrc. I don't know what everyone else does for pacman aliases, but I just use the pm<stuff> shown below: ## functions wgnc() { if [[ -z $1 ]]; then echo -e "\n Usage: wg <filename>\t\t(runs wget --no-check-certificate --progress=bar)\n" else wget --no-check-certificate --progress=bar $1 fi } showhist() { [[ -z $1 ]] && { echo -e "\nUsage: hist <search term>\n"; return 1; } history | grep $1 return 0 } mkdircd() { [[ -z $1 ]] && { echo -e "\nUsage: mdcd <newdir>\n"; return 1; } mkdir -p $1 && cd $1 || { echo -e "\n Failed to make or change to directory: $1\n"; return 1; } return 0 } perledinln() { if [[ ! -f $2 ]]; then echo -e "\n Usage ${0##*/} REGEX filename\n\n Will edit the file in-place based on REGEX using perl\n" else REGEX=$1 INFILE=$2 perl -p -i -e $REGEX $INFILE fi } fnkwrite() { [[ -f $1 ]] && ( /opt/kde/bin/kwrite $1 & ) || ( /opt/kde/bin/kwrite & ); } fnkate() { [[ -f $1 ]] && ( /opt/kde/bin/kate $1 & ) || ( /opt/kde/bin/kate & ); } ## aliases alias hist='showhist' alias mdcd='mkdircd' alias ppie='perledinln' alias wg='wgnc' alias kw='fnkwrite' alias ka='fnkate' # ## pacman aliases (of course just remove sudo for root .bashrc) # alias pm='sudo pacman' alias pmq='sudo pacman -Q' alias pmql='sudo pacman -Ql' alias pmqi='sudo pacman -Qi' alias pmr='sudo pacman -R' alias pms='sudo pacman -Sy --needed' alias pmss='sudo pacman -Ss' alias pmu='sudo pacman -U' alias pmsu='sudo pacman --sync --refresh --sysupgrade' -- David C. Rankin, J.D.,P.E. Rankin Law Firm, PLLC 510 Ochiltree Street Nacogdoches, Texas 75961 Telephone: (936) 715-9333 Facsimile: (936) 715-9339 www.rankinlawfirm.com
On Tue, Apr 13, 2010 at 21:22, David C. Rankin <drankinatty@suddenlinkmail.com> wrote:
One thing I miss with Arch are init-script shortcuts for starting and stopping processes. rc-commands really help cut down on typing. For example, all suse did was to create links to the files in /etc/rc.d/... with a naming convention of rc<init script name>. So, for example, instead of having to type:
IMHO you just have to use tab completion and you will not type much more. I don't like the symlink approach of suse... Bye...Frank
On 04/13/2010 02:36 PM, Frank Thieme wrote:
On Tue, Apr 13, 2010 at 21:22, David C. Rankin <drankinatty@suddenlinkmail.com> wrote:
One thing I miss with Arch are init-script shortcuts for starting and stopping processes. rc-commands really help cut down on typing. For example, all suse did was to create links to the files in /etc/rc.d/... with a naming convention of rc<init script name>. So, for example, instead of having to type:
IMHO you just have to use tab completion and you will not type much more. I don't like the symlink approach of suse...
Bye...Frank
point taken, but you still have to get past /etc/rc.d/.. before you get the benefit. Not being a great typist, l seek to eliminate any typing I can. It's taking efficiency (synonymous with laziness in some cases) to the next level :p -- David C. Rankin, J.D.,P.E. Rankin Law Firm, PLLC 510 Ochiltree Street Nacogdoches, Texas 75961 Telephone: (936) 715-9333 Facsimile: (936) 715-9339 www.rankinlawfirm.com
On Tue, Apr 13, 2010 at 1:36 PM, Frank Thieme <frank@fthieme.net> wrote:
On Tue, Apr 13, 2010 at 21:22, David C. Rankin <drankinatty@suddenlinkmail.com> wrote:
One thing I miss with Arch are init-script shortcuts for starting
and stopping
processes. rc-commands really help cut down on typing. For example, all suse did was to create links to the files in /etc/rc.d/... with a naming convention of rc<init script name>. So, for example, instead of having to type:
IMHO you just have to use tab completion and you will not type much more. I don't like the symlink approach of suse...
Bye...Frank
I promote the use of tab completion as it helps with reinforcing the directory structure in my head. In addition too many soft links makes me feel as though I am chasing ghosts around my computer. Tab completion and good old fashion elbow grease is a sure and concise way of making it around the directory structure. Benji
On 14 April 2010 21:29, Benjamin Campbell <benji.campbell@gmail.com> wrote:
I promote the use of tab completion as it helps with reinforcing the directory structure in my head. In addition too many soft links makes me feel as though I am chasing ghosts around my computer. Tab completion and good old fashion elbow grease is a sure and concise way of making it around the directory structure.
Well, the thing is, nobody stops you from making your own life a lot easier if symlinks are going to do it. I have a ton of custom scripts and functions, for even the simplest of things. But to me it makes my computing life easier. -- GPG/PGP ID: B42DDCAD
On Wed, 2010-04-14 at 07:29 -0600, Benjamin Campbell wrote:
On Tue, Apr 13, 2010 at 1:36 PM, Frank Thieme <frank@fthieme.net> wrote:
On Tue, Apr 13, 2010 at 21:22, David C. Rankin <drankinatty@suddenlinkmail.com> wrote:
One thing I miss with Arch are init-script shortcuts for starting
and stopping
processes. rc-commands really help cut down on typing. For example, all suse did was to create links to the files in /etc/rc.d/... with a naming convention of rc<init script name>. So, for example, instead of having to type:
IMHO you just have to use tab completion and you will not type much more. I don't like the symlink approach of suse...
Bye...Frank
I promote the use of tab completion as it helps with reinforcing the directory structure in my head. In addition too many soft links makes me feel as though I am chasing ghosts around my computer. Tab completion and good old fashion elbow grease is a sure and concise way of making it around the directory structure.
Benji
I'm not sure what shell everyone is using, but the tab completion in extra/zsh + extra/grml-zsh-config makes it easy as: sudo /e/r/sam <tab> start which completes on my system to sudo /etc/rc.d/samba start
On Tue, Apr 13, 2010 at 4:22 PM, David C. Rankin <drankinatty@suddenlinkmail.com> wrote:
Guys,
One thing I miss with Arch are init-script shortcuts for starting and stopping processes. rc-commands really help cut down on typing. For example, all suse did was to create links to the files in /etc/rc.d/... with a naming convention of rc<init script name>. So, for example, instead of having to type:
/etc/rc.d/postfix
the shortcut was simply
rcpostfix
Uhh, I dont use rc.d too much to this be usefull to me but... I'm thinking about it, creating sym links looks *ugly* to me, because you need to updated it after you remove or add new rc.d. I think that a much cleaner solution is to create a rename filesystem using FUSE to rename files from /etc/rc.d on the fly. (FUSE is so cool ^_^) Bye, Kazuo -- «Dans la vie, rien n'est à craindre, tout est à comprendre» Marie Sklodowska Curie.
What about that: for i in $(ls -1 /etc/rc.d); do alias rc-$i="/etc/rc,d/$i"; done That's simple and dynamic, just insert it on your .bashrc ou /etc/bash.bashrc (global) On Tue, Apr 13, 2010 at 4:41 PM, Kazuo Teramoto <kaz.rag@gmail.com> wrote:
On Tue, Apr 13, 2010 at 4:22 PM, David C. Rankin <drankinatty@suddenlinkmail.com> wrote:
Guys,
One thing I miss with Arch are init-script shortcuts for starting and stopping processes. rc-commands really help cut down on typing. For example, all suse did was to create links to the files in /etc/rc.d/... with a naming convention of rc<init script name>. So, for example, instead of having to type:
/etc/rc.d/postfix
the shortcut was simply
rcpostfix
Uhh, I dont use rc.d too much to this be usefull to me but...
I'm thinking about it, creating sym links looks *ugly* to me, because you need to updated it after you remove or add new rc.d.
I think that a much cleaner solution is to create a rename filesystem using FUSE to rename files from /etc/rc.d on the fly. (FUSE is so cool ^_^)
Bye, Kazuo
-- «Dans la vie, rien n'est à craindre, tout est à comprendre» Marie Sklodowska Curie.
-- Flávio Coutinho da Costa
On Tue, Apr 13, 2010 at 4:58 PM, Flavio Costa <flavio.cdc@gmail.com> wrote:
What about that: for i in $(ls -1 /etc/rc.d); do alias rc-$i="/etc/rc,d/$i"; done That's simple and dynamic, just insert it on your .bashrc ou /etc/bash.bashrc (global)
That has a problem. It is evaluated when you log in (or when you source .bashrc explicitly). But if you keep a session long enough and install a package with a file in /etc/rc.d, you will not have a corresponding alias rc-<new service>. So you have to log out and in again to get it. I think that the best approach was from Gaurish Sharma. The funcions are really dynamic and work pretty well (I thought of contributing something similar, but he did it first. My compliments for Gaurish, by the way). -- A: Because it obfuscates the reading. Q: Why is top posting so bad? ------------------------------------------- Denis A. Altoe Falqueto -------------------------------------------
On 04/13/2010 02:58 PM, Flavio Costa wrote:
What about that: for i in $(ls -1 /etc/rc.d); do alias rc-$i="/etc/rc,d/$i"; done That's simple and dynamic, just insert it on your .bashrc ou /etc/bash.bashrc (global)
Yes, But that leaves me updating multiple .bashrc files (root, david, testacct1, etc..) on each box. If you just symlink them, they are there for all -- no editing involved. However, that does touch on a good point. Currently, I'm working on a modular .bashrc setup that does something like this in .bashrc: # . ~/scr/bash/brc-Arch.sh # . ~/scr/bash/brc-suse.sh # . ~/scr/bash/brc-ssh.sh where, for example, brc-Arch.sh would hold Arch specific functions and aliases. It's just a matter of free time needed to collect all the various .bashrc files I have from all the boxes and do it.... -- David C. Rankin, J.D.,P.E. Rankin Law Firm, PLLC 510 Ochiltree Street Nacogdoches, Texas 75961 Telephone: (936) 715-9333 Facsimile: (936) 715-9339 www.rankinlawfirm.com
On Tue, 13 Apr 2010 21:03:50 -0500 "David C. Rankin" <drankinatty@suddenlinkmail.com> wrote:
On 04/13/2010 02:58 PM, Flavio Costa wrote:
What about that: for i in $(ls -1 /etc/rc.d); do alias rc-$i="/etc/rc,d/$i"; done That's simple and dynamic, just insert it on your .bashrc ou /etc/bash.bashrc (global)
Yes,
But that leaves me updating multiple .bashrc files (root, david, testacct1, etc..) on each box. If you just symlink them, they are there for all -- no editing involved.
You could put it in /etc/bash.bashrc On Tue, 13 Apr 2010 17:11:17 -0300 Denis A. Altoé Falqueto <denisfalqueto@gmail.com> wrote:
On Tue, Apr 13, 2010 at 4:58 PM, Flavio Costa <flavio.cdc@gmail.com> wrote:
What about that: for i in $(ls -1 /etc/rc.d); do alias rc-$i="/etc/rc,d/$i"; done That's simple and dynamic, just insert it on your .bashrc ou /etc/bash.bashrc (global)
That has a problem. It is evaluated when you log in (or when you source .bashrc explicitly). But if you keep a session long enough and install a package with a file in /etc/rc.d, you will not have a corresponding alias rc-<new service>.
you could easily reinvoke the script manually, or with a wrapper function around pacman. On Wed, 14 Apr 2010 07:52:44 +0200 Linas <linas_fi@ymail.com> wrote:
Seems my message didn't get through.
It was just doing rc() { /etc/rc.d/$*; }
And to get completion, complete -o filenames -W "$(cd /etc/rc.d/ && echo *)" rc
That requires a relogin / sourcing the profile again to update the completion (could be avoided with another function) but it's neat and simple.
very nice. can you make the completion dynamic? that would make it awesome. Dieter
David C. Rankin wrote:
Guys,
One thing I miss with Arch are init-script shortcuts for starting and stopping processes. rc-commands really help cut down on typing. For example, all suse did was to create links to the files in /etc/rc.d/... with a naming convention of rc<init script name>. So, for example, instead of having to type:
/etc/rc.d/postfix
the shortcut was simply
rcpostfix
I have normally seen the sym-link shortcuts placed in /usr/sbin, but /usr/local/sbin works fine as well. The convenience is addictive. If you manage your box from the command line or want to, then you can give this setup a testdrive. You can create the sym-links very easily with the following cut and pasted to the command line (as root - all on one line):
for i in $(ls /etc/rc.d); do [[ -e /etc/rc.d/$i ]] && [[ ! -h /usr/local/sbin/$i ]] && ln -sv /etc/rc.d/$i /usr/local/sbin/rc${i}; done
No need to create one symlink per file. You can just add rc() { /etc/rc.d/$*; } to the user profile to automatically be able to do: rc postfix start for any script you have or ever add. To have autocompletion with your new command, also add: complete -o filenames -W "$(cd /etc/rc.d/ && echo *)" rc __________________________________________________ Do You Yahoo!? Tired of spam? Yahoo! Mail has the best spam protection around http://mail.yahoo.com
On 13/04/10 20:50, Linas wrote:
David C. Rankin wrote:
Guys,
One thing I miss with Arch are init-script shortcuts for starting and stopping processes. rc-commands really help cut down on typing. For example, all suse did was to create links to the files in /etc/rc.d/... with a naming convention of rc<init script name>. So, for example, instead of having to type:
/etc/rc.d/postfix
the shortcut was simply
rcpostfix
I have normally seen the sym-link shortcuts placed in /usr/sbin, but /usr/local/sbin works fine as well. The convenience is addictive. If you manage your box from the command line or want to, then you can give this setup a testdrive. You can create the sym-links very easily with the following cut and pasted to the command line (as root - all on one line):
for i in $(ls /etc/rc.d); do [[ -e /etc/rc.d/$i ]]&& [[ ! -h /usr/local/sbin/$i ]]&& ln -sv /etc/rc.d/$i /usr/local/sbin/rc${i}; done
No need to create one symlink per file. You can just add rc() { /etc/rc.d/$*; } to the user profile to automatically be able to do:
rc postfix start for any script you have or ever add.
To have autocompletion with your new command, also add: complete -o filenames -W "$(cd /etc/rc.d/&& echo *)" rc
here's my rc script, no need for completion IMO when you can just type: `rc r l~pd` to restart lighttpd #!/bin/sh WC='~' if [ $# -ne 2 ]; then echo "usage: <OPERATION> <PATTERN>" echo " OPERATION can also be one of: k(stop), r(restart), s(start)" echo " PATTERN(grep -E ^PATTERN$) where $WC is replaced with .*" exit 1 fi case $1 in k) opr="stop" ;; r) opr="restart" ;; s) opr="start" ;; *) opr=$1 esac if [ "$opr" = "" ]; then echo "error: no operation specified." exit 1 fi pat=$(echo $2 | sed "s/$WC/.*/g") rc=$(ls /etc/rc.d/ | grep -E "^$pat$") mat=$(echo $rc | wc -w) if [ "$mat" = "1" ]; then sudo /etc/rc.d/$rc $opr elif [ "$mat" = "0" ]; then echo "error: no targets found." else echo "error: multiple targets found:" for t in $(echo $rc); do echo " $t" done fi
On 04/13/2010 03:22 PM, David C. Rankin wrote:
Guys,
One thing I miss with Arch are init-script shortcuts for starting and stopping processes. rc-commands really help cut down on typing. For example, all suse did was to create links to the files in /etc/rc.d/... with a naming convention of rc<init script name>. So, for example, instead of having to type:
/etc/rc.d/postfix
the shortcut was simply
rcpostfix
The way I usually handle this is to create an executable shell script in my ~/bin directory (which is on my path) and in /root/bin called "service". It looks like so: #!/bin/bash /etc/rc.d/$* Then I can use RedHat-like syntax to start and stop services: $ sudo service httpd restart HTH, DR
Seems my message didn't get through. It was just doing rc() { /etc/rc.d/$*; } And to get completion, complete -o filenames -W "$(cd /etc/rc.d/ && echo *)" rc That requires a relogin / sourcing the profile again to update the completion (could be avoided with another function) but it's neat and simple.
But that leaves me updating multiple .bashrc files (root, david, testacct1, etc..) on each box. If you just symlink them, they are there for all -- no editing involved.
You still have to add the symlinks on each box (and you will forget to add some symlink on one computer after an install). For the multiple accounts, you can add the scripts to /etc/bash.bashrc.local __________________________________________________ Do You Yahoo!? Tired of spam? Yahoo! Mail has the best spam protection around http://mail.yahoo.com
On 04/13/2010 01:22 PM, David C. Rankin wrote:
Guys,
One thing I miss with Arch are init-script shortcuts for starting and stopping processes. rc-commands really help cut down on typing. For example, all suse did was to create links to the files in /etc/rc.d/... with a naming convention of rc<init script name>. {snip}
If you're doing this, why not just add /etc/rc.d to your path? -Brendan
On Wed, Apr 14, 2010 at 11:55 PM, Brendan Long <korin43@gmail.com> wrote:
On 04/13/2010 01:22 PM, David C. Rankin wrote:
Guys,
One thing I miss with Arch are init-script shortcuts for starting and stopping processes. rc-commands really help cut down on typing. For example, all suse did was to create links to the files in /etc/rc.d/... with a naming convention of rc<init script name>. {snip}
If you're doing this, why not just add /etc/rc.d to your path?
-Brendan
Then the rc scripts would conflict with the programs they call.
participants (15)
-
Benjamin Campbell
-
Brendan Long
-
David C. Rankin
-
David Rosenstrauch
-
Denis A. Altoé Falqueto
-
Dieter Plaetinck
-
Flavio Costa
-
Frank Thieme
-
Gary Wright
-
Gaurish Sharma
-
Kazuo Teramoto
-
Linas
-
Nathan Wayde
-
Ray Rashif
-
Shacristo