profile
viewpoint

Ask questionsDocumentation Addition for Creating a service

First - VM is amazing so far. Thank you.

I'd love to see you add documentation on running VM as a service in systemd. Here's what I did to make it work on CentOS 7, but this should work on any systemd OS.

Create a directory to hold the PID file:

mkdir /run/victoriametrics

Create /etc/systemd/system/victoriametrics.service. Copy and paste the below into this new file, adjusting the ExecStart line as needed.

[Unit]
Description=VictoriaMetrics
After=network.target

[Service]
Type=simple
StartLimitBurst=5
StartLimitInterval=0
Restart=on-failure
RestartSec=1
PIDFile=/run/victoriametrics/victoriametrics.pid
ExecStart=/usr/local/bin/victoriametrics -storageDataPath /data -retentionPeriod 6
ExecStop=/bin/kill -s SIGTERM $MAINPID

[Install]
WantedBy=multi-user.target

Set the file limits for the service:
mkdir /etc/systemd/system/victoriametrics.service.d
In this folder create a file ulimit.conf with the following:

[Service]
LimitNOFILE=32000
LimitNPROC=32000

Enable the service to start automatically:

systemctl enable victoriametrics

Start the service:

systemctl start victoriametrics
VictoriaMetrics/VictoriaMetrics

Answer questions kmansoft

@patsevanton I'm thinking of adding new code to the makefiles / build scripts.

It would dynamically generate the .spec file with the right paths (which do vary by version and by actual built path) and then use rpmbuild -bb --target to package.

Here is some code from my own build scripts:

            mkdir -p "${TEMPDIR_RPM}/${WHAT}/SPECS"
            cat > "${TEMPDIR_RPM}/${WHAT}/SPECS/clearview-${WHAT}.spec" <<EOF
Summary: Clearview agent
Name: clearview-agent
Version: ${VERSION}
Release: ${BUILD}
License: n/a
URL: https://clearview.rocks
Group: System
Packager: Kostya Vasilyev <kmansoft@gmail.com>
Requires: libpthread
Requires: libc

%description
Clearview is an easy to install, easy to use performance monitoring for
your Linux web servers. Inspired by Linode Longview.

%files
%attr(0744, root, root) /usr/sbin/*
%attr(0644, root, root) /lib/systemd/system/*

%prep
echo "BUILDROOT = \$RPM_BUILD_ROOT"

mkdir -p \$RPM_BUILD_ROOT/usr/sbin/
mkdir -p \$RPM_BUILD_ROOT/lib/systemd/system/

cp ${PWD}/package/temp-deb/agent/usr/sbin/${OUT_EXE} \$RPM_BUILD_ROOT/usr/sbin/
cp ${PWD}/package/agent/clearview-agent.service \$RPM_BUILD_ROOT/lib/systemd/system/
EOF

            cat "${TEMPDIR_RPM}/${WHAT}/SPECS/clearview-${WHAT}.spec"

            rpmbuild -bb --target "${RPM_ARCH}" \
                "${TEMPDIR_RPM}/${WHAT}/SPECS/clearview-${WHAT}.spec"

            cp "${HOME}/rpmbuild/RPMS/${RPM_ARCH}/${OUT_RPM}" "${PACKDIR}/${OUT_RPM}"
useful!
source:https://uonfu.com/
answerer
Kostya Vasilyev kmansoft Russia https://kman.mobi Writing code since early 1990-ies. Android since 2010. Go since 2016.
Github User Rank List