# How to set a custom umask for service?



## SolomonKane (Dec 24, 2022)

I want the files created by the service to have read and write permissions for the group.
For example qbittorrent creates files with permissions -rw-r--r-- i.e. umask 022 and I need -rw-rw-r-- i.e. umask 002.

I tested adding:


```
start_precmd=qbittorrent_prestart

qbittorrent_prestart()
{
        umask 002
}
```

to the /usr/local/etc/rc.d/qbittorrent but this doesnt help.


----------



## T-Daemon (Dec 25, 2022)

Hi SolomonKane,

set in /usr/local/etc/rc.d/qbittorrent

```
...
command="/usr/local/bin/qbittorrent-nox"
command_args="--daemon"

*umask 002*

qbittorrent_flags=" \
        ...
```

Works for me:

```
% ls -l /var/db/qbittorrent/conf/qBittorrent/downloads/
*drwxrwxr-x*  2 qbittorrent  qbittorrent  4 Dec 25 21:48 Some dir/

% ls -l  /var/db/qbittorrent/conf/qBittorrent/downloads/'Some dir'
total 161
*-rw-rw-r--*  1 qbittorrent  qbittorrent  150986 Dec 25 21:48 Some file
```


----------



## T-Daemon (Dec 26, 2022)

Checked your rc(8) script pre-command, it works just fine.

I assumed in my previous post it didn't work. Maybe you didn't re-start the qbittorrent service after modifying the script?

/usr/local/etc/rc.d/qbittorrent

```
...

command="/usr/local/bin/qbittorrent-nox"
command_args="--daemon"
*start_precmd=qbittorrent_precmd

qbittorrent_precmd()
{
    umask 002
}*

qbittorrent_flags=" \
            ...
```


```
% ls -l /var/db/qbittorrent/conf/qBittorrent/downloads/
total 17
*drwxrwxr-x*  2 qbittorrent  qbittorrent  4 Dec 26 11:09 Some dir

 % ls -l /var/db/qbittorrent/conf/qBittorrent/downloads/'Some dir'
total 161
*-rw-rw-r--*  1 qbittorrent  qbittorrent  150986 Dec 26 11:09 Some file
```


----------



## covacat (Dec 26, 2022)

can't you play with qbittorrent_login_class ? and set umask in login.conf ?


----------



## SolomonKane (Dec 26, 2022)

I tested both

```
...
command="/usr/local/bin/qbittorrent-nox"
command_args="--daemon"

umask 002

qbittorrent_flags=" \
        ...
```
and

```
...

command="/usr/local/bin/qbittorrent-nox"
command_args="--daemon"
start_precmd=qbittorrent_precmd

qbittorrent_precmd()
{
    umask 002
}

qbittorrent_flags=" \
            ...
```

each time restarting service and still file permissions on newly created files are -rw-r--r--

In /etc/rc.conf

qbittorrent_enable="YES"

System is FreeBSD 13.1


----------



## T-Daemon (Dec 27, 2022)

SolomonKane said:


> System is FreeBSD 13.1


Same here, 13.1-RELEASE. net-p2p/qbittorrent version 4.5.0, nox flavor, running Web UI. With the modified rc(8) script downloaded files get `-rw-rw-r--` permissions.

Not sure what's different on your system. I suppose you haven't modified ACLs (Access Control Lists) of the default save directory? setfacl(1), getfacl(1), if file system ZFS zfsprops(7) `aclmod=`.


Try, instead of modifying the rc(8) script,


> Run external program on torrent completion (finished) option  (found in Preferences > Downloads):
> 
> 
> ```
> ...


From https://qbforums.shiki.hu/viewtopic.php?p=32896&sid=685a88c5778e187ebff1d39e5c042e2c#p32896


----------



## SolomonKane (Dec 27, 2022)

It's clean install of OS.
What settings related to ACL should be modified?


----------



## T-Daemon (Dec 28, 2022)

SolomonKane said:


> What settings related to ACL should be modified?


They should not be modified. There is no special permission setting on the default save directory required. The umask setting in the qbittorrent rc(8) script should change directory and file permissions.

I can't see why on your system the permissions are not set as instructed. ACLs was the only thing coming to my mind which could prevent a umask 002. But since you haven't changed them I'm out of ideas.

Have you tried the suggested solution from the qBittorrent forum I linked?


----------



## SolomonKane (Dec 28, 2022)

Problem with "Run external program on torrent completion" is that if i move completed torrent or change its category in WebUI file permisions drop to default.

Can you post full text of /usr/local/etc/rc.d/qbittorrent and /etc/rc.conf?

Mine version shown by qbittorrent-nox --version is 4.4.5 not 4.5.0 and thats strange considering same distro versions.



covacat said:


> can't you play with qbittorrent_login_class ? and set umask in login.conf ?


I guess login.conf is used when user logs in and qbittorrent user never actually logs in.


----------



## T-Daemon (Dec 29, 2022)

SolomonKane said:


> Mine version shown by qbittorrent-nox --version is 4.4.5 not 4.5.0 and thats strange considering same distro versions.


There are two FreeBSD:13 package repositories, 'quarterly' and 'latest'.  Your package repository configuration is set to 'quarterly' by default, I've set mine to 'latest'.

/etc/pkg/FreeBSD.conf

```
# $FreeBSD$
#
# To disable this repository, instead of modifying or removing this file,
# create a /usr/local/etc/pkg/repos/FreeBSD.conf file:
#
#   mkdir -p /usr/local/etc/pkg/repos
#   echo "FreeBSD: { enabled: no }" > /usr/local/etc/pkg/repos/FreeBSD.conf
#

