Could not edit systemd service file - linux

Need to edit following entries:
[Service]
Type=notify
# the default is not to use systemd for cgroups because the delegate issues still
# exists and systemd currently does not support the cgroup feature set required
# for containers run by docker
ExecStart=/usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock
ExecReload=/bin/kill -s HUP $MAINPID
TimeoutSec=0
RestartSec=2
Restart=always
in /lib/systemd/system/docker.service file
$ sudo -E systemctl edit docker.service
[Service]
ExecStart=
ExecStart=/usr/bin/dockerd -H fd:// -H tcp://0.0.0.0:2376 --containerd=/run/containerd/containerd.sock
did not update the service file after restart(sudo systemctl restart docker.service)
Edit
On AWS EC2, below is the issue:
$ nano /etc/systemd/system/docker.service.d/override.conf
$ sudo systemctl daemon-reload
$ sudo systemctl restart docker
/lib/systemd/system/docker.service still shows unmodified
1) What is the recommended approach to edit service file(docker.service)?
2) Why /lib/systemd/system/docker.service cannot be edited directly?

You need to create a systemd drop-in file for docker.service.
Create /etc/systemd/system/docker.service.d/override.conf file with contents
[Service]
ExecStart=
ExecStart=/usr/bin/dockerd -H fd:// -H tcp://0.0.0.0:2376 --containerd=/run/containerd/containerd.sock
Reload systemd unit files.
systemctl daemon-reload
NOTE: Reloading systemctl daemon is required after editing any systemd unit file that's as per systemd design. For more info check this.
Restart docker daemon.
systemctl restart docker
You need to restart docker daemon to pick up the latest updated systemd unit file.
For more info check this.

Related

How to start Greeplum on boot - linux

Trying to start Greenplum on system startup. Please find systemd service file content below.
[Unit]
Description=Greenplum daemon
[Service]
EnvironmentFile=/etc/environment
EnvironmentFile=/etc/default/greenplum
User=gpadmin
Group=gpadmin
Type=simple
ExecStartPre=/bin/bash -c "source /opt/greenplum-db-6-6.11.2/greenplum_path.sh"
#ExecStartPre=/opt/greenplum-db-6-6.11.2/greenplum_path.sh
ExecStart=/opt/greenplum-db-6-6.11.2/bin/gpstart -a -l /home/gpadmin/gpAdminLogs -d /greenplum/master/gpseg-1
Restart=on-failure
RestartSec=5s
PrivateTmp=true
[Install]
WantedBy=multi-user.target
All required environment variables are loaded and required path is sourced still not able to start service. Getting "ImportError: No module named gppylib.mainUtils". After machine is started if I run start command(/opt/greenplum-db-6-6.11.2/bin/gpstart -a -l /home/gpadmin/gpAdminLogs -d /greenplum/master/gpseg-1) it is working fine. I am not able to understand what is going wrong. My current setup has two hosts(master and segment host). I have kept segment node up and trying on master. Any help is much appreciated.
Sourcing greenplum_path.sh in ExecStartPre won't work because the environment isn't preserved between ExecStartPre and ExecStart. I would try something like
ExecStart=/bin/bash -c "source /opt/greenplum-db-6-6.11.2/greenplum_path.sh; gpstart -a -l /home/gpadmin/gpAdminLogs -d /greenplum/master/gpseg-1.

NodeJS forever after #reboot

I am working with React and need my web page to be alive after reboot.
So I need forever after crontab.
What I have tried.
crontab -e
#reboot ~/reboot.sh
#reboot sudo service nginx restart
#!/bin/bash
cd ~/lacirolnikdev && sudo ~/.nvm/versions/node/v14.13.1/bin/forever start -c "/.nvm/versions/node/v14.13.1/bin/npm start" .
cd ~/coinwork && sudo ~/.nvm/versions/node/v14.13.1/bin/forever start -c "/.nvm/versions/node/v14.13.1/bin/npm start" .
I tried absolute paths, sudo and moving to directories.
Commands works fine besides crontab.
Thank you Laci
A better way to start processes after boot would be a systemd unit file, the de-facto standard init daemon on most distributions. systemd takes care of starting your application, is capable of monitoring and restarting it on crashes.
Have a look at the documentation for unit files here:
https://www.freedesktop.org/software/systemd/man/systemd.unit.html
This is an example for nginx:
/lib/systemd/system/nginx.service
[Unit]
Description=A high performance web server and a reverse proxy server
Documentation=man:nginx(8)
After=network.target
[Service]
Type=forking
PIDFile=/run/nginx.pid
ExecStartPre=/usr/sbin/nginx -t -q -g 'daemon on; master_process on;'
ExecStart=/usr/sbin/nginx -g 'daemon on; master_process on;'
ExecReload=/usr/sbin/nginx -g 'daemon on; master_process on;' -s reload
ExecStop=-/sbin/start-stop-daemon --quiet --stop --retry QUIT/5 --pidfile /run/nginx.pid
TimeoutStopSec=5
KillMode=mixed
[Install]
WantedBy=multi-user.target

