From Fedora Project Wiki

Testing Systemd new package scriptlets

Environment

Fedora 15 i686
systemd-units-20-1.fc15.i686
Test package: ser2net (with fixed draft scriptlets).

ser2net.service

[Unit]
Description=Proxy that allows tcp connections to serial ports
After=syslog.target network.target

[Service]
Type=forking
ExecStart=/usr/sbin/ser2net

[Install]
WantedBy=multi-user.target

Test packages

Initial package: http://spot.fedorapeople.org/ser2net-2.7-3.fc15.src.rpm
Upgrade package: http://spot.fedorapeople.org/ser2net-2.7-5.fc15.src.rpm (identical except for different Description wording in service)

Disabled by default

New install (not upgrade)

# Check that package is not installed
[spot@f15 ~]$ rpm -q ser2net
package ser2net is not installed

# Make sure there are no legacy SysV scripts for ser2net
[spot@f15 ~]$ chkconfig --list ser2net

Note: This output shows SysV services only and does not include native
      systemd services. SysV configuration data might be overriden by native
      systemd configuration.

error reading information on service ser2net: No such file or directory

# Confirm that systemctl doesn't know about ser2net
[spot@f15 ~]$ sudo systemctl -a | grep ser2net

# Install ser2net package
[spot@f15 ~]$ sudo rpm -ivh /home/spot/rpmbuild/RPMS/i686/ser2net-2.7-3.fc15.i686.rpm
Preparing...                ########################################### [100%]
   1:ser2net                ########################################### [100%]

# At this point, the .service file is in place, but no symlinks have been created.

# Accordingly, systemctl does not list ser2net as a service
[spot@f15 ~]$ sudo systemctl -a |grep ser2net
[spot@f15 ~]$ 

# Check to make sure that ser2net is not running
[spot@f15 ~]$ ps ax |grep ser2net
20232 pts/0    S+     0:00 grep --color=auto ser2net

# Manually start ser2net.service with systemctl
[spot@f15 ~]$ sudo systemctl start ser2net.service

# Confirm successful startup
[spot@f15 ~]$ systemctl -a |grep ser2net
ser2net.service           loaded active   running       Proxy that allows tcp co
[spot@f15 ~]$ ps ax |grep ser2net
20241 ?        S      0:00 /usr/sbin/ser2net
20245 pts/0    S+     0:00 grep --color=auto ser2net

# Try to connect to ser2net
[spot@f15 ~]$ telnet localhost 3011
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
this is ser2net TCP port 3011 device /dev/ttyS0
second line third line
Connection closed by foreign host.

# Manually stop ser2net service with systemctl
[spot@f15 ~]$ sudo systemctl stop ser2net.service
[spot@f15 ~]$ 

# Confirm successful shutdown
[spot@f15 ~]$ sudo systemctl -a |grep ser2net
ser2net.service           loaded inactive dead          Proxy that allows tcp co

# Try to connect to ser2net
[spot@f15 ~]$ telnet localhost 3011
Trying 127.0.0.1...
telnet: connect to address 127.0.0.1: Connection refused

# Reboot system
[spot@f15 ~]$ sudo shutdown -r now

# Listen to some music. Wait for system to reboot.

# Check to see what systemctl sees
[spot@f15 ~]$ sudo systemctl -a |grep ser2net
[spot@f15 ~]$

# Okay, it is back to not seeing it at all. Try to start it again:
[spot@f15 ~]$ sudo systemctl start ser2net.service

# Check to see if it reports as running
[spot@f15 ~]$ sudo systemctl -a |grep ser2net
ser2net.service           loaded active   running       Proxy that allows tcp co

# Confirm that it is actually running
[spot@f15 ~]$ ps ax |grep ser2net
 1256 ?        S      0:00 /usr/sbin/ser2net
 1261 pts/0    S+     0:00 grep --color=auto ser2net

