You are not logged in.

#1 2012-10-22 07:51:38

yaffare
Member
Registered: 2011-12-29
Posts: 71

systemd shell wrapper script - cloning rc.d output

Update: 2012-10-22 19:25:52
- code cleaning
- minor changes

Update: 2012-10-23 13:26:38
- mini bugfix, thx @theDOC
- separate script and configuration
- added AUR-Package

Update: 2012-10-24 22:30:14
- moved source to github

Update: 2012-10-31 20:30:54
- bugfix: improvements for non root-usage

Update: 2012-11-11 17:31:14
- make the scripts independent of unit type, thx @denisfalqueto
- added function logtruncate()

Update: 2013-01-09 11:22:13
- minor bugfix

Description
Simple shell wrapper script around the systemd ctls

Supported Shells
- bash

Installation
- Install systemd-shell-wrapper from the AUR
- add "source /etc/profile" to your ~/.bashrc

Configuration
Configuration is stored in /etc/systemd/shell-wrapper.conf, though there is only one option called HIDEDAEMONS

Features
- cloning rc.d output
- tab-completion

Usage Examples

[root@mypc ~]# s.TAB
s.analyze     s.disable     s.enable      s.list        s.listfailed  s.log         s.logsize     s.reload      s.restart     s.start       s.status      s.stop        s.tree        s.wants
[root@mypc ~]# s.list
[STARTED][AUTO] cronie
[STARTED][AUTO] dhcpcd@eth0
[STARTED][AUTO] getty@tty1
[STOPPED][    ] krb5-kadmind
[STOPPED][    ] krb5-kdc
[STOPPED][    ] krb5-kpropd
[STOPPED][    ] nginx
[STARTED][AUTO] ntpd
[STOPPED][    ] rsyncd
[STARTED][AUTO] sshd
[STOPPED][    ] vboxservice
[root@mypc ~]#
[root@mypc ~]# s.start TAB
krb5-kadmind  krb5-kdc      krb5-kpropd   nginx         rsyncd        vboxservice   
[root@mypc ~]# s.start nginx
::  Starting nginx daemon                    [DONE]
[root@mypc ~]# 
[root@mypc ~]# s.start nginx
::  nginx daemon is already running
[root@mypc ~]# 
[root@mypc ~]# s.start nginx
::  Starting nginx daemon                    [FAIL]
nginx.service - A high performance web server and a reverse proxy server
	  Loaded: loaded (/usr/lib/systemd/system/nginx.service; disabled)
	  Active: failed (Result: exit-code) since Mon, 22 Oct 2012 09:41:48 +0200; 35ms ago
	 Process: 14212 ExecStartPre=/usr/sbin/nginx -t -q -g pid /run/nginx.pid; daemon on; master_process on; (code=exited, status=1/FAILURE)
	Main PID: 10386 (code=exited, status=0/SUCCESS)
	  CGroup: name=systemd:/system/nginx.service

Oct 22 09:41:48 mypc nginx[14212]: nginx: [emerg] unknown directive "a" in /etc/nginx/nginx.conf:12
Oct 22 09:41:48 mypc nginx[14212]: nginx: configuration file /etc/nginx/nginx.conf test failed
Oct 22 09:41:48 mypc systemd[1]: Failed to start A high performance web server and a reverse proxy server.
[root@mypc ~]#
[root@mypc ~]# s.log -p 6 nginx
adding match PRIORITY=0
adding match PRIORITY=1
adding match PRIORITY=2
adding match PRIORITY=3
adding match PRIORITY=4
adding match PRIORITY=5
adding match PRIORITY=6
Logs begin at Sun, 21 Oct 2012 01:07:17 +0200, end at Sun, 21 Oct 2012 02:06:57 +0200.
Oct 22 08:28:26 mypc nginx[10348]: nginx: [emerg] unknown directive "a" in /etc/nginx/nginx.conf:12
Oct 22 08:28:26 mypc nginx[10348]: nginx: configuration file /etc/nginx/nginx.conf test failed
Oct 22 09:21:35 mypc nginx[13708]: nginx: [emerg] unknown directive "a" in /etc/nginx/nginx.conf:12
Oct 22 09:21:35 mypc nginx[13708]: nginx: configuration file /etc/nginx/nginx.conf test failed
Oct 22 09:41:48 mypc nginx[14212]: nginx: [emerg] unknown directive "a" in /etc/nginx/nginx.conf:12
Oct 22 09:41:48 mypc nginx[14212]: nginx: configuration file /etc/nginx/nginx.conf test failed
[root@mypc ~]# 
[root@mypc ~]# s.logsize
Journals take up 53.9M on disk.
[root@mypc ~]# s.status cronie
cronie.service - Periodic Command Scheduler
      Loaded: loaded (/usr/lib/systemd/system/cronie.service; enabled)
      Active: active (running) since Tue, 23 Oct 2012 15:26:17 +0200; 16min ago
    Main PID: 160 (crond)
      CGroup: name=systemd:/system/cronie.service
          └ 160 /usr/sbin/crond -n

