Skip to content

Work on Systemd service unit#6806

Merged
Chocobo1 merged 1 commit into
qbittorrent:masterfrom
Anton-Latukha:master
Jul 1, 2017
Merged

Work on Systemd service unit#6806
Chocobo1 merged 1 commit into
qbittorrent:masterfrom
Anton-Latukha:master

Conversation

@Anton-Latukha
Copy link
Copy Markdown
Contributor

@Anton-Latukha Anton-Latukha commented May 18, 2017

On Ubuntu qBittorrent-nox comes without service. Because service unit was in bad state.

qBittorrent-nox should provide a good service, because its purpose is to run as a daemon, or, better, a service on server.

Without service, on every restart user needs to start daemon manually, or make service by himself.

Pull request does work adding a reliable service.

Possibility to pick user:

systemctl start qbittorrent-nox@user.service
systemctl enable qbittorrent-nox@user.service

On why old service removed

Old-one service unit had issues:

  • hardcoded to 1000 user
  • demonise and Type=forking is not a proper way to build Systemd service, because Systemd loose control over that process and it's stdout (logs).

Also old service on change become redundant, so it was removed.

Packaging

Maintainers know what to do in this situation.
If link /etc/systemd/system/multi-user.target.wants/qbittorrent-nox.service exists - package manager instruction need to leave that old file on hard drive. If link not exists - service was not enabled, so it is safe to remove old unit file.

If someone has it working on old service unit - it is going to continue to work.
On updates new service file is going to be added.
On new installations - only new service file is going to be added.

Placing new service file

Corresponding to systemd standards, there are no segregation on { @ : %i } feature for units, they placed just like other ones. In other words this new service file goes in the same directory as previous one. So only minor renaming in cmake was needed.

@Anton-Latukha
Copy link
Copy Markdown
Contributor Author

Anton-Latukha commented May 18, 2017

I don't use any.

It is not my agenda, I don't have those systems and I have no applications for that. Most of users is going to be satisfied with auto-start.

Create Windows service is not so hard, I used to do it couple of times years ago. To do SNMP and active-agent monitoring on hosts.

There is a number of tools.

I think I used this one: 1. Because it is in default Windows installation.

And call execution as an Administrator. 2

Also there is other similar utilities: 3, 4

For other way, is to use programming languages. Like C++: main callback if binary is not service capable.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since web UI port can be set via config file (and as such via web UI itself), this breaks the POLA principle.

@zeule
Copy link
Copy Markdown
Contributor

zeule commented May 18, 2017

You have to make changes to configure.ac as well.

@Anton-Latukha
Copy link
Copy Markdown
Contributor Author

Ok.

Understood.

This can be closed.

@zeule
Copy link
Copy Markdown
Contributor

zeule commented May 18, 2017

This can be closed.

Why?

@Anton-Latukha
Copy link
Copy Markdown
Contributor Author

Anton-Latukha commented May 18, 2017

Ok.

Sorry, I'm not experienced, in pull requests workflow.

I'm going to look what is going on, and how to update my pull request to full extend.

@Anton-Latukha
Copy link
Copy Markdown
Contributor Author

'Add more commits by pushing to the master branch on Anton-Latukha/qBittorrent.' Ok 👍

@zeule
Copy link
Copy Markdown
Contributor

zeule commented May 18, 2017

  1. Create a new branch for the PR, based on master branch: $ git checkout master; git checkout -b my-branch-name
  2. Make changes and commit them.
  3. Create a PR.
  4. When you are asked to make a correction, make a fixup commit, optionally using git --fixup option $ git commit --fixup=... and push new commits.
  5. When PR is ready to be merged, squash your fixup commits: $ git rebase -i --autosquash master and force push the branch: $ git push --force

@zeule
Copy link
Copy Markdown
Contributor

zeule commented May 18, 2017

Changed all mentions of service to new file.

Good, thank you. Now what about --webui-port option?

oops, you've done it too. Thanks!

@Anton-Latukha
Copy link
Copy Markdown
Contributor Author

Done.