FreeBSD: {
  url: "pkg+http://pkg.FreeBSD.org/${ABI}/*quarterly*",
  mirror_type: "srv",
  signature_type: "fingerprints",
  fingerprints: "/usr/share/keys/pkg",
  enabled: yes
}
```

The reason for the quarterly ports (packages) branch:


			Ports/QuarterlyBranch - FreeBSD Wiki
		


On https://freshports.org the package versions between 'quarterly' and 'latest' can be compared:

https://www.freshports.org/net-p2p/qbittorrent#packages .


----------



## T-Daemon (Dec 29, 2022)

SolomonKane said:


> Can you post full text of /usr/local/etc/rc.d/qbittorrent




```
#!/bin/sh

# PROVIDE: qbittorrent
# REQUIRE: DAEMON
# KEYWORD: shutdown
#
# Add the following lines to /etc/rc.conf to enable this service:
#
# qbittorrent_enable:        Set to NO by default. Set it to YES to enable it.
# qbittorrent_conf_dir:      Directory where qbittorrent configuration
#                            data is stored.
#                            Default: /var/db/qbittorrent/conf
# qbittorrent_download_dir:  Directory to store downloaded data.
#                            Default: /var/db/qbittorrent/Downloads
# qbittorrent_user:          The user account transmission daemon runs as.
#                            Default is 'qbittorrent'
# qbittorrent_group:         The group associated with username qbittorrent
#                            daemon runs as. Default is 'qbittorrent'
#

. /etc/rc.subr

name=qbittorrent
rcvar=qbittorrent_enable

load_rc_config $name

: ${qbittorrent_enable="NO"}
: ${qbittorrent_conf_dir="/var/db/qbittorrent/conf"}
: ${qbittorrent_download_dir="/var/db/qbittorrent/Downloads"}
: ${qbittorrent_user=qbittorrent}
: ${qbittorrent_group=qbittorrent}

command="/usr/local/bin/qbittorrent-nox"
command_args="--daemon"
start_precmd=qbittorrent_precmd

qbittorrent_precmd()
{
        umask 002
}

qbittorrent_flags=" \
        ${qbittorrent_conf_dir:+--profile=${qbittorrent_conf_dir}} \
        ${qbittorrent_download_dir:+--save-path=${qbittorrent_download_dir}} \
        ${qbittorrent_flags}"

run_rc_command $1
```

Check also file type of the rc(8) script, see if there is some unusual output. It should be

```
% file /usr/local/etc/rc.d/qbittorrent
/usr/local/etc/rc.d/qbittorrent: POSIX shell script, ASCII text executable
```



SolomonKane said:


> and /etc/rc.conf?



There is only one line related to qBittorrent in /etc/rc.conf, the same you have:

```
qbittorrent_enable="YES"
```


----------



## T-Daemon (Dec 29, 2022)

Try this for testing purposes, not permanent solution, execute as root:

```
# service qbittorrent stop
# qbittorrent-nox -d
```

As normal user open Web UI, set in 'Options -> Saving Management -> Default Save Path', e.g., /tmp/qbittorrent/Downloads
Exit qBittorrent.

As root:

```
# mkdir -p /tmp/qbittorrent/Downloads
# chown -R qbittorrent:qbittorrent /tmp/qbittorrent

# umask 002
# qbittorrent-nox -d
```
As normal user download a small file and check permissions.

After you are done, exit Web UI, start qbittorrent service.


----------



## SolomonKane (Dec 29, 2022)

T-Daemon said:


> As root:
> 
> ```
> # mkdir -p /tmp/qbittorrent/Downloads
> ...


file permissions change

but files downloaded by service still have default mask


----------



## SolomonKane (Thursday at 4:47 PM)

umask changes for qbittorrent-nox service if i start it by calling it's script(modified) manually by
`/usr/local/etc/rc.d/qbittorrent start`
but umask stays default 022 if service started by command
`service qbittorrent start`

how to make service start automatically by `/usr/local/etc/rc.d/qbittorrent start` ?


----------



## T-Daemon (Thursday at 7:59 PM)

SolomonKane said:


> umask changes for qbittorrent-nox service if i start it by calling it's script(modified) manually by
> /usr/local/etc/rc.d/qbittorrent start
> but umask stays default 022 if service started by command
> `service qbittorrent start`


I still can't imagine what could be the causing not to work on your system, it's not a normal service(8) behavior.

Have you upgraded all installed packages? The "quarterly" ports tree, from which the "quarterly" packages are build, has been cut from the "main" branch recently into 2023Q1, net-p2p/qbittorrent is now at version 4.5.0.

While we are at it, freebsd-update(8) the system also, if not done yet.



SolomonKane said:


> how to make service start automatically by `/usr/local/etc/rc.d/qbittorrent start` ?


You could set it as a cron(8) job, which would start the daemon after every system boot, but try version 4.5.0 first, after upgrading packages, in case you haven't done it already.

Disable the qbittorrent variable in /etc/rc.conf, as root `crontab -e`:

```
@reboot   /usr/local/etc/rc.d/qbittorrent onestart
```
If you are unfamiliar with crontab(1), its editor is vi(1).


----------