Oct 23 15:26:17 mypc /usr/sbin/crond[160]: (CRON) INFO (running with inotify support)

Last edited by yaffare (2013-01-09 14:41:36)


systemd is like pacman. enjoys eating up stuff.

Offline

#2 2012-10-22 11:00:08

Unia
Member
From: Stockholm, Sweden
Registered: 2010-03-30
Posts: 2,486
Website

Re: systemd shell wrapper script - cloning rc.d output

Nice! I think many users are going to like this!


If you can't sit by a cozy fire with your code in hand enjoying its simplicity and clarity, it needs more work. --Carlos Torres

Offline

#3 2012-10-23 02:24:30

denisfalqueto
Member
From: ES, Brazil
Registered: 2006-03-24
Posts: 197

Re: systemd shell wrapper script - cloning rc.d output

This is very slick!! you should consider contributing it upstream.


Satisfied users don't rant, so you'll never know how many of us there are.

Offline

#4 2012-10-23 03:18:10

ngoonee
Forum Fellow
From: Between Thailand and Singapore
Registered: 2009-03-17
Posts: 7,354

Re: systemd shell wrapper script - cloning rc.d output

denisfalqueto wrote:

This is very slick!! you should consider contributing it upstream.

This. Do you plan to do so?

Though after a bit of though, this is more of a translation/shortening of systemctl. Perhaps it should be provided locally by Arch itself. I'd advise a feature request on this (perhaps provide an AUR package for automatic install first, as a proof of concept. For one, should be moved out of .systemd, seems that part will be easy though).

Last edited by ngoonee (2012-10-23 03:19:27)


Allan-Volunteer on the (topic being discussed) mailn lists. You never get the people who matters attention on the forums.
jasonwryan-Installing Arch is a measure of your literacy. Maintaining Arch is a measure of your diligence. Contributing to Arch is a measure of your competence.
Griemak-Bleeding edge, not bleeding flat. Edge denotes falls will occur from time to time. Bring your own parachute.

Offline

#5 2012-10-23 08:35:56

theDOC
Member
From: Aachen, Germany
Registered: 2009-06-18
Posts: 50

Re: systemd shell wrapper script - cloning rc.d output

very nice script, love it!

one small bugfix. I had to move the minus sign in the regexp of s_list_services

grep -o "${daemon}[A-Za-z0-9_-/=:]*"

to the end of the expression:

grep -o "${daemon}[A-Za-z0-9_/=:-]*"

because grep was giving me "grep: Invalid range end" errors on tab completion

Offline

#6 2012-10-23 14:54:36

yaffare
Member
Registered: 2011-12-29
Posts: 71

Re: systemd shell wrapper script - cloning rc.d output

ngoonee wrote:
denisfalqueto wrote:

This is very slick!! you should consider contributing it upstream.

This. Do you plan to do so?

Nice idea, but maybe some feature requests to the systemd folks could do the job:
- add a third column to systemctl list-unit-files which shows if a service is actually running
- add a switch to choose what to show enabled,disabled,static
- add a switch to hide the .service extension when I type -t service
- add option Hide=always/success to .service files
  to hide services completely from the list or only if they have not failed

ngoonee wrote:

Perhaps it should be provided locally by Arch itself.

We can put a link to the AUR-package in the wiki. And as any other AUR-package, if enough people interested we may move it to community.