# Try to connect to ser2net (expected success)
[spot@f15 ~]$ telnet localhost 3011
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
this is ser2net TCP port 3011 device /dev/ttyS0
second line third line
Connection closed by foreign host.

# Reboot once more, it should not be running afterwards.
[spot@f15 ~]$ sudo shutdown -r now

# Do a little dance. Wait for system to reboot.

# Check to see if it reports as running
[spot@f15 ~]$ sudo systemctl -a |grep ser2net
[spot@f15 ~]$ 

# Confirm that ser2net is not running
[spot@f15 ~]$ ps ax |grep ser2net
 1248 pts/0    S+     0:00 grep --color=auto ser2net

# Try to connect to ser2net (expected fail)
[spot@f15 ~]$ telnet localhost 3011
Trying 127.0.0.1...
telnet: connect to address 127.0.0.1: Connection refused

Remove package

# Remove ser2net package
[spot@f15 ~]$ sudo rpm -e ser2net

# Confirm service is no longer running
[spot@f15 ~]$ ps ax |grep ser2net
20256 pts/0    S+     0:00 grep --color=auto ser2net

# Confirm that systemctl knows the service is disabled
[spot@f15 ~]$ sudo systemctl -a |grep ser2net
ser2net.service           error  inactive dead          ser2net.service

# Attempt to connect to ser2net (expected fail)
[spot@f15 ~]$ telnet localhost 3011
Trying 127.0.0.1...
telnet: connect to address 127.0.0.1: Connection refused

# Attempt to start service
[spot@f15 ~]$ sudo systemctl start ser2net.service
Failed to issue method call: Unit ser2net.service failed to load: No such file or directory. See system logs and 'systemctl status' for details.

# Fails as expected. systemctl does not garbage collect dead entry on daemon-reload.
# ? Is there another way to force garbage collection?

# Reboot system to see what systemd reports.
[spot@f15 ~]$ sudo shutdown -r now

# Wait for system to reboot, then confirm service is not running
[spot@f15 ~]$ ps ax |grep ser2net
 1262 pts/0    S+     0:00 grep --color=auto ser2net

# Attempt to connect to ser2net (expected fail)
[spot@f15 ~]$ telnet localhost 3011
Trying 127.0.0.1...
telnet: connect to address 127.0.0.1: Connection refused

# systemctl has forgotten about the ser2net service
[spot@f15 ~]$ sudo systemctl -a |grep ser2net
[spot@f15 ~]$ 

Upgrade

# Check that package is not installed
[spot@f15 ~]$ rpm -q ser2net
package ser2net is not installed

# Make sure there are no legacy SysV scripts for ser2net
[spot@f15 ~]$ chkconfig --list ser2net

Note: This output shows SysV services only and does not include native
      systemd services. SysV configuration data might be overriden by native
      systemd configuration.

error reading information on service ser2net: No such file or directory

# Confirm that systemctl doesn't know about ser2net
[spot@f15 ~]$ sudo systemctl -a | grep ser2net
[spot@f15 ~]$

# Install first ser2net package
[spot@f15 ~]$ sudo rpm -ivh /home/spot/rpmbuild/RPMS/i686/ser2net-2.7-3.fc15.i686.rpm
Preparing...                ########################################### [100%]
   1:ser2net                ########################################### [100%]

# Manually start ser2net service
[spot@f15 ~]$ sudo systemctl start ser2net.service

# Check to see if it reports as running
[spot@f15 ~]$ sudo systemctl -a |grep ser2net
ser2net.service           loaded active   running       Proxy that allows tcp co

# Note that this description starts with "Proxy..."

# Confirm that it is actually running
[spot@f15 ~]$ ps ax |grep ser2net
 1294 ?        S      0:00 /usr/sbin/ser2net
 1299 pts/0    S+     0:00 grep --color=auto ser2net

# Note that the PID of the process is 1294

# Try to connect to ser2net (expected success)
[spot@f15 ~]$ telnet localhost 3011
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
this is ser2net TCP port 3011 device /dev/ttyS0
second line third line
Connection closed by foreign host.