Now I know, do all commits and one push in this situations.
CI reacts on every push.

@zeule
Copy link
Copy Markdown
Contributor

zeule commented May 18, 2017

It's funny, but configure does not process qbittorrent-nox.service.in nor it does that in master. So I can not test this PR yet.

@Anton-Latukha
Copy link
Copy Markdown
Contributor Author

Anton-Latukha commented May 18, 2017

I going to wait on test.

This service works for myself. But I am not knowledgeable how provisioning of it through code to package must happen.

I know only this: dist/unix/CMakeLists.txt

configure_file(systemd/qbittorrent-nox@.service.in ${CMAKE_CURRENT_BINARY_DIR}/qbittorrent-nox@.service @ONLY)

I don't know cmake or configure process, I thought it processes qbittorrent-nox.service.in to qbittorrent-nox@.service and moves ahead, and then maintainers work with those files.

Sorry, I am a DevOps )

@zeule
Copy link
Copy Markdown
Contributor

zeule commented May 18, 2017

It's funny, but configure does not process qbittorrent-nox.service.in nor it does that in master.

My bad, that was evening and two qBt copies on disk...

zeule
zeule previously approved these changes May 18, 2017
@zeule
Copy link
Copy Markdown
Contributor

zeule commented May 18, 2017

@qbittorrent/frequent-contributors, does anybody want to review?

@zeule
Copy link
Copy Markdown
Contributor

zeule commented May 18, 2017

@Anton-Latukha, please squash all your commits.

Copy link
Copy Markdown
Member

@Chocobo1 Chocobo1 May 19, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how about qBittorrent-nox service for user %I?
it's not a daemon anymore.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMO, better be explicit, pls add back Type=simple

@Chocobo1
Copy link
Copy Markdown
Member

@Anton-Latukha
Have you tried running multiple qbt-nox instances at the same time? Does it work?

@KingLucius
Copy link
Copy Markdown

KingLucius commented May 19, 2017

Sorry for hijacking the thread.
@evsh squash your fixup commits: $ git rebase -i --autosquash master
do I have to rebase against master or the first commit in the new feature branch?

My current approach,

  1. create new feature branch
  2. make then commit changes
  3. when you ask for correction I commit the changes with "amend" option (which will squash but there is no return)
  4. force push

@zeule
Copy link
Copy Markdown
Contributor

zeule commented May 19, 2017

@KingLucius, rebasing against master serves two purposes: you not only squash commits, but also resolve merge conflicts. So you need up-to-date master branch,

@zeule
Copy link
Copy Markdown
Contributor

zeule commented May 19, 2017

Have you tried running multiple qbt-nox instances at the same time? Does it work?

It is possible with an isolated /tmp/ dir. We can, actually, add PrivateTmp=true to the service file for that.

@Chocobo1
Copy link
Copy Markdown
Member

We can, actually, add PrivateTmp=true to the service file for that.

Actually, I think that is required in case of this PR.

@zeule
Copy link
Copy Markdown
Contributor

zeule commented May 20, 2017

But that would disable passing parameters to the running instance.

@Chocobo1
Copy link
Copy Markdown
Member

@Anton-Latukha
Is running multiple instance of qbt the target of this PR?

@Anton-Latukha
Copy link
Copy Markdown
Contributor Author

Anton-Latukha commented Jun 7, 2017

@Chocobo1

I did source build of my fork and some testing:

This moments:

  1. Service file is not placed in service directory on build.
  2. Instances use the same port.
  3. Instances not report, or error, when port already used.

Fully user-based service:
There's also a other possible implementation, as a clearly user service (great article on ArchWiki).

I have chosen to pull current one, root based, because it is more used and encountered, by me anyway. And it work-around a moment, when users start to run instances, - those port and other inconsistencies lays on the hands of OS root administrator. It is better something than nothing.

User-based service going to enable for use that now available switch (%i) for port, but it going to collude then with conf file setting. Then that needs to be resolved.

I have chosen a more simple solution.

P.S. If that moments are going to be addressed - we can think to do multi-user qB-nox.