Systemd ExecStart with arguments

I have process, that i run in this way :
sudo RADIODEV=/dev/spidev0.0 /opt/basicstation/build-rpi-std/bin/station -d -h /opt/basicstation/build-rpi-std/bin
I would like to lunch it on raspberry boot with systemctl like that :
[Unit]
Description=Basic station secure websocket
Wants=network-online.target
After=network-online.target
[Service]
User=root
Group=root
ExecStart= RADIODEV=/dev/spidev0.0 /opt/basicstation/build-rpi-std/bin/station -d -h /opt/basicstation/build-rpi-std/bin
[Install]
WantedBy=multi-user.target
Alias=basic_station.service
So i want to know how put the argument
RADIODEV=/dev/spidev0.0
-d
-h /opt/basicstation/build-rpi-std/bin
because wheni just put :
ExecStart= RADIODEV=/dev/spidev0.0 /opt/basicstation/build-rpi-std/bin/station -d -h /opt/basicstation/build-rpi-std/bin
That's not work
I already check some issue like :
issue systemd
But i can't reproduce what they propose.

Resolve systemd alias (service name)

Systemd supports aliases. For example "httpd.service"
ls -l /etc/systemd/system/httpd.service
/etc/systemd/system/httpd.service -> /usr/lib/systemd/system/apache2.service
Content of this file:
[Unit]
Description=The Apache Webserver
...
[Install]
WantedBy=multi-user.target
Alias=httpd.service apache.service
I would like to resolve the alias in a script.
Example:
If the input is "httpd.service", then the output should be "apache2.service"
I can use shell or python for this script.
How to do this the systemd-way?
Reading the symlink might work, but I guess there is a more official way to resolve the alias.
You should ask for the Id property of the aliased service
> systemctl show -p Id --value httpd.service
apache2.service
You can also query the Names property
> systemctl show -p Names --value httpd.service
httpd.service apache2.service

How can I run this script automatically on startup

I have a game server on my VPS, but i have a strong problem. When it reboots(for technical reasons or something) the game server doesn't start automatically. I use this script, which is located in /home/steam/csgo-ds:
#!/bin/sh
ln -s /home/steam/csgo-ds/csgo/*.dem /var/www/html/
ln -s /var/run/mysqld/mysqld.sock /tmp/mysql.sock
cd /home/steam/csgo-ds
chmod 777 * -R
screen -S "CS:GO Server" ./srcds_run -game csgo -usercon +game_type 0 +game_mode 0 -tickrate 64 -maxplayers 24 -maxplayers_override 24 +ip 188.116.46.148 -port 27015 +sv_setsteamaccount "XXXXX" -exec server.cfg +tv_enable 1 +tv_maxclients 0 +tv_port 27020 +tv_advertise_watchable 0 +map jb_dust2_final2
I have tried adding it to crontab, startup files and a lot more and nothing worked.
Operating system on the VPS is Ubuntu Server 64-bit 14.04 upgraded to 16.04
Ubuntu 16.04 uses systemd as init system, Follow these steps:
chmod 744 /path/to/script
Now create a unit file:
vim /etc/systemd/system/csgo.service
[Unit]
Wants=network-online.target
After=network-online.target
[Service]
ExecStart=/path/to/script
[Install]
WantedBy=default.target
Set permissions:
chmod 664 /etc/systemd/system/csgo.service
Reload and enable the service:
systemctl daemon-reload
systemctl enable csgo.service
Now reboot and test it out.
there are different ways of doing this , the easiest way is to put 5 line of your code in :
/etc/rc.local
it will be executed automatically on each os boot
you should put your lines of code under this line:
exit 0

Resources