# Now, update to newer package
# NOTE: Newer package has a different description in ser2net.service to show that systemd is operating on the new instance.
# This package is too simple for anything more complicated.

# Upgrade package
[spot@f15 ~]$ sudo rpm -Uvh /home/spot/rpmbuild/RPMS/i686/ser2net-2.7-5.fc15.i686.rpm
Preparing...                ########################################### [100%]
   1:ser2net                ########################################### [100%]

# Check to see if it reports as running
[spot@f15 ~]$ sudo systemctl status ser2net.service
ser2net.service - New proxy that allows tcp connections to serial ports
	  Loaded: loaded (/lib/systemd/system/ser2net.service)
	  Active: active (running)
	 Process: 1332 ExecStart=/usr/sbin/ser2net (code=exited, status=0/SUCCESS)
	Main PID: 1334 (ser2net)
	  CGroup: name=systemd:/system/ser2net.service
		  └ 1334 /usr/sbin/ser2net

# It lives! (In earlier testing, it failed, but it seems not to be reproducible.)

Enabled by default

New install (not upgrade)

# Check that package is not installed
[spot@f15 ~]$ rpm -q ser2net
package ser2net is not installed

# Make sure there are no legacy SysV scripts for ser2net
[spot@f15 ~]$ chkconfig --list ser2net

Note: This output shows SysV services only and does not include native
      systemd services. SysV configuration data might be overriden by native
      systemd configuration.

error reading information on service ser2net: No such file or directory

# Confirm that systemctl doesn't know about ser2net
[spot@f15 ~]$ sudo systemctl -a | grep ser2net

# Check systemctl status
[spot@f15 ~]$ sudo systemctl status ser2net.service
ser2net.service
	  Loaded: error
	  Active: inactive (dead)
# Note that it says this about any non-present service

# Install ser2net package
[spot@f15 ~]$ sudo rpm -ivh /home/spot/rpmbuild/RPMS/i686/ser2net-2.7-6.fc15.i686.rpm
Preparing...                ########################################### [100%]
   1:ser2net                ########################################### [100%]

# At this point, the .service file is in place, and it has been enabled, so there should be symlinks.

# systemctl -a sees it
[spot@f15 ~]$ sudo systemctl -a |grep ser2net
ser2net.service           loaded inactive dead          Proxy that allows tcp connections to serial ports

# Check systemd status
[spot@f15 ~]$ sudo systemctl status ser2net.service
ser2net.service - Proxy that allows tcp connections to serial ports
	  Loaded: loaded (/lib/systemd/system/ser2net.service)
	  Active: inactive (dead)
	  CGroup: name=systemd:/system/ser2net.service

# Check to make sure that ser2net is not running
[spot@f15 ~]$ ps ax |grep ser2net
 1281 pts/0    S+     0:00 grep --color=auto ser2net

# Manually start ser2net.service with systemctl
[spot@f15 ~]$ sudo systemctl start ser2net.service

# Confirm successful startup
[spot@f15 ~]$ systemctl -a |grep ser2net
ser2net.service           loaded active   running       Proxy that allows tcp connections to serial ports

[spot@f15 ~]$ sudo systemctl status ser2net.service
ser2net.service - Proxy that allows tcp connections to serial ports
	  Loaded: loaded (/lib/systemd/system/ser2net.service)
	  Active: active (running)
	 Process: 1285 ExecStart=/usr/sbin/ser2net (code=exited, status=0/SUCCESS)
	Main PID: 1287 (ser2net)
	  CGroup: name=systemd:/system/ser2net.service
		  └ 1287 /usr/sbin/ser2net

[spot@f15 ~]$ ps ax |grep ser2net
 1287 ?        S      0:00 /usr/sbin/ser2net
 1295 pts/0    S+     0:00 grep --color=auto ser2net