@Anton-Latukha
Copy link
Copy Markdown
Contributor Author

@evsh
I've made a commit squash, as you asked.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I understand your reply correctly, qbt is not ready for multi-user usage, then this should be PrivateTmp=false for now.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And there is a typo in commit message: w to systemd service ... ??

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PrivateTmp=true is a recommended secure option by Systemd team.
Since it doesn't interfere with work, it can be left as is.

But as you request, I'll remove it.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is no typo, it is intuitive vocabulary I use in commits names, in Git or on wikis.

Like:
w - for 'write'
rw - for 'rewrite'
del - for 'deletions'
add
mv - for 'move'
sec - for 'section'
subsec - for 'subsection'
and so on.

So:

add subsec "anton" in sec "Draft"
rw subsec "anton"
mv subsec "anton" to sec "Name"
w to subsec "anton" useful information about qBittorrent.

I don't know why something like this is not widely adopted, so I promote it by example.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know why something like this is not widely adopted

My reaction is exactly why and honestly this is the first time I encounter this kind of shorthand...

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Chocobo1:

this is the first time I encounter this kind of shorthand...

Actually, that shorthand is pretty standard command-line syntax for defining file access permissions, and database variables.

That being said, it does make very little sense to use it in an otherwise conventional English sentence.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, that shorthand is pretty standard command-line syntax for defining file access permissions, and database variables.

right... the shorthand usage depends on the context.
And my thoughts are clearly expressed in your second sentence.

Copy link
Copy Markdown
Member

@Chocobo1 Chocobo1 Jun 12, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But as you request, I'll remove it.

It's actually a bit more complex under the hood, if PrivateTmp=true you won't be able to add torrents to qbt via cmdline easily, I'm not sure users uses this extensively or not...
also: #6806 (comment)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would prefer moving this line on top of User=

@Anton-Latukha
Copy link
Copy Markdown
Contributor Author

I opened a bug report:

If WebUI port already used - qBittorrent-nox does nothing #6955

rm previous systemd unit service

cmake now placing new file 'qbittorrent-nox@.service.in'

systemd service now "Type=simple"
@Anton-Latukha
Copy link
Copy Markdown
Contributor Author

Anton-Latukha commented Jun 12, 2017

If bug #6955 sorts-out, than probably we can use this service.

Or move and do real user-service.

Considering proper usage of:
XDG Basedir specification

$XDG_RUNTIME_DIR defines the base directory relative to which user-specific non-essential runtime files and other file objects (such as sockets, named pipes, ...) should be stored. The directory MUST be owned by the user, and he MUST be the only one having read and write access to it. Its Unix access mode MUST be 0700.
$XDG_CACHE_HOME defines the base directory relative to which user specific non-essential data files should be stored.

So PrivateTmp - qBt-nox CLI on user-service is non an issue.

@Anton-Latukha
Copy link
Copy Markdown
Contributor Author

@Chocobo1 Done what you being asking: set PrivateTmp=false and moved things around.

Copy link
Copy Markdown
Member

@Chocobo1 Chocobo1 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@Chocobo1
Copy link
Copy Markdown
Member

Considering proper usage of:
XDG Basedir specification

Thanks for the information! This might be a good idea...
AFAIK qbt isn't using $XDG_RUNTIME_DIR right now.

@Anton-Latukha
Copy link
Copy Markdown
Contributor Author

Anton-Latukha commented Jun 15, 2017

Ok @Chocobo1. Thank you.

I remind about, that all XDG Basedir variables have established fallback.

For $XDG_RUNTIME_DIR it is not literally set in spec, but: '/run/user/'"$UID" must be default path on most distributions.

@Chocobo1
Copy link
Copy Markdown
Member

@evsh @sledgehammer999
Shall we merge it? IMO it's ready in its current form.

@Chocobo1 Chocobo1 merged commit 8150805 into qbittorrent:master Jul 1, 2017
@Chocobo1
Copy link
Copy Markdown
Member

Chocobo1 commented Jul 1, 2017

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants