Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Systemd service file #623

Closed
UweSauter opened this issue Apr 5, 2020 · 12 comments · Fixed by #633
Closed

Systemd service file #623

UweSauter opened this issue Apr 5, 2020 · 12 comments · Fixed by #633

Comments

@UweSauter
Copy link

UweSauter commented Apr 5, 2020

You might want to include the following file as /usr/lib/systemd/system/[email protected]. It allows openfortivpn to act as system service with its configuration stored in /etc/openfortivpn/<NAME>.conf.
Start a particular configuration with systemctl start [email protected].

[Unit]
Description=OpenFortiVPN for %I
After=network-online.target

[Service]
Type=simple
PrivateTmp=true
ExecStart=/usr/bin/openfortivpn -c /etc/openfortivpn/%I.conf
OOMScoreAdjust=-100

[Install]
WantedBy=multi-user.target
@DimitriPapadopoulos
Copy link
Collaborator

DimitriPapadopoulos commented Apr 6, 2020

I'm not certain the openfortivpn sources are the place to add this file to.

If you want this file added to RPM packages please ask the packagers. I think that's where you may add a pull request:
https://src.fedoraproject.org/rpms/openfortivpn

@UweSauter
Copy link
Author

As you say.
At least others now have a reference if they build openfortivpn manually.

@DimitriPapadopoulos
Copy link
Collaborator

DimitriPapadopoulos commented Apr 7, 2020

If you think it's useful outside of vendor packages we could add the file. It's just that not all target platforms have systemd. The title of this issue starts with CentOS 8.1 so I assumed this is only relevant for CentOS 8.

We need to detect if systemd is available and find the location to write the file to. I don't know is the target always /usr/lib/systemd/system/? Could systemd be installed elsewhere, even in theory? We probably need to query pkg-config.

@DimitriPapadopoulos
Copy link
Collaborator

On Ubuntu 18.04 /usr/lib/systemd/system is exposed in by variable systemdsystemunitpath of pkg-config together with other paths:

$ pkg-config systemd --variable=systemdsystemunitpath
/etc/systemd/system:/etc/systemd/system:/run/systemd/system:/usr/local/lib/systemd/system:/lib/systemd/system:/usr/lib/systemd/system:/lib/systemd/system
$ 

However on Ubuntu /usr/lib/systemd/system does not exist, only /lib/systemd/system:

$ ls /usr/lib/systemd/system
ls: cannot access '/usr/lib/systemd/system': No such file or directory
$ 
$ ls /lib/systemd/system/*@.service
/lib/systemd/system/[email protected]
/lib/systemd/system/[email protected]
/lib/systemd/system/[email protected]
/lib/systemd/system/[email protected]
[...]
/lib/systemd/system/[email protected]
/lib/systemd/system/[email protected]
$ 

That said on Fedora /lib is a symlink to /usr/lib:

$ ls -l /lib
lrwxrwxrwx. 1 root root 7 Jul 25  2019 /lib -> usr/lib
$ 

And indeed while some of these files are brought by the systemd package, other are brought by other packages similar to openfortivpn:

$ dpkg -S /lib/systemd/system/*@.service
apport: /lib/systemd/system/[email protected]
systemd: /lib/systemd/system/[email protected]
udisks2: /lib/systemd/system/[email protected]
system-config-printer-udev: /lib/systemd/system/[email protected]
[...]
wpasupplicant: /lib/systemd/system/[email protected]
wpasupplicant: /lib/systemd/system/[email protected]
$ 

In short I'm OK with adding this file but I don't know how to find the target directory, either /lib/systemd/system or /usr/lib/systemd/system. I'll have a look at how other Ubuntu and Fedora packages generate similar files. Are they installed by upstream sources or by vendor-specific packages?

@mrbaseman
Copy link
Collaborator

perhaps as a template in $PREFIX/share/systemd?

@DimitriPapadopoulos
Copy link
Collaborator

DimitriPapadopoulos commented Apr 8, 2020

The apport setup script does seem to be installing such a file:
https://github.com/rickysarraf/apport/blob/master/data/systemd/apport-forward%40.service
and part of the relevant code is here:
https://github.com/rickysarraf/apport/blob/0582b09/setup.py#L115-L122

# determine systemd unit directory
try:
    systemd_unit_dir = subprocess.check_output(
        ['pkg-config', '--variable=systemdsystemunitdir', 'systemd'],
        universal_newlines=True).strip()
except subprocess.CalledProcessError:
    # hardcoded fallback path
    systemd_unit_dir = '/lib/systemd/system'

It appears the proper pkg-config variable is systemdsystemunitdir.

On Ubuntu 18.04:

$ pkg-config --variable=systemdsystemunitdir systemd
/lib/systemd/system
$ 

On Fedora 31:

$ pkg-config --variable=systemdsystemunitdir systemd
/usr/lib/systemd/system
$ 

We can get the source installation process to install the file if systemd is available. But then vendor packages might need to be modified as well to include this file.

@DimitriPapadopoulos
Copy link
Collaborator

More information on how to use Autotools to install the file here:
https://stackoverflow.com/questions/58017453/install-systemd-service-using-autotools

@UweSauter
Copy link
Author

When I installed it a few days ago from EPEL 8 no systemd unit file was included. This is the content of the package:

# rpm -ql openfortivpn
/etc/openfortivpn
/etc/openfortivpn/config
/usr/bin/openfortivpn
/usr/lib/.build-id
/usr/lib/.build-id/cf
/usr/lib/.build-id/cf/0a00798e7f1acf977f7aeb9e63f9046df0980d
/usr/share/doc/openfortivpn
/usr/share/doc/openfortivpn/README.md
/usr/share/licenses/openfortivpn
/usr/share/licenses/openfortivpn/LICENSE
/usr/share/man/man1/openfortivpn.1.gz
/usr/share/openfortivpn
/usr/share/openfortivpn/config.template

@DimitriPapadopoulos
Copy link
Collaborator

DimitriPapadopoulos commented Apr 8, 2020

@UweSauter Yes, right now it is totally expected that no systemd unit file is included.

@UweSauter
Copy link
Author

As I wrote before I'm happy if this issue is just kept as reference for those in need of a systemd unit file.

@DimitriPapadopoulos
Copy link
Collaborator

@UweSauter We are precisely in the process of finding a way to add the file.

@DimitriPapadopoulos
Copy link
Collaborator

I have provided a patch that installs the file when systemd is available:
#633
Do you want to give it a try?

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

Successfully merging a pull request may close this issue.

3 participants