# Try to connect to ser2net
[spot@f15 ~]$ telnet localhost 3011
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
this is ser2net TCP port 3011 device /dev/ttyS0
second line third line
Connection closed by foreign host.

# Manually stop ser2net service with systemctl
[spot@f15 ~]$ sudo systemctl stop ser2net.service
[spot@f15 ~]$ 

# Confirm successful shutdown
[spot@f15 ~]$ sudo systemctl -a |grep ser2net
ser2net.service           loaded inactive dead          Proxy that allows tcp connections to serial ports

[spot@f15 ~]$ sudo systemctl status ser2net.service
ser2net.service - Proxy that allows tcp connections to serial ports
	  Loaded: loaded (/lib/systemd/system/ser2net.service)
	  Active: inactive (dead)
	 Process: 1285 ExecStart=/usr/sbin/ser2net (code=exited, status=0/SUCCESS)
	Main PID: 1287 (code=killed, signal=TERM)
	  CGroup: name=systemd:/system/ser2net.service

# Try to connect to ser2net
[spot@f15 ~]$ telnet localhost 3011
Trying 127.0.0.1...
telnet: connect to address 127.0.0.1: Connection refused

# Reboot system
[spot@f15 ~]$ sudo shutdown -r now

# Listen to some music. Wait for system to reboot.

# Check to see what systemctl sees
[spot@f15 ~]$ sudo systemctl -a |grep ser2net
ser2net.service           loaded active   running       Proxy that allows tcp connections to serial ports

[spot@f15 ~]$ sudo systemctl status ser2net.service
ser2net.service - Proxy that allows tcp connections to serial ports
	  Loaded: loaded (/lib/systemd/system/ser2net.service)
	  Active: active (running) since Mon, 04 Apr 2011 18:17:06 -0400; 30s ago
	 Process: 690 ExecStart=/usr/sbin/ser2net (code=exited, status=0/SUCCESS)
	Main PID: 696 (ser2net)
	  CGroup: name=systemd:/system/ser2net.service
		  └ 696 /usr/sbin/ser2net

# Okay, the symlinks survived the reboot and its running!

# Confirm that it is actually running
[spot@f15 ~]$ ps ax |grep ser2net
  696 ?        S      0:00 /usr/sbin/ser2net
 1273 pts/0    S+     0:00 grep --color=auto ser2net

# Try to connect to ser2net (expected success)
[spot@f15 ~]$ telnet localhost 3011
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
this is ser2net TCP port 3011 device /dev/ttyS0
second line third line
Connection closed by foreign host.

Remove package

# Remove ser2net package
[spot@f15 ~]$ sudo rpm -e ser2net

# Confirm service is no longer running
[spot@f15 ~]$ ps ax |grep ser2net
 1286 pts/0    S+     0:00 grep --color=auto ser2net

# Confirm that systemctl knows the service is disabled
[spot@f15 ~]$ sudo systemctl -a |grep ser2net
ser2net.service           error  inactive dead          ser2net.service

[spot@f15 ~]$ sudo systemctl status ser2net.service
ser2net.service
	  Loaded: error
	  Active: inactive (dead) since Mon, 04 Apr 2011 18:18:54 -0400; 19s ago
	Main PID: 696 (code=killed, signal=TERM)

# Attempt to connect to ser2net (expected fail)
[spot@f15 ~]$ telnet localhost 3011
Trying 127.0.0.1...
telnet: connect to address 127.0.0.1: Connection refused

# Attempt to start service
[spot@f15 ~]$ sudo systemctl start ser2net.service
Failed to issue method call: Unit ser2net.service failed to load: No such file or directory. See system logs and 'systemctl status' for details.

# Fails as expected. systemctl does not garbage collect dead entry on daemon-reload.

# Reboot system to see what systemd reports.
[spot@f15 ~]$ sudo shutdown -r now

