You are not logged in.

#1 2015-08-24 06:43:16

julesm
Member
Registered: 2014-07-29
Posts: 70

[SOLVED] trying to understand systemd and daemons

I'm trying to understand something about systemd and daemons.

Here's the setup: I can start openvpn by the command line as a daemon with the "daemon" parameter in the openvpn config file. It all works fine. No questions so far...

To find my daemon, I use the following command and can see it:

ps -ef | grep openvpn

And to stop openvpn, the only way that I know how to do this (when it's running as a daemon) to issue this command:

sudo pkill -SIGTERM openvpn

Again, it works fine and openvpn is now stopped.

Here my question: Is there a way using systemd to stop and even restart openvpn in the way that I'm running it - as a daemon? Or does systemctl stop/restart only work when the daemon is running as a systemd service?

Again, everything is working fine - I'm just trying to understand systemd and daemons a bit better.

Cheers!

Last edited by julesm (2015-08-24 17:33:27)

Offline

#2 2015-08-24 07:28:21

jasonwryan
Anarchist
From: .nz
Registered: 2009-05-09
Posts: 30,424
Website

Re: [SOLVED] trying to understand systemd and daemons

Read the openvpn service file...


Arch + dwm   •   Mercurial repos  •   Surfraw

Registered Linux User #482438

Offline

#3 2015-08-24 09:14:22

smiszym
Member
Registered: 2014-04-04
Posts: 14

Re: [SOLVED] trying to understand systemd and daemons

I don't know whether systemd is able to stop or restart process not started with systemctl, but I think the recommended way is to start, stop, restart, etc with systemctl. (manually for testing)

You can start a daemon using systemctl with one of the commands (depending on what you want, client or server):

# systemctl start openvpn@server.service
# systemctl start openvpn@client.service

Offline

#4 2015-08-24 09:28:23

GloW_on_dub
Member
Registered: 2013-03-13
Posts: 388

Re: [SOLVED] trying to understand systemd and daemons

information that can be found in the OpenVPN wiki page.

Offline

#5 2015-08-24 11:10:22

julesm
Member
Registered: 2014-07-29
Posts: 70

Re: [SOLVED] trying to understand systemd and daemons

Many thanks for all of that. But what I'm asking (I believe) is slightly different.

The wiki page mainly talks about starting openvpn as a service. That's not what I'm doing. I'm starting it as a daemon manually and I want to know if I can then use systemd to stop/restart it. I know that if I start openvpn as a service then I can use systemd.

But can you stop/restart using systemd a daemon that you've started manually?  That's my question.

I've probably muddied the waters by using openvpn as an example. My question has little if anything to do with openvpn...

Last edited by julesm (2015-08-24 11:25:13)

Offline

#6 2015-08-24 13:44:31

fsckd
Forum Fellow
Registered: 2009-06-15
Posts: 4,173

Re: [SOLVED] trying to understand systemd and daemons

No you can't. When a process is daemonized, it just means it forked off so that it doesn't get closed when the parent process gets closed. You can do this with any program. systemd does not stop those for you. To stop a manually started daemon, find its PID and use kill. Well behaved daemonized process make a pid file with their PID in it. (Pid files are what rc scripts use to stop daemons.)


aur S & M :: forum rules :: Community Ethos
Resources for Women, POC, LGBT*, and allies

Offline

#7 2015-08-24 14:43:30

tomk
Forum Fellow
From: Ireland
Registered: 2004-07-21
Posts: 9,839

Re: [SOLVED] trying to understand systemd and daemons

julesm wrote:

can you stop/restart using systemd a daemon that you've started manually?

Already answered by fsckd, but I'm curious why you think you need this? Seems obvious to me that if you want to use systemd, you should use systemd. If you want to do things manually, do that instead. What would you achieve by this mix-n-match approach, even if it was possible?

Offline

#8 2015-08-24 17:33:02

julesm
Member
Registered: 2014-07-29
Posts: 70

Re: [SOLVED] trying to understand systemd and daemons

Excellent - fsckd - that was just the explanation and understanding that I was after!  Thanks again for that!

tomk, the more I get into Arch, the more stuff I try and I think about...sometimes it's a bit of a rabbit hole - doing one thing makes me wonder about another and then I find myself wondering how that works and whether I could do something else altogether - even if I'm not going to...but I suppose that's what makes Arch so much fun - it gets you thinking and trying out things that you wouldn't otherwise dare do!

Thanks again for the info!  Now I understand it much, much better!

Jules

Offline

Board footer

Powered by FluxBB