How to start Greeplum on boot - linux - 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.

Related

ubuntu 18 custom service does not load

ubuntu 18
I have created a custom service at /etc/systemd/system/mycustomservice.service
and enable it : sudo systemctl enable /etc/systemd/system/mycustomservice.service
but the service does not load at start up, the content is:
[Unit]
After=mysql.service
[Service]
ExecStart=/home/myuser/runupdate.sh
[Install]
WantedBy=default.target
I try to execute the file /home/myuser/runupdate.sh without any issue
the permission of
/home/myuser/runupdate.sh is -rwxr--r--
/etc/systemd/system/mycustomservice.service is -rw-rw-r--
Please advise, thank you!
Systemd will need to know how to execute the script and what shell to use, hence there are two options Add:
#!/bin/bash
or
#!/bin/sh
to the top line of the script depending on the shell you are using. Alternatively, you can use:
ExecStart=/bin/bash -c /home/myuser/runupdate.sh

start .sh in .bash with a service or start the .sh file within the service

im currently setting up a minecraft server on my root but struggle with the startup on boot.
Before having this in startup i was starting the server with a .sh file which i had to start manually.
the .sh file also created a screen where i was able to check the console
.sh file:
screen -AmdS minecraft java -Xms4096M -Xmx4096M -jar /home/minecraft/server/server.jar nogui
But then i tried to have the server in startup of the root server so it starts automaticly
i created a service with a .bash file which starts the server with no problem on startup but without the screen option for the console
Service:
[Unit]
Description=Start Minecraft
After=network.target
[Service]
Type=simple
ExecStart=/root/start_minecraft_server.bash
TimeoutStartSec=0
[Install]
WantedBy=default.target
Bash:
#!/bin/bash
#Standard Minecraft
cd /home/minecraft/server/
exec java -Xmx4096M -Xms1024M -jar server.jar nogui
now i want to ask if you know any easy option for adding the screen option to the service or bash file?
Try this and make sure your screen is actually in /usr/bin/ by which screen
[Unit]
Description=Start Minecraft
After=network.target
[Service]
user=minecraft
Type=simple
ExecStart=/usr/bin/screen -S Minecraft_Server -d -m sh /root/start_minecraft_server.bash
TimeoutStartSec=0
[Install]
WantedBy=default.target
But you should also alter your startcript itself:
#!/bin/bash
#Standard Minecraft
cd /home/minecraft/server/
while true; do
exec java -Xmx4096M -Xms1024M -jar server.jar nogui
done;
And just for security reasons, you should never run your mc server as root - create another user for it with limited permissions and add something like user=minecraft below the SERVICE tag in the init startscript

Sudoer does not use the same environnement for python3

I have a python script1 which i use as a library which i import to my main script.
before using it i checked that it was working fine, i noticed that when i run this script1 with "sudo" then it doesn't find one of library he use.
sudo python3 -W ignore detector.py -d datasets -c MLP predict
By searching a little, I found that "sudo" did not use the same environment as my user account, and that it was necessary to add the argument "-E", and it works well.
sudo -E python3 -W ignore detector.py -d datasets -c MLP predict
the script1 also works well when I run it without "sudo"
python3 -W ignore detector.py -d datasets -c MLP predict
Then i import my script1 into my main script "import script1" and call one of the functions from script1 but get the same error from script1.
the problem is that my main script is managed by systemctl with service with root user and i can't use "-E" in ExecStart:
[Unit]
Description= Uplink manager with IA supervison of LORAWAN data
Wants=network-online.target
After=network-online.target
[Service]
ExecStart= /usr/bin/python3 -u/opt/flask_server/uplink_server/uplink_manager.py
Restart=on-failure
[Install]
WantedBy=multi-user.target
Alias=uplink_manager.service
Can you help me ? Thanks.
The library that was missing, was in fact present in the root environment, but the version of the library was not right.

How do I run a python script on boot on Google Coral?

I have written a simple test code in python to toggle two of the I/O pins on and off every few seconds. I would like to be able to run this code whenever the board powers on so that I don't need to bring a keyboard, mouse, and monitor everywhere I want to run the simple test. How do I do this on Mendel OS on a google coral?
On Mendel OS, your systemd service should look like this:
myservice.service:
[Unit]
Description=Example systemd service.
After=weston.target
[Service]
Environment=DISPLAY=:0
PAMName=login
Type=simple
User=mendel
WorkingDirectory=/home/mendel
ExecStart=/bin/bash /usr/bin/test_service.sh
Restart=always
[Install]
WantedBy=multi-user.target
Regarding how to create a service and how to deploy it, you can follow this article.
Change 'ExecStart' line with your python file that you want to get executed.
Using crontab has been working consistently for me, you may want to add a time.sleep in the beginning of your python file
edit crontab
crontab -e
select nano editor
add
#reboot sudo python3 <path_to_your_script>
I had same issue.
This might be useful for you.
https://askubuntu.com/questions/919054/how-do-i-run-a-single-command-at-startup-using-systemd
I was able to add new service into systemd, but the script didn't run properly, but perhaps this won't be your problem.
I copied the instruction from the Nam Vu's note in Gist. This is like the details of Nanoj's answer above.
This is an example of starting a systemd object detection service on boot on the Coral Dev Board.
create a file called "detects.service" with similar with the following contents:
[Unit]
Description=systemd object detection service
After=weston.target
[Service]
PAMName=login
Type=simple
User=mendel
WorkingDirectory=/home/mendel
Environment=DISPLAY=:0
ExecStart=/bin/bash /usr/bin/detect_service.sh
Restart=always
[Install]
WantedBy=multi-user.target
Copy the file to "/lib/systemd/system/detects.service"
$ sudo cp -i detects.service /lib/systemd/system
Create a file called "detect_service.sh" with similar to following content:
edgetpu_detect --model fullpath/mobilenet_ssd_v2_coco_quant_postprocess_edgetpu.tflite --label fullpath/coco_labels.txt
or
python detect.py --model fullpath/mobilenet_ssd_v2_coco_quant_postprocess_edgetpu.tflite --label fullpath/coco_labels.txt
Make it executable and copy it to "/usr/bin":
$ sudo chmod u+x detect_service.sh
$ sudo cp -i detect_service.sh /usr/bin
enable the service with the systemctl command:
$ sudo systemctl enable detects.service
This would be useful when your python code called the Google "gstreamer code" example. The gstreamer code not able to be executed with sudo command, so you may not able to use with "sudo crontab -e" method for example Danny Dasilva's answer above.

systemd-path service not working

I have added systemd service to monitor a path. But it is not working. I touched a .txt file under /tmp/test/. But it is not kicking in my service. I cant see "/tmp/testlog.txt" getting generated. Is there anything wrong in my service?
myservice.path
[Unit]
Description=Path Exists
[Path]
PathExistsGlob=/tmp/test/*.txt
PathChanged=/tmp/test/
[Install]
WantedBy=multi-user.target
myservice.service
[Unit]
Description=Test
[Service]
ExecStartPre=/bin/sh -c 'mkdir /tmp/test && sleep 60'
ExecStart=/bin/sh -c 'echo "Test Success" >> /tmp/testlog.txt & '
[Install]
WantedBy=multi-user.target
tmp dir:
# ls /tmp/test/
ab.txt
#
What could be the reason for the failure?
That was a timing issue. I added dependency and made this service to start as the very last one. That one solved the issue.

Resources