SYSV init discussion

Linux SYSV init testing - Redhat & Debian

This thread is for combined final development testing and forum preview prior to creation of the releasable package.

In this thread, we will:

  1. Test the system configuration validator.
  2. Test the updated installer.
  3. Test a full CI-built package .

The new validator:

  1. Is generic. It handles both /etc/default/plexmediaserver and /etc/systemd/system/plexmediserver.service.d/*.conf
  2. Ingests your configuration overrides
  3. Adapts to the system’s video group (if not root) and attaches Plex to it
  4. Performs basic existence and permissions testing of the operating enviornment
  5. Reports illegal variables found
  6. Reports conflicting configuration file conditions

The new validator does not:

  1. Write to your system at this time.
    This is a point of discussion. The preference is to leave your system as you intend it. Only the most basic changes will be made during initial Plex installation.

  2. The test version shows its actions instead of making any actual changes it normally would during installation / update

  3. Does not require root permission to execute.

The new installer will install both configurations: init and systemd
It will will only link the configuration needed based on pid 1 (init or systemd)

Should you change between the two, it is your responsibility to issue the appropriate update-rc.d or systemctl command(s) as required.

This thread is expected to be lengthy.
There will be a companion thread created with the same sysv-init-testing tag which is strictly for testing the package files as they are build. Issues will be handled there.

Goals:

  1. Try to break it. Look the script over and find ways to break it if possible.
  2. Find out what has been omitted so it can be added.

Let the discussion begin.

Update: 29-Apr-2019

  1. Fixes:
    a. init= syntax error
    b. systemd / init reporting error
    c. Incorrectly selected null PlexGroup
  2. Additions: - None

Update: 30-Apr-2019

  • File which should have been posted yesterday :jack_o_lantern:

PMS-installation-validator.tar.gz (3.8 KB)

2 Likes

When helping to test the validator, you should be able to create errors / output such as this:

[chuck@lizum init.530]$ ./validate-sysv
Error: Unknown username 'Chuck' used in /etc/systemd/system/plexmediaserver.service.d/override.conf.
Error: Unkown group name 'Chuck' used in /etc/systemd/system/plexmediaserver.service.d/override.conf.
Error: Directory '/home/botswanna/Application Support' in /etc/systemd/system/plexmediaserver.service.d/override.conf does not exist.
SUBSYSTEM=="usb", ATTRS{idVendor}=="1d19", ATTRS{idProduct}=="0100",  GROUP="video" , MODE="0660" > /lib/udev/rules.d/60-tv-butler.rules
SUBSYSTEM=="drm", GROUP="video" , MODE="0660" > /lib/udev/rules.d/60-plex-hw-transcoding.rules
udevadm control --reload-rules
devadm trigger
Validation tests: FAIL
Process Control:  Systemd
Plex user:        plex
Plex group:       plex
Video Group:      video
AppSupp Dir:      /var/lib/plexmediaserver/Library/Application Support
Config file:      /etc/systemd/system/plexmediaserver.service.d/override.conf
[chuck@lizum init.531]$ 

Apologies for not getting to this until now. It’s been a really hard last couple of weeks.

Chuck, nicely written code. I’m impressed.

Just ran it and that is what I have so far.

Downloaded file is not a tar.gz, but just a tar actually.

Line 169 has a spelling error.

First time running:
./PMS-installation-validator: line 82: Init: command not found
Line 82 need to be changed from:
Init = 1
to
Init=1

Process Control is backwards:
Line 356:

if [ $Init -eq 1 ]; then
echo “Process Control: Systemd”
else
echo “Process Control: Init”
fi

to

if [ $Init -eq 1 ]; then
echo “Process Control: Init”
else
echo “Process Control: Systemd”
fi

My output:
==groupadd plex
==usermod -a -G plex plex
Warning: PLEX_MEDIA_SERVER_USER is obsolete. Please use PLEX_USER to override the default username in /etc/default/plexmediaserver.
Retaining username: plex
==usermod -a -G video plex
==SUBSYSTEM==“usb”, ATTRS{idVendor}==“1d19”, ATTRS{idProduct}==“0100”, GROUP=“video” , MODE=“0660” > /lib/udev/rules.d/60-tv-butler.rules
==SUBSYSTEM==“drm”, GROUP=“video” , MODE=“0660” > /lib/udev/rules.d/60-plex-hw-transcoding.rules
==udevadm control --reload-rules
==devadm trigger
Validation tests: PASS
Process Control: Init
Plex user: plex
Plex group:
Video Group: video
AppSupp Dir: /var/lib/plexmediaserver/Library/Application Support
Config file: /etc/default/plexmediaserver

Should a warning happen if no plex group was found? I do not have a plex group.

Thanks for the feedback. I was about to put this all back on the shelf until later.

I have made the corrections you indicated plus found and corrrected a logic error.

The updated script can be found above.

Please let the others know.

I would like to validate this for ALL linux systems (systemd and init).
It is my intention to make one base package for all Linux distributions.
This reduces the prerequisites to glibc and a compatible package manager.

New output once I made the change above:

./PMS-installation-validator
==groupadd plex
==usermod -a -G plex plex
Warning: PLEX_MEDIA_SERVER_USER is obsolete. Please use PLEX_USER to override the default username in /etc/default/plexmediaserver.
Retaining username: plex
==usermod -a -G video plex
==SUBSYSTEM==“usb”, ATTRS{idVendor}==“1d19”, ATTRS{idProduct}==“0100”, GROUP=“video” , MODE=“0660” > /lib/udev/rules.d/60-tv-butler.rules
==SUBSYSTEM==“drm”, GROUP=“video” , MODE=“0660” > /lib/udev/rules.d/60-plex-hw-transcoding.rules
==udevadm control --reload-rules
==devadm trigger
Validation tests: PASS
Process Control: Init
Plex user: plex
Plex group:
Video Group: video
AppSupp Dir: /var/lib/plexmediaserver/Library/Application Support
Config file: /etc/default/plexmediaserver

It will be so nice to reduce the checks to just the glibc version and have this work on all Linux systems. Major kudos!

Thanks for that catch :man_facepalming: on my part.
I made the change but didn’t save it DOOH

Here is a deliberate “Break it” test. Fedora 28 (systemd)

[chuck@lizum init.47]$ ./validate-sysv 
Error: Unknown username 'Chuck' used in /etc/systemd/system/plexmediaserver.service.d/override.conf.
Error: Unknown group name 'Chuck' used in /etc/systemd/system/plexmediaserver.service.d/override.conf.
Error: Directory '/home/botswanna/Application Support' in /etc/systemd/system/plexmediaserver.service.d/override.conf does not exist.
==SUBSYSTEM=="usb", ATTRS{idVendor}=="1d19", ATTRS{idProduct}=="0100",  GROUP="video" , MODE="0660" > /lib/udev/rules.d/60-tv-butler.rules
==SUBSYSTEM=="drm", GROUP="video" , MODE="0660" > /lib/udev/rules.d/60-plex-hw-transcoding.rules
==udevadm control --reload-rules
==devadm trigger
Validation tests: FAIL
Process Control:  Systemd
Plex user:        plex
Plex group:       plex
Video Group:      video
AppSupp Dir:      /var/lib/plexmediaserver/Library/Application Support
Config file:      /etc/systemd/system/plexmediaserver.service.d/override.conf
[chuck@lizum init.48]$

Development update: 03-May-2019

Just about ready to provide test packages here in this thread:

This is a fresh-install on Debian 9 with init.
As always, == indicates actions to be performed.

root@debian9-init:/home/chuck# ./postinst 
Plex Media Server installation validation and configurtion
Warning: PLEX_MEDIA_SERVER_USER is obsolete.  Please use PLEX_USER to override the default username in /etc/default/plexmediaserver.
         Retaining username:  plex
Plex now configuring for:
  Process Control:  Init
  Plex user:        plex
  Plex group:       plex
  Video Group:      video
  Metadata Dir:     /var/lib/plexmediaserver/Library/Application Support
  Config file used: /etc/default/plexmediaserver
  HW transcoding:   Not capable
 
Completing final configuration on your system.
==useradd --quiet --system --shell /bin/bash --home /var/lib/plexmediaserver --group plex plex
==mkdir -p /var/lib/plexmediaserver/Library/Application Support/Plex Media Server
==mkdir /var/lib/plexmediaserver/tmp_transcoding
==chown -R plex:plex /var/lib/plexmediaserver
==SUBSYSTEM=="usb", ATTRS{idVendor}=="1d19", ATTRS{idProduct}=="0100",  GROUP="video" , MODE="0660" > /lib/udev/rules.d/60-tv-butler.rules
==SUBSYSTEM=="drm", GROUP="video" , MODE="0660" > /lib/udev/rules.d/60-plex-hw-transcoding.rules
==udevadm control --reload-rules
==devadm trigger
===/usr/sbin/update-rc.d plexmediaserver defaults
===service plexmediaserver restart
root@debian9-init:/home/chuck#

Should this be “==udevadm trigger”?

Yep. a typo. thanks for the catch!

Is this amount of output too verbose? (all == lines will be hidden when live code)

I am performing a bit of fine tuning assist now and would like input.

Would you like PMS to create the directories specified in your configuration files or simply flag the error if they don’t exist?

I believe it should flag all errors and exit which allows you to correct typos.

Example being:

[chuck@lizum init.56]$ ./postinst-new
Plex Media Server installation validation and configurtion
Error: Directory '/home/chuck/Application Support' in /etc/systemd/system/plexmediaserver.service.d/override.conf does not exist.
System validation tests FAILED.
Please correct the problems found before installing again.
[chuck@lizum init.57]$

A new installation, with a completed and valid configuration file, looks like this and would behave as shown here

[chuck@lizum init.56]$ ./postinst-new
Plex Media Server installation validation and configurtion
Plex now configuring for:
  Process Control:  Systemd
  Plex user:        chuck
  Plex group:       chuck
  Video Group:      video
  Metadata Dir:     /home/plexdata
  Config file used: /etc/systemd/system/plexmediaserver.service.d/override.conf
  HW transcoding:   Found
 
Completing final configuration on your system.
==useradd --quiet --system --shell /bin/bash --home /var/lib/plexmediaserver --group chuck chuck
Warning:  "/home/plexdata" is not owned by "chuck".
          Please standby while this is corrected.
===chown -R chuck:chuck /home/plexdata
==SUBSYSTEM=="usb", ATTRS{idVendor}=="1d19", ATTRS{idProduct}=="0100",  GROUP="video" , MODE="0660" > /lib/udev/rules.d/60-tv-butler.rules
==SUBSYSTEM=="drm", GROUP="video" , MODE="0660" > /lib/udev/rules.d/60-plex-hw-transcoding.rules
==udevadm control --reload-rules
==udevadm trigger
===systemctl enable plexmediaserver
===systemctl restart plexmediaserver
[chuck@lizum init.57]$

Spotted an error. Fixed

Being a *nix guy, I agree with your thoughts. Have it tells us what is wrong and and we should fix it and run the check again.

To be clear,

  1. If the directories don’t exist, this is deemed a hard error.
  2. If the directories listed exist, but ownership is incorrect, fix this and continue?

Should there be “Warning” and “Error” ?

  1. Error would be “Does not exist”
  2. Warning would be “incorrect ownership” which is fixable.

If a customization file exists / parameters are not default values, correct discrepancies (Warnings) ?

These are the little tweaks I would like to get ready before first thread-test.

My plan is to have the Debian one available this week, as early as Monday, for evaluation.
It is the easiest to use for testing purposes because plexmediaserver.postinst is freestanding.

Error for both. Issues will occur if either one exists.

Thanks for the input.

  1. If a new install, but override exists, ERROR (non-default values)
  2. If a new install, create as needed
  3. Updating, print all messages, ERROR.

12-May-2019

From the input received,

  1. Warnings are now errors where appropriate
  2. Validator’s internal module now standalone for use with Startup in /etc/init.d/plexmediaserver

PMS-installation-validator.tar.gz (5.4 KB)

The new version was not running for me until I made these changes:

GetHostInfo.sh needs to be sourced in order to pass through the variables back to to the main script.
Line 13 needs to be: source ./GetHostInfo.sh

Output from the script:
Plex Media Server installation validation and configurtion
Warning: PLEX_MEDIA_SERVER_USER is obsolete. Please use PLEX_USER to override the default username in /etc/default/plexmediaserver.
Retaining username: plex
Plex now configuring based on:
Process Control: Init
Plex User: plex
Plex Group: plex
Video Group: video
Metadata Dir: /var/lib/plexmediaserver/Library/Application Support
Temp Directory: /tmp
Lang Encoding: en_US.UTF-8
Config file used: /etc/default/plexmediaserver
HW transcoding: Not found

Completing final configuration on your system.
===groupadd plex
===usermod -a -G plex plex
===usermod -a -G video plex
===SUBSYSTEM==“usb”, ATTRS{idVendor}==“1d19”, ATTRS{idProduct}==“0100”, GROUP=“video” , MODE=“0660” > /lib/udev/rules.d/60-tv-butler.rules
===SUBSYSTEM==“drm”, GROUP=“video” , MODE=“0660” > /lib/udev/rules.d/60-plex-hw-transcoding.rules
===udevadm control --reload-rules
===udevadm trigger
===/usr/sbin/update-rc.d plexmediaserver defaults
===service plexmediaserver restart

That was expected. Not everyone has . in their path

Can you catch errors correct from what used to be warnings?

Can you include the validate-sysv script to generate errors. I’d like to test more.

The source directive was needed for me to to passthrough the variables made by teh GetHostInfo.sh script. But the ./ was needed for me as well as having “.” in my path is not recommend for security. :slight_smile:

I have a complete pair for you now:

The preinst and postinst scripts in standalone form.

Plex-Installer-PrePost.tar.gz (7.1 KB)

Changes:

  1. Validator is now fully integrated into preinst
  2. Site configuration information transferred via log file (located in /tmp) to postinst which can also be used for latter debugging.
  3. Postinst executes what Preinst has found.
  4. error reports now written to system log along with begin/completion delineation.
  5. Site config used in system log
  6. Honors run/stop state

You should see the following if all is working correctly:

[chuck@lizum init.103]$ ./Postinst
Plex now configuring based on:
  Process Control:  Systemd
  Plex User:          chuck
  Plex Group:         chuck
  Video Group:        render
  Metadata Dir:       /home/plexdata
  Temp Directory:     /var/lib/plexmediaserver/tmp_transcoding
  Lang Encoding:      en_US.UTF-8
  Config file used:   /etc/systemd/system/plexmediaserver.service.d/override.conf
  HW transcoding:     Found
 
Completing final configuration on your system.
===usermod -a -G render chuck
===SUBSYSTEM=="usb", ATTRS{idVendor}=="1d19", ATTRS{idProduct}=="0100", GROUP="render" , MODE="0660" > /lib/udev/rules.d/60-tv-butler.rules
===SUBSYSTEM=="drm", GROUP="render" , MODE="0660" > /lib/udev/rules.d/60-plex-hw-transcoding.rules
===udevadm control --reload-rules
===udevadm trigger
===systemctl restart plexmediaserver
[chuck@lizum init.104]$ journalctl -xe | grep -i installer
May 21 01:59:10 lizum.hessen.lan logger[10537]: PlexMediaServer installer: Plex Media Server: ver 1.15.2.793-782228f99 - Installation starting.
May 21 01:59:10 lizum.hessen.lan logger[10540]: PlexMediaServer installer: PlexUser:
May 21 01:59:10 lizum.hessen.lan logger[10543]: PlexMediaServer installer: PlexGroup: chuck
May 21 01:59:10 lizum.hessen.lan logger[10546]: PlexMediaServer installer: VideoGroup: render
May 21 01:59:10 lizum.hessen.lan logger[10549]: PlexMediaServer installer: Metadata Dir: /home/plexdata
May 21 01:59:10 lizum.hessen.lan logger[10552]: PlexMediaServer installer: Temp Dir: /var/lib/plexmediaserver/tmp_transcoding
May 21 01:59:10 lizum.hessen.lan logger[10555]: PlexMediaServer installer: Locale: en_US.UTF-8
May 21 01:59:10 lizum.hessen.lan logger[10558]: PlexMediaServer installer: Config file used: "/etc/systemd/system/plexmediaserver.service.d/override.conf"
May 21 01:59:10 lizum.hessen.lan logger[10561]: PlexMediaServer installer: HW Transcoding: Found
May 21 01:59:10 lizum.hessen.lan logger[10573]: PlexMediaServer installer: Plex Media Server: ver: 1.15.2.793-782228f99 - installation successful.
May 21 02:27:04 lizum.hessen.lan logger[11378]: PlexMediaServer installer: Plex Media Server: ver 1.15.2.793-782228f99 - Installation starting.
May 21 02:27:04 lizum.hessen.lan logger[11382]: PlexMediaServer installer: PlexUser: chuck
May 21 02:27:04 lizum.hessen.lan logger[11385]: PlexMediaServer installer: PlexGroup: chuck
May 21 02:27:04 lizum.hessen.lan logger[11388]: PlexMediaServer installer: VideoGroup: render
May 21 02:27:04 lizum.hessen.lan logger[11391]: PlexMediaServer installer: Metadata Dir: /home/plexdata
May 21 02:27:04 lizum.hessen.lan logger[11394]: PlexMediaServer installer: Temp Dir: /var/lib/plexmediaserver/tmp_transcoding
May 21 02:27:04 lizum.hessen.lan logger[11397]: PlexMediaServer installer: Locale: en_US.UTF-8
May 21 02:27:04 lizum.hessen.lan logger[11400]: PlexMediaServer installer: Config file used: "/etc/systemd/system/plexmediaserver.service.d/override.conf"
May 21 02:27:04 lizum.hessen.lan logger[11403]: PlexMediaServer installer: HW Transcoding: Found
May 21 02:27:04 lizum.hessen.lan logger[11415]: PlexMediaServer installer: Plex Media Server: ver: 1.15.2.793-782228f99 - installation successful.
[chuck@lizum init.105]$