Skip to content

Commit

Permalink
Install systemd service via debian package
Browse files Browse the repository at this point in the history
Signed-off-by: Michael Buesch <[email protected]>
  • Loading branch information
mbuesch committed Jul 8, 2019
1 parent e71b18b commit 5c35576
Show file tree
Hide file tree
Showing 9 changed files with 46 additions and 51 deletions.
1 change: 1 addition & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ include README.md
include TODO.html
include TODO.md
include awlsim-covreport
include awlsim-server.service
include awlsim/gui/icons/pic2py
include awlsimhw_linuxcnc/awlsim.hal
include awlsimhw_pyprofibus.conf
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ The hardware modules are the glue between the Awlsim core and the real world. Th

### Misc
<pre>
. awlsim-server.service.in : Systemd unit template for awlsim-server.
. awlsim-server.service : Systemd unit for awlsim-server.
. debian/ : Debian packaging support.
. maintenance/ : Maintainer scripts.
. misc/ : Miscellaneous scripts and files.
Expand Down
22 changes: 22 additions & 0 deletions awlsim-server.service
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
[Unit]
Description=Awlsim PLC core server
After=syslog.target
After=network.target

[Service]
Type=simple
TimeoutSec=60
Restart=on-failure
RestartSec=100ms
User=root
Group=root
WorkingDirectory=/etc/awlsim
Nice=-15

ExecStart=/usr/bin/python3 /usr/bin/awlsim-server -l localhost -4 -S -w /etc/awlsim/awlsim-server.awlpro
ExecStartPost=-/usr/bin/python3 /usr/bin/awlsim-client -c localhost -r RUN

Environment=PYTHONPATH=/usr/lib/python3/dist-packages PYTHONHASHSEED=0 PYTHONOPTIMIZE=1 PYTHONDONTWRITEBYTECODE=1 AWLSIM_CYTHON=1 AWLSIM_SCHED= AWLSIM_PRIO= AWLSIM_AFFINITY= AWLSIM_MLOCK=

[Install]
WantedBy=multi-user.target
22 changes: 0 additions & 22 deletions awlsim-server.service.in

This file was deleted.

4 changes: 3 additions & 1 deletion awlsim/common/env.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,9 @@ def getMLock(cls):
"""Get AWLSIM_MLOCK.
Returns one of the MLOCK_... constants.
"""
mlockStr = cls.__getVar("MLOCK", "0").lower().strip()
mlockStr = cls.__getVar("MLOCK", "").lower().strip()
if not mlockStr:
mlockStr = cls.MLOCK_OFF
try:
mlock = int(mlockStr)
if mlock not in {cls.MLOCK_OFF,
Expand Down
3 changes: 3 additions & 0 deletions debian/awlsim-server.install
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
debian/destdir-py3-awlsim/usr/bin/awlsim-server usr/bin
debian/etc_awlsim/README.md etc/awlsim
awlsimhw_pyprofibus.conf etc/awlsim
awlsim-server.service lib/systemd/system
2 changes: 1 addition & 1 deletion debian/compat
Original file line number Diff line number Diff line change
@@ -1 +1 @@
9
10
7 changes: 7 additions & 0 deletions debian/etc_awlsim/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# /etc/awlsim

This is the Awlsim working directory.

The awlsim-server project and its configuration files are stored here.
This is the $PWD while executing awlsim-server.

34 changes: 8 additions & 26 deletions pilc/pilc-bootstrap.sh
Original file line number Diff line number Diff line change
Expand Up @@ -597,6 +597,14 @@ EOF
debian/rules ||\
die "Failed to patch rules file (pypy)"

# Update the systemd service file.
sed -i -e 's|AWLSIM_SCHED=|AWLSIM_SCHED=realtime-if-multicore|g' \
-e 's|AWLSIM_PRIO=|AWLSIM_PRIO=50|g' \
-e 's|AWLSIM_AFFINITY=|AWLSIM_AFFINITY=-1,-2,-3|g' \
-e 's|AWLSIM_MLOCK=|AWLSIM_MLOCK=1|g' \
awlsim-server.service ||\
die "Failed to patch awlsim-server.service"

# Build the packages.
debuild -uc -us -b -d || die "debuild failed"
info "Built awlsim files:"
Expand Down Expand Up @@ -675,32 +683,6 @@ EOF
do_install -T -o pi -g pi -m 644 \
examples/raspberrypi-pixtend.awlpro \
/home/pi/raspberrypi-pixtend-example.awlpro

#TODO run the testsuite

# Install configuration
do_install -d -o root -g root -m 755 /etc/awlsim
do_install -o root -g root -m 644 \
awlsimhw_pyprofibus.conf \
/etc/awlsim/

#TODO install unit via package
info "Installing awlsim service unit..."
local awlsim_prefix=/usr
local pyver=3
local site="$awlsim_prefix/lib/python$pyver/dist-packages"
cat awlsim-server.service.in |\
sed -e 's|@USER@|root|g' \
-e 's|@GROUP@|root|g' \
-e "s|@PREFIX@|$awlsim_prefix|g" \
-e 's|@WORKING_DIRECTORY@|/etc/awlsim|g' \
-e 's|@PROJECT@|/etc/awlsim/awlsim-server.awlpro|g' \
-e "s|@PYTHON@|/usr/bin/python$pyver|g" \
-e "s|@PYTHON_SITE@|$site|g" >\
/lib/systemd/system/awlsim-server.service ||\
die "Failed to create awlsim-server.service"
systemctl enable awlsim-server.service ||\
die "Failed to enable awlsim-server-service"
) || die
info "Building pyprofibus..."
(
Expand Down

0 comments on commit 5c35576

Please sign in to comment.