Last edited by yaffare (2012-10-23 15:25:46)


systemd is like pacman. enjoys eating up stuff.

Offline

#7 2012-10-23 16:10:54

Hspasta
Member
Registered: 2011-12-24
Posts: 189
Website

Re: systemd shell wrapper script - cloning rc.d output

Other shell support (zsh) planned?

Offline

#8 2012-10-23 16:26:06

yaffare
Member
Registered: 2011-12-29
Posts: 71

Re: systemd shell wrapper script - cloning rc.d output

Hspasta wrote:

Other shell support (zsh) planned?

I may do this at some point in the future, but not now, as I do not use or know anything about zsh.
If someone else would convert the script one time to zsh, I would integrate and maintain it.


systemd is like pacman. enjoys eating up stuff.

Offline

#9 2012-10-23 18:46:52

denisfalqueto
Member
From: ES, Brazil
Registered: 2006-03-24
Posts: 197

Re: systemd shell wrapper script - cloning rc.d output

Would you mind putting it on github or some equivalent? I needed a 'isolate' command and had to fall back to systemctl smile It would be cool to send you patches (I don't have any right now).


Satisfied users don't rant, so you'll never know how many of us there are.

Offline

#10 2012-10-23 19:10:06

graysky
Wiki Maintainer
From: :wq
Registered: 2008-12-01
Posts: 10,592
Website

Re: systemd shell wrapper script - cloning rc.d output

denisfalqueto wrote:

Would you mind putting it on girhub.

+1


CPU-optimized Linux-ck packages @ Repo-ck  • AUR packagesZsh and other configs

Offline

#11 2012-10-23 22:34:20

yaffare
Member
Registered: 2011-12-29
Posts: 71

Re: systemd shell wrapper script - cloning rc.d output


systemd is like pacman. enjoys eating up stuff.

Offline

#12 2012-10-30 23:18:56

American_Jesus
Member
From: Lisbon/Portugal
Registered: 2011-07-20
Posts: 37

Re: systemd shell wrapper script - cloning rc.d output

I'm not a great developer or bash/script expert, but here's a workaround for zsh

if [ "$SHELL" == "/bin/zsh" ]; then
     compdef s_bashcompletion_start s.start
     compdef s_bashcompletion_stop s.stop
     compdef s_bashcompletion_restart s.restart
     compdef s_bashcompletion_reload s.reload
     compdef s_bashcompletion_enable s.enable
     compdef s_bashcompletion_disable s.disable
     compdef s_bashcompletion_status s.status
     compdef s_bashcompletion_wants s.wants
     compdef s_bashcompletion_log s.log
   else
     complete -F s_bashcompletion_start s.start
     complete -F s_bashcompletion_stop s.stop
     complete -F s_bashcompletion_restart s.restart
     complete -F s_bashcompletion_reload s.reload
     complete -F s_bashcompletion_enable s.enable
     complete -F s_bashcompletion_disable s.disable
     complete -F s_bashcompletion_status s.status
     complete -F s_bashcompletion_wants s.wants
     complete -F s_bashcompletion_log s.log
fi

Works only with s.TAB

Last edited by American_Jesus (2012-10-30 23:21:04)


Archlinux X86_64

Offline

#13 2012-10-31 00:48:23

graysky
Wiki Maintainer
From: :wq
Registered: 2008-12-01
Posts: 10,592
Website

Re: systemd shell wrapper script - cloning rc.d output

Send him a pull request, AJ.


CPU-optimized Linux-ck packages @ Repo-ck  • AUR packagesZsh and other configs

Offline

#14 2012-10-31 01:48:39

American_Jesus
Member
From: Lisbon/Portugal
Registered: 2011-07-20
Posts: 37

Re: systemd shell wrapper script - cloning rc.d output

some stuff are not working with that workaround like s.{start,stop,enable,...} daemon.service, i'll try something else
when i got it working properly i make a fork of the repo and send some patches


Archlinux X86_64

Offline

#15 2012-10-31 10:19:56

graysky
Wiki Maintainer
From: :wq
Registered: 2008-12-01
Posts: 10,592
Website

Re: systemd shell wrapper script - cloning rc.d output

American_Jesus wrote:

some stuff are not working with that workaround like s.{start,stop,enable,...} daemon.service, i'll try something else
when i got it working properly i make a fork of the repo and send some patches

Delete your fork -- Yaffare hasn't been keeping his github in sync with his releases per his changelog in his original post.

Last edited by graysky (2012-10-31 10:38:20)


CPU-optimized Linux-ck packages @ Repo-ck  • AUR packagesZsh and other configs

Offline

#16 2012-10-31 10:39:59

graysky
Wiki Maintainer
From: :wq
Registered: 2008-12-01
Posts: 10,592
Website

Re: systemd shell wrapper script - cloning rc.d output

yaffare wrote:

Update: 2012-10-22 19:25:52
- code cleaning
- minor changes

Update: 2012-10-23 13:26:38
- mini bugfix, thx @theDOC
- separate script and configuration
- added AUR-Package

Update: 2012-10-24 22:30:14
- moved source to github

@Yaffare - Since your AUR package pulls from your github, people are not benefiting from the changes you outlined above because the code in your github repo is 8 days old.  You gotta push ever change you make.  Here is a helpful alias you can add to your shell rc (~/.bashrc I'm guessing) that does this for you.  Just be sure you're in the /path/to/local/repo when you call it:

alias gitc="git commit -av ; git push -u origin master"

Last edited by graysky (2012-10-31 10:40:29)


CPU-optimized Linux-ck packages @ Repo-ck  • AUR packagesZsh and other configs

Offline

#17 2012-10-31 11:09:24

yaffare
Member
Registered: 2011-12-29
Posts: 71

Re: systemd shell wrapper script - cloning rc.d output

American_Jesus wrote:

some stuff are not working with that workaround like s.{start,stop,enable,...} daemon.service, i'll try something else
when i got it working properly i make a fork of the repo and send some patches

Could you be a little more specific? What exactly is not working, what error-messages do you get?


systemd is like pacman. enjoys eating up stuff.

Offline

#18 2012-10-31 11:15:48

yaffare
Member
Registered: 2011-12-29
Posts: 71

Re: systemd shell wrapper script - cloning rc.d output

graysky wrote:
yaffare wrote:

Update: 2012-10-22 19:25:52
- code cleaning
- minor changes

Update: 2012-10-23 13:26:38
- mini bugfix, thx @theDOC
- separate script and configuration
- added AUR-Package

Update: 2012-10-24 22:30:14
- moved source to github

@Yaffare - Since your AUR package pulls from your github, people are not benefiting from the changes you outlined above because the code in your github repo is 8 days old.

Dude, as you can see, the last update here in this post is: moved source to github.
Probably my fault, because I ordered the changes wrong, sorry.
I have not been making any changes to the code since then, because for me, the script is working very well on serveral machines. Also I havent gotten any bug-reports or pull requests, so there was no reason for me to change the code.

You gotta push ever change you make.  Here is a helpful alias you can add to your shell rc (~/.bashrc I'm guessing) that does this for you.  Just be sure you're in the /path/to/local/repo when you call it:

alias gitc="git commit -av ; git push -u origin master"

But before I can do that I must turn my computer on, is that right? Can you please explain that too. tongue

Last edited by yaffare (2012-10-31 11:35:27)


systemd is like pacman. enjoys eating up stuff.

Offline

#19 2012-10-31 12:05:16

graysky
Wiki Maintainer
From: :wq
Registered: 2008-12-01
Posts: 10,592
Website

Re: systemd shell wrapper script - cloning rc.d output

yaffare wrote:

Dude, as you can see, the last update here in this post is: moved source to github.
Probably my fault, because I ordered the changes wrong, sorry.

Right but your DTS on that is only 7 days ago whereas the code in the github is 8 days old.  I got the impression that you had some uncommited changes.

yaffare wrote:

But before I can do that I must turn my computer on, is that right? Can you please explain that too. tongue

Sorry, I'm in a pissy mood.  No offence was intended.  You clearly have a good handle on scripting.  I just wanted to give you a code snipette to help in case you haven't used github before.


CPU-optimized Linux-ck packages @ Repo-ck  • AUR packagesZsh and other configs

Offline

#20 2012-10-31 13:50:14

American_Jesus
Member
From: Lisbon/Portugal
Registered: 2011-07-20
Posts: 37

Re: systemd shell wrapper script - cloning rc.d output

yaffare wrote:
American_Jesus wrote:

some stuff are not working with that workaround like s.{start,stop,enable,...} daemon.service, i'll try something else
when i got it working properly i make a fork of the repo and send some patches

Could you be a little more specific? What exactly is not working, what error-messages do you get?

start/stop or enable/disable units, not work with that workaround

$ s.stop ntpd.service
::  Stopping ntpd daemon[sudo] password for aj:
sudo: systemctl -q stop ntpd.service: command not found
                                                                     [FAIL]
sudo: systemctl status ntpd.service: command not found

also s.start TAB are not working

btw here's a more clean workaround

if [ "$SHELL" == "/bin/zsh" ]; then
     complt="compdef"
   else
     complt="complete -F"
fi
     $complt s_bashcompletion_start s.start
     $complt s_bashcompletion_stop s.stop
     $complt s_bashcompletion_restart s.restart
     $complt s_bashcompletion_reload s.reload
     $complt s_bashcompletion_enable s.enable
     $complt s_bashcompletion_disable s.disable
     $complt s_bashcompletion_status s.status
     $complt s_bashcompletion_wants s.wants
     $complt s_bashcompletion_log s.log

Last edited by American_Jesus (2012-10-31 15:05:43)


Archlinux X86_64

Offline

#21 2012-10-31 16:27:17

yaffare
Member
Registered: 2011-12-29
Posts: 71

Re: systemd shell wrapper script - cloning rc.d output

American_Jesus wrote:
$ s.stop ntpd.service
::  Stopping ntpd daemon[sudo] password for aj:
sudo: systemctl -q stop ntpd.service: command not found
                                                                     [FAIL]
sudo: systemctl status ntpd.service: command not found

seems like /usr/bin/ is not in your $PATH when you use sudo. I will change the call to fullpath /usr/bin/systemctl in the future.

American_Jesus wrote:

also s.start TAB are not working

btw here's a more clean workaround

if [ "$SHELL" == "/bin/zsh" ]; then
     complt="compdef"
   else
     complt="complete -F"
fi
     $complt s_bashcompletion_start s.start
     $complt s_bashcompletion_stop s.stop
     $complt s_bashcompletion_restart s.restart
     $complt s_bashcompletion_reload s.reload
     $complt s_bashcompletion_enable s.enable
     $complt s_bashcompletion_disable s.disable
     $complt s_bashcompletion_status s.status
     $complt s_bashcompletion_wants s.wants
     $complt s_bashcompletion_log s.log
yaffare wrote:

Supported Shells
- bash


systemd is like pacman. enjoys eating up stuff.

Offline

#22 2012-11-06 09:30:04

wzyboy
Member
Registered: 2012-01-21
Posts: 11

Re: systemd shell wrapper script - cloning rc.d output

Thanks a  lot! This is what exactly I want! After moving to systemd I really miss rc.d-style daemon starting/stopping messages. ( https://bbs.archlinux.org/viewtopic.php?pid=1188528 )

Last edited by wzyboy (2012-11-06 09:30:13)

Offline

#23 2012-11-30 16:14:57

maattd
Member
From: Toulouse, France
Registered: 2008-08-23
Posts: 56
Website

Re: systemd shell wrapper script - cloning rc.d output

Is it possible to make it work with ZSH ?

Offline

#24 2012-11-30 16:46:15

illusionist
Member
From: localhost
Registered: 2012-04-03
Posts: 498

Re: systemd shell wrapper script - cloning rc.d output

yaffare wrote:
Hspasta wrote:

Other shell support (zsh) planned?

I may do this at some point in the future, but not now, as I do not use or know anything about zsh.
If someone else would convert the script one time to zsh, I would integrate and maintain it.

@mattd
Although American_Jesus posted his work here. You may try that.


  Never argue with stupid people,They will drag you down to their level and then beat you with experience.--Mark Twain
@github

Offline

Board footer

Powered by FluxBB