# Wait for system to reboot, then confirm service is not running
[spot@f15 ~]$ ps ax |grep ser2net
 1261 pts/0    S+     0:00 grep --color=auto ser2net

# Attempt to connect to ser2net (expected fail)
[spot@f15 ~]$ telnet localhost 3011
Trying 127.0.0.1...
telnet: connect to address 127.0.0.1: Connection refused

# systemctl has forgotten about the ser2net service
[spot@f15 ~]$ sudo systemctl -a |grep ser2net
[spot@f15 ~]$ 

[spot@f15 ~]$ sudo systemctl status ser2net.service
ser2net.service
	  Loaded: error
	  Active: inactive (dead)

Upgrade

# Check that package is not installed
[spot@f15 ~]$ rpm -q ser2net
package ser2net is not installed

# Make sure there are no legacy SysV scripts for ser2net
[spot@f15 ~]$ chkconfig --list ser2net

Note: This output shows SysV services only and does not include native
      systemd services. SysV configuration data might be overriden by native
      systemd configuration.

error reading information on service ser2net: No such file or directory

# Confirm that systemctl doesn't know about ser2net
[spot@f15 ~]$ sudo systemctl -a | grep ser2net
[spot@f15 ~]$

[spot@f15 ~]$ sudo systemctl status ser2net.service
ser2net.service
	  Loaded: error
	  Active: inactive (dead)

# Install first ser2net package
[spot@f15 ~]$ sudo rpm -ivh /home/spot/rpmbuild/RPMS/i686/ser2net-2.7-6.fc15.i686.rpm
Preparing...                ########################################### [100%]
   1:ser2net                ########################################### [100%]

# Manually start ser2net service (a reboot would also work here, since it is enabled by default)
[spot@f15 ~]$ sudo systemctl start ser2net.service

# Check to see if it reports as running
[spot@f15 ~]$ sudo systemctl -a |grep ser2net
ser2net.service           loaded active   running       Proxy that allows tcp connections to serial ports

[spot@f15 ~]$ sudo systemctl status ser2net.service
ser2net.service - Proxy that allows tcp connections to serial ports
	  Loaded: loaded (/lib/systemd/system/ser2net.service)
	  Active: active (running)
	 Process: 1351 ExecStart=/usr/sbin/ser2net (code=exited, status=0/SUCCESS)
	Main PID: 1353 (ser2net)
	  CGroup: name=systemd:/system/ser2net.service
		  └ 1353 /usr/sbin/ser2net

# Note that this description starts with "Proxy..."

# Confirm that it is actually running
[spot@f15 ~]$ ps ax |grep ser2net
 1353 ?        S      0:00 /usr/sbin/ser2net
 1360 pts/0    S+     0:00 grep --color=auto ser2net

# Note that the PID of the process is 1353

# Try to connect to ser2net (expected success)
[spot@f15 ~]$ telnet localhost 3011
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
this is ser2net TCP port 3011 device /dev/ttyS0
second line third line
Connection closed by foreign host.

# Now, update to newer package
# NOTE: Newer package has a different description in ser2net.service to show that systemd is operating on the new instance.
# This package is too simple for anything more complicated.

# Upgrade package
[spot@f15 ~]$ sudo rpm -Uvh /home/spot/rpmbuild/RPMS/i686/ser2net-2.7-7.fc15.i686.rpm
Preparing...                ########################################### [100%]
   1:ser2net                ########################################### [100%]

# Check to see if it reports as running
[spot@f15 ~]$ sudo systemctl status ser2net.service
ser2net.service - New proxy that allows tcp connections to serial ports
	  Loaded: loaded (/lib/systemd/system/ser2net.service)
	  Active: active (running)
	 Process: 1379 ExecStart=/usr/sbin/ser2net (code=exited, status=0/SUCCESS)
	Main PID: 1381 (ser2net)
	  CGroup: name=systemd:/system/ser2net.service
		  └ 1381 /usr/sbin/ser2net

# It lives! Note the new description indicating the upgrade.