C program won't start on boot

This forum is for discussion about general software issues.

C program won't start on boot

Postby XploD » Sun May 17, 2015 11:05 am

I wrote a program in C to control LCD display and buttons, compiled it and it works. But I can't manage to get it to start automatically at boot. So, after compiling, I moved my program to /usr/bin and did:

$this->bbcode_second_pass_code('', 'chmod a+x board')

Then I created a script called board.service in /usr/lib/systemd/system/ with following content:

$this->bbcode_second_pass_code('', '
[Unit]
Description=playback_buttons

[Service]
ExecStart=/usr/bin/board

[Install]
WantedBy=multi-user.target')

And executed

$this->bbcode_second_pass_code('', 'systemctl enable board.service')

But nothing, it just doesn't work. Then I tried in different folder, /etc/systemd/system, and called it board2.service and again:

$this->bbcode_second_pass_code('', 'systemctl enable board2.service')

Still nothing. Then I tried to create a shell script with following content:

$this->bbcode_second_pass_code('', '
#!/bin/sh
/usr/bin/board
')

And then in board.service and board2.service I replaced ExecStart=/usr/bin/board with ExecStart=/usr/bin/board.sh. I tried to chmod board.sh also but no progress. But it works when I execute

$this->bbcode_second_pass_code('', '/usr/bin/board.sh')

Before this, I had a program for controlling buttons in a .sh script and I made it start on boot on this way successfully, but with this C program, it just doesn't work. What am I doing wrong?
XploD
 
Posts: 5
Joined: Wed May 13, 2015 9:24 am

Re: C program won't start on boot

Postby moonman » Sun May 17, 2015 7:44 pm

What is the status of the service? Also, you only mentioned that you enabled the service, did you actually start it?

Look into RemainAfterExit=yes option (might be called something else, just going memory)
Pogoplug V4 | GoFlex Home | Raspberry Pi 4 4GB | CuBox-i4 Pro | ClearFog | BeagleBone Black | Odroid U2 | Odroid C1 | Odroid XU4
-----------------------------------------------------------------------------------------------------------------------
[armv5] Updated U-Boot | [armv5] NAND Rescue System
moonman
Developer
 
Posts: 3388
Joined: Sat Jan 15, 2011 3:36 am

Re: C program won't start on boot

Postby XploD » Mon May 18, 2015 7:31 pm

I forgot to start it but I thought there's no need since once enabled, it should start on boot. I tried to start it now with

$this->bbcode_second_pass_code('', 'systemctl start board.service')

And it works! But it's still not starting on boot so I have to execute this command everytime I start my Pi. But this is still better than before because now, after I start the service, I can close SSH. And yes, I executed systemctl enable board.service

On which exit do you mean? My program has a while(1){} loop so it will never end, the only way to end it is to kill it manually.
XploD
 
Posts: 5
Joined: Wed May 13, 2015 9:24 am

Re: C program won't start on boot

Postby moonman » Mon May 18, 2015 8:46 pm

You never mentioned you did a reboot. Something is not up in time when the service starts. Check journal and service status (systemctl status <service>). You may need to add After=<some target or service>. Do you have a DE? If you do then maybe you need to change wanted by to graphical if your program requires any graphical front end.
Pogoplug V4 | GoFlex Home | Raspberry Pi 4 4GB | CuBox-i4 Pro | ClearFog | BeagleBone Black | Odroid U2 | Odroid C1 | Odroid XU4
-----------------------------------------------------------------------------------------------------------------------
[armv5] Updated U-Boot | [armv5] NAND Rescue System
moonman
Developer
 
Posts: 3388
Joined: Sat Jan 15, 2011 3:36 am

Re: C program won't start on boot

Postby XploD » Tue May 19, 2015 6:14 am

No, there's no DE nor any kind of GUI, it's RuneAudio for Raspberry Pi and it's based on ArchLinux, it's only accessible via network. Weid thing is that before this I had same program (for controlling buttons) written in bash (as .sh) and I did the same thing and it was normally starting at boot.

Unfortunately, I somehow managed to break Arch yesterday while trying to install Python and Python-pip and it won't boot anymore, I haven't done backup so I lost all my C and .sh programs :| I will write another program but this time in Python and see if there will be the same problems.

So, what's the correct procedure? This?
1) Put my program to /bin/sh
2) Open something.service in /usr/lib/systemd/system/ or /etc/systemd/system?
3) Execute systemctl start and systemctl enable

Is that everything?
XploD
 
Posts: 5
Joined: Wed May 13, 2015 9:24 am


Return to General

Who is online

Users browsing this forum: No registered users and 5 guests