1

Due to conflicting and constantly changing permissions on mounted drives (which cannot easily be solved due to the development structure of programs), there is a script that must be run with root permissions.

This can be done with sudo /usr/serverm1/lsintd and provides good results. However, we wish to run this script automatically on startup.

Running the script under our main user on startup results in a core dump due to insufficient permissions. Therefore, we figured we could set it in crontab as @reboot /usr/serverm1/lsintd (as suggested here, however this runs it with settings and config from root (which is non existent).

TLDR: How can we run the script exactly as it would run with the command sudo /usr/serverm1/lsintd on startup?

I also tried applying chmod u+x to the binary, however this still resulted in a core dump as if run with regular perms (idea taken from let a user run a script with root permissions).

Side note: I admit this is somewhat an XY problem, however due to the slow and poorly organized development structure of some of the other services on our server, we have no way of solving the root issues and must instead workaround with this.

Mark Deven
  • 113
  • 5

1 Answers1

2

One way would be to create a systemd unit.
All the possible options you can find here: www.freedesktop.org/.../systemd.unit.html but I am going to present simple example:

1.Lets create a bash script which will write the date and time of each system bootup to the file: /root/file
Only root user has permissions to write and edit files in /root directory.
I am going to switch user to the root with sudo su -
Lets create a script /root/timelog.sh and make it executable chmod +x /root/timelog.sh

   #!/bin/bash

   if ! [ /root/file ]; then touch /root/file; fi 
   echo $(date) >> /root/file

2.Now we need the System Unit file: /etc/systemd/system/timelog.service

[Unit]
Description=timelog.service

[Service]
Type=oneshot
ExecStart=/root/timelog.sh

[Install]
WantedBy=multi-user.target

3.Last task is to make sure it will start with the system:

systemctl enable timelog
RomanK
  • 161
  • 5
  • Genius! I never considered making it into a service. Of course! Thank you Romank! – Mark Deven Dec 17 '20 at 13:33
  • @MarkDeven If this answered your question, would you select it as an answer? Thanks. – RomanK Dec 17 '20 at 17:21
  • Yes @RomanK, sorry for the delay in doing so. Christmas season and all. – Mark Deven Dec 26 '20 at 23:33
  • the software is giving an error since the script requires an X display. Any ideas how to make it use the default :0 display? I tried `Environment=DISPLAY:0.0`. – Mark Deven Dec 26 '20 at 23:52
  • @MarkDeven This question will fork significantly from the original question but check if [THIS](https://superuser.com/questions/759759/writing-a-service-that-depends-on-xorg) answers it. – RomanK Dec 27 '20 at 05:23
  • It continued giving me issues but I was able to convince the development team to run it on a webserver since the gui used html anyways. Thanks for your help! – Mark Deven Dec 28 '20 at